#include#define uint unsigned int#define uchar unsigned charsbit rs=P1^0;//數(shù)據(jù)/命令選擇端(H/L)sbit rw=P1^1;//讀/寫選擇端(H/L)sbit en=P1^2;//使能端uchar code zifu1[]="Gui fa zhi *_* !";uchar code zifu2[]="tel: 18778434282";uint i;void delay(uchar time)//延時函數(shù){uint x,y;for(x=100;x>0;x--)for(y=time;y>0;y--);}void write_com(uchar com) //命令輸入函數(shù){rs=0;P2=com;delay(5);en=1;delay(5);en=0;}void write_date(uchar date)//數(shù)據(jù)輸入函數(shù){rs=1;P2=date;delay(5);en=1;delay(5);en=0;}void chu()//液晶初始化{rw=0;//低電平威脅數(shù)據(jù)或命令en=0;write_com(0x38);//設(shè)置16X2顯示,5X7點陣,8位數(shù)據(jù)口write_com(0x01);//數(shù)據(jù)指針清零write_com(0x0c);//光標開啟}void move()//整屏移動(0x18是向左移,0x1c是右移){for(i=0;i<16;i++)//移動16位{write_com(0x18);delay(500);}}void main()//主函數(shù){chu();write_com(0x80+0x10);//選擇地址for(i=0;i<16;i++){write_date(zifu1[i]);delay(5);}write_com(0x80+0x40+0x10);for(i=0;i<16;i++){write_date(zifu2[i]);delay(5);}while(1){move();}}
評論