抄的不仔细,也没有认真检查。
- #include <reg51.h>
- #include <intrins.h>
- #define DB P0
- sbit RS=P2^0;
- sbit RW=P2^1;
- sbit E=P2^2;
- void delay(unsigned int z)
- {
- unsigned int x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void write_dat(unsigned char dat)
- {
- RW=0;
- RS=1;
- DB=dat;
- delay(5);
- E=1;
- delay(5);
- E=0;
- }
- void write_com(unsigned char com)
- {
- RW=0;
- RS=0;
- DB=com;
- delay(5);
- E=1;
- delay(5);
- E=0;
- }
- void lcd_1602init()
- {
- RW=0;
- E=0;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- // write_com(0x80);
- }
- void write_sfm(unsigned char add,unsigned char date)
- {
- unsigned char shi,ge;
- shi=date/10;
- ge=date%10;
- write_com(0x80+add);
- write_dat(0x30+shi);
- write_dat(0x30+ge);
- }
- void main()
- {
- lcd_1602init();
- write_sfm(0,20);//写第一行
- while(1)
- {
- write_com(0xc0);//写第二行
- write_dat('2');
- write_dat('0');
- }
- }
复制代码
|