|
- #include<reg52.h>
- typedef unsigned char uint8;
- typedef unsigned int uint16;
- sbit rs=P2^6;
- sbit rw=P2^5;
- sbit e=P2^7;
- uint8 a[16]="zheeeg ti wwi ";
- uint8 b[27]="ze asfeng xe xi 1w284g50hb6 ";
- void delay(uint16 i) //1us
- {
- while(i--);
- }
- void wrc(uint8 c) /*寫命令*/
- {
- delay(1000);
- rs=0; //選擇發(fā)送命令
- rw=0; //選擇寫入
- e=0; //使能清零
- P0=c; //放入命令
- e=1; //寫入時(shí)序
- delay(10); //保持時(shí)間
- e=0;
- /*
- P0=c<<4;
- e=1;
- e=0;*/ //四位的LCD要加上
- }
- void wrd(uint8 dat) /*讀命令將數(shù)據(jù)寫在LCD上*/
- {
- delay(1000);
- rs=1; //選擇輸入數(shù)據(jù)
- rw=0; //選擇寫入
- e=0; //使能清零
- P0=dat; //寫入數(shù)據(jù)
- e=1; //寫入時(shí)序
- delay(10);//保持時(shí)間
- e=0;
- /*
- P0=dat<<4;
- e=1;
- e=0; //四位的LCD要加上
- rs=0;*/
- }
- void init() /*初始化設(shè)置*/
- {
- delay(1000);
- /*wrc(0x32);
- wrc(0x28);
- wrc(0x28); */ //四位的LCD要加上
- wrc(0x38); //8位數(shù)據(jù)總線,顯示兩行,5*10點(diǎn)陣
- wrc(0x0c);
- wrc(0x01);
- }
- void display()
- {
- uint8 i;
- wrc(0x00+0x80);
- for(i=0;i<16;i++)
- {
- wrd(a[i]);
- delay(30000);
- }
- wrc(0x40+0x80);
- for(i=0;i<27;i++)
- {
- wrd(b[i]);
- delay(30000);
- }
- wrc(0x07); //每寫一個(gè)數(shù)據(jù)屏幕就要右移一位,就相對于數(shù)據(jù)來說就是左移了;
- /* while(1)
- {
- wrc(0x00+0x80);
- for(i=0;i<16;i++)
- {
- wrd(a[i]);
- delay(30000); //如果不加這條延時(shí)語句的話滾動會非常快。
- }
- } */
- }
- void main()
- {
- init();
- while(1)
- {
- display();
- }
- }
復(fù)制代碼 |
|