LCD1602液晶完整中文资料

10.8.3.3 软件代码 #include #include sbit rs= P2^0; sbit rw = P2^1; sbit ep = P2^2;

unsigned char code dis1[] = {\

10-61 软件流程图图

unsigned char code dis2[] = {\void delay(unsigned char ms) {

unsigned char i; while(ms--) {

for(i = 0; i< 250; i++) { _nop_(); _nop_(); _nop_(); _nop_(); } } }

bit lcd_bz() { bit result; rs = 0; rw = 1; ep = 1; _nop_(); _nop_(); _nop_(); _nop_();

result = (bit)(P0 & 0x80); ep = 0; return result; }

void lcd_wcmd(unsigned char cmd) {

while(lcd_bz());//判断LCD是否忙碌 rs = 0; rw = 0; ep = 0; _nop_(); _nop_(); P0 = cmd; _nop_(); _nop_(); _nop_(); _nop_(); ep = 1; _nop_(); _nop_(); _nop_(); _nop_(); ep = 0; }

void lcd_pos(unsigned char pos)

{

lcd_wcmd(pos | 0x80); }

void lcd_wdat(unsigned char dat) {

while(lcd_bz());//判断LCD是否忙碌 rs = 1; rw = 0; ep = 0; P0 = dat; _nop_(); _nop_(); _nop_(); _nop_(); ep = 1; _nop_(); _nop_(); _nop_(); _nop_(); ep = 0; }

void lcd_init() {

lcd_wcmd(0x38); delay(1);

lcd_wcmd(0x0c); delay(1); lcd_wcmd(0x06); delay(1); lcd_wcmd(0x01); delay(1); }

void main(void) {

unsigned char i; lcd_init();// 初始化LCD delay(10);

lcd_pos(0x01);//设置显示位置 i = 0;

while(dis1[i] != '\\0') {

lcd_wdat(dis1[i]);//显示字符 i++; }

lcd_pos(0x42);// 设置显示位置 i = 0;

while(dis2[i] != '\\0') {

lcd_wdat(dis2[i]);// 显示字符 i++;

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4