- #include<reg51.h>
- #include<intrins.h>
- sbit RS=0xb0;
- sbit RW=0xb1;
- sbit E =0xb2;
- void lcd_w_cmd(unsigned char com);
- void lcd_w_dat(unsigned char dat);
- void lcd_r_start();
- void lcd_int();
- void delay(unsigned int i);
- void main()
- {
- unsigned char lcd[]="0123456789ABCDEF";
- unsigned char lcd1[]="HELLO WORLD!" ;
- unsigned char i;
- lcd_int();
- lcd_w_cmd(0x80);
- for(i=0;i<16;i++)
- lcd_w_dat(lcd[i]);
- lcd_w_cmd(0xc2);
- for(i=0;i<12;i++)
- lcd_w_dat(lcd1[i]);
- while(1);
- }
- void lcd_int()
- {
- RW=0;
- E =0;
- lcd_w_cmd(0x38);
- lcd_w_cmd(0x01);
- lcd_w_cmd(0x0c);
- lcd_w_cmd(0x06);
- }
- void lcd_r_start()
- {
- unsigned char s;
- P1=0xff;
- RS=0;
- RW=1;
- do
- {
- E = 1;
- s = P1;
- E = 0; //使能
- }while(s&0x80);
- }
- void lcd_w_cmd(unsigned char com)
- {
- lcd_r_start();
- RW=0;
- RS=0;
- P1=com;
- delay(10);
- E=1;
- delay(10);
- E=0;
- }
- void lcd_w_dat(unsigned char dat)
- {
- lcd_r_start();
- RW=0;
- RS=1;
- P1=dat;
- delay(10);
- E=1;
- delay(10);
- E=0;
- }
- void delay(unsigned int i)
- {
- unsigned int a,b;
- for(a=i;a>0;a--)
- for(b=10;b>0;b--);
- }
复制代码
|