教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 幼儿教育 >

AVR实现LCD12864显示汉字程序

来源:网络收集 时间:2026-05-19
导读: 本程序所使用的单片机芯片是ATmega16,液晶是LCD12864,程序可以在开发板上很完美的运行,只显示汉字(只显示汉字,字符、字符串、图片未写程序) /******************************************************************************* ***************************

本程序所使用的单片机芯片是ATmega16,液晶是LCD12864,程序可以在开发板上很完美的运行,只显示汉字(只显示汉字,字符、字符串、图片未写程序)

/*******************************************************************************
********************************************************************************
作者:松清竹龄
时间:2010.10
运行软件:ICCAVR7.14
使用芯片:ATmega16
实现功能:LCD12864显示汉字
汉字取模软件:PCtoLCD2002
********************************************************************************
*******************************************************************************/
#include <iom16v.h>

#define RS_CLRPORTD &= ~(1 << PD3)/*命令或数据选择*/
#define RS_SETPORTD |= (1 << PD3)/*RS = 1命令,RS = 0数据*/

#define RW_CLRPORTD &= ~(1 << PD4)/*读取或写入选择*/
#define RW_SETPORTD |= (1 << PD4)/*RW = 1读,RW = 0写*/

#define EN_CLRPORTD &= ~(1 << PD6)/*读写使能信号*/
#define EN_SETPORTD |= (1 << PD6)/*下降沿有效*/

#define RST_CLRPORTD &= ~(1 << PD7)/*芯片复位脚*/
#define RST_SETPORTD |= (1 << PD7)/*高电平复位*/

#define CSA_CLRPORTC &= ~(1 << PC6)/*左半屏片选*/
#define CSA_SETPORTC |= (1 << PC6)/*高电平选中*/

#define CSB_CLRPORTC &= ~(1 << PC7)/*右半屏片选*/
#define CSB_SETPORTC |= (1 << PC7)/*高电平选中*/

extern const unsigned char CHINESE_FONT[];
extern const unsigned char ENGLISH_FONT[];
void disp_init(void);
void disp_clear(unsigned char x0, unsigned char x1, unsigned char y);
void disp_word(unsigned char x, unsigned char y, unsigned char word);
void delay_ms(unsigned char i);
void delay_us(unsigned int n);

/*延时函数*/
void delay_us(unsigned int n) {

if (n == 0) {
return ;
}
while (--n);
}

/*延时函数*/
void delay_ms(unsigned char i) {

unsigned char a, b;
for (a = 1; a < i; a++) {
for (b = 1; b; b++) {
;
}
}
}
void main(void) {

PORTA = 0xFF;/*打开上拉*/
DDRA = 0x00;/*方向输入*/
PORTB = 0xFF;/*电平设置*/
DDRB = 0xFF;/*方向输出*/
PORTC = 0x7F;
DDRC = 0x80;
PORTD = 0xFF;
DDRD = 0x00;

disp_init();
disp_clear(0, 128, 0);
disp_clear(0, 128, 2);
disp_clear(0, 128, 4);
disp_clear(0, 128, 6);

/**********汉字显示控制部分************/
disp_word(1, 1,1);
disp_word(20,2,2);
disp_word(40,4,3);
disp_word(60,4,4);
disp_word(80,2,5);
disp_word(100,1,6);
/***************************************/
while (1);
}

/*显示屏命令写入函数前半屏*/
void LCD0_write_com(unsigned char com) {

RS_CLR;
RW_CLR;
CSA_SET;
CSB_CLR;
EN_SET;
PORTB = com;
delay_us(1);
EN_CLR;
}

/*显示屏命令写入函数后半屏*/
void LCD1_write_com(unsigned char com) {

RS_CLR;
RW_CLR;
CSA_CLR;
CSB_SET;
EN_SET;
PORTB = com;
delay_us(1);
EN_CLR;
}

/*显示屏命令写入函数*/
void LCD0_write_data(unsigned char data
) {

RS_SET;
RW_CLR;
CSA_SET;
CSB_CLR;
EN_SET;
PORTB = data;
delay_us(1);
EN_CLR;
}

/*显示屏命令写入函数*/
void LCD1_write_data(unsigned ch

本程序所使用的单片机芯片是ATmega16,液晶是LCD12864,程序可以在开发板上很完美的运行,只显示汉字(只显示汉字,字符、字符串、图片未写程序)

ar data) {

RS_SET;
RW_CLR;
CSA_CLR;
CSB_SET;
EN_SET;
PORTB = data;
delay_us(1);
EN_CLR;
}

/*显示屏清空显示*/
void disp_clear(unsigned char x0, unsigned char x1, unsigned char y) {

unsigned char x;

/*清除高位*/
x = x0;
if (x < 63) {/*地址在左半屏范围内*/
LCD0_write_com(y | 0xB8);
LCD0_write_com(x | 0x40);
}
while (x < x1) {
LCD0_write_data(0x00);
x ++;
if (x > 63) {/*判断地址是否越界*/
break;
}
}
if (x < x1) {/*地址进入左半屏范围*/
LCD1_write_com(y | 0xB8);
LCD1_write_com(x | 0x40);
}
while (x < x1) {
LCD1_write_data(0x00);
x ++;
}

/*清除低位*/
x = x0;
if (x < 63) {/*地址在左半屏范围内*/
LCD0_write_com((y+1) | 0xB8);
LCD0_write_com(x | 0x40);
}
while (x < x1) {
LCD0_write_data(0x00);
x ++;
if (x > 63) {/*判断地址是否越界*/
break;
}
}
if (x < x1) {/*地址进入左半屏范围*/
LCD1_write_com((y+1) | 0xB8);
LCD1_write_com(x | 0x40);
}
while (x < x1) {
LCD1_write_data(0x00);
x ++;
}
}



/*在指定位置显示一个汉字*/
void disp_word(unsigned char x, unsigned char y, unsigned char word) {

unsigned char i = 0x00;
const unsigned char *q;/*取字库指针*/

q = &CHINESE_FONT[word * 32];/*定位指针地址*/

/*显示高16位*/
i = 0x00;
if (x < 64) {/*地址在左半屏范围内*/
LCD0_write_com(y | 0xB8);
LCD0_write_com(x | 0x40);
while (i < 16) {
LCD0_write_data(*q);
q ++;
x ++;
i ++;
if (x > 63) {/*判断地址是否越界*/
break;
}
}
}
if (i < 16) {/*地址进入左半屏范围*/
LCD1_write_com(y | 0xB8);
LCD1_write_com(x | 0x40);
while (i < 16) {
LCD1_write_data(*q);
q ++;
x ++;
i ++;
}
}

/*显示低16位*/
i = 0x00;
x -= 16;
if (x < 64) {/*地址在左半屏范围内*/
LCD0_write_com((y+1) | 0xB8);
LCD0_write_com(x | 0x40);
while (i < 16) {
LCD0_write_data(*q);
q ++;
x ++;
i ++;
if (x > 63) {/*判断地址是否越界*/
break;
}
}
}
if (i < 16) {/*地址进 …… 此处隐藏:4080字,全部文档内容请下载后查看。喜欢就下载吧 ……

AVR实现LCD12864显示汉字程序.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/1529061.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)