/* 液晶 */ #define LCD P1 // P1口作LCD I/O #define uchar unsigned char #define uint unsigned int /************ 位变量定义 *********/ sbit RS=P3^6; sbit RW=P3^5; sbit E=P3^4 ; sbit BF=P1^7; /************ 函数声明 ************/ bit busy_check(); // 检查忙函数 void busy_wait(); // 等待空闲 void LCD_int(); // 初始化液晶 void write_data(uchar dat); // 写数据 void write_comm(uchar com); // 写指令 void write_1602_DATA(uchar addr,uchar dat); // 指定位置写数据 /************ 检查忙子函数 ********/ bit busy_check() { bit bf; LCD=0xff; RS=0; RW=1; E=0; E=0; E=1; E=1; bf=BF; return (bf); } /************ 等待空闲 *************/ void busy_wait() { while (busy_check()) { busy_check(); }; } /************ 初始化液晶 **********/ void LCD_int() { write_comm(0x38); delay_nms(5); write_comm(0x38); delay_nms(5); write_comm(0x38); delay_nms(5); write_comm(0x38); busy_wait(); write_comm(0x08); busy_wait(); write_comm(0x01); busy_wait(); write_comm(0x06); busy_wait(); write_comm(0x0c); busy_wait(); } /************ 写数据子函数 *********/ void write_data(uchar dat) { busy_wait(); RS=1; RW=0; LCD=dat; E=0; E=1; } /************ 写指令子函数 **********/ void write_comm(uchar com) { busy_wait(); RS=0; RW=0; LCD=com; E=0; E=1; }