//液晶1602(带字库)显示测试程序// #include<reg51.h> #define uint unsigned int #define uchar unsigned char //宏定义 uchar code table[]=" LU LIE QI "; uchar code table1[]="WWW.LAOWANG.COM"; sbit LCD_RS=P2^6; //位定义 sbit LCD_RW=P2^5; sbit LCD_EN=P2^7; uchar num; //定义全局变量 //延时程序===1ms// void delay_1ms(uint mas) { uint i,j; for(i=0;i<mas;i++) for(j=0;j<110;j++); } void write_com(uchar com) // 写命令 { LCD_RS=0; LCD_RW=0; P0=com; delay_1ms(5); LCD_EN=1; delay_1ms(5); LCD_EN=0; } void write_data(uchar dadt) //写数据 { LCD_RS=1; P0=dadt; delay_1ms(5); LCD_EN=1; delay_1ms(5); LCD_EN=0; } void init() //初始化函数 { LCD_EN=0; write_com(0x38); //显示模式设置16X2,5X7点阵,8位数据口 write_com(0x0f); //开显示、开关标、关标闪烁 write_com(0x06); //关标加一 write_com(0x01); //清屏 write_com(0x80+0x10); //数据指针位置 } //=====主函数======// void main() { init(); for(num=0;num<10;num++) { write_data(table[num]); delay_1ms(20); } write_com(0x80+0x50); for(num=0;num<15;num++) { write_data(table1[num]); delay_1ms(20); } for(num=0;num<16;num++) { write_com(0x18); delay_1ms(500); } while(1); } |