//*****************************************************************/*程序功能:顯示兩行字符并且整屏左移 (程序使用在接口為4位的1602液晶)涉及芯片:1602液晶顯示器*///*****************************************************************#includereg52.h>#define uint unsigned int#define uchar unsigned charsbit rs=P2^0;//數(shù)據(jù)/命令選擇端(H/L)sbit rw=P2^1;//讀/寫選擇端(H/L)sbit en=P2^2; //使能選擇端uchar code mingzi[]="Gui fa zhi !_! "; //定義數(shù)據(jù)mingzi【】 uchar code num[]="tel:18778434282 "; //定義數(shù)組num【】void delay(uint time)//延時(shí)函數(shù)(運(yùn)行的時(shí)間與晶振有關(guān)系){uint i,j;for(i=time;i>0;i--)for(j=110;j>0;j--);}void write_com(uchar mingling)//命令輸入函數(shù){uchar gao,di; //定義高、低四位gao=mingling0xf0;//分出高四位di=(mingling4)0xf0;//分出低四位//==========================================讀走高四位P2=gao;//讓數(shù)據(jù)(mingling)高四位有效rs=0;//rs端為低電平時(shí),為接收命令 delay(5);en=1; //en一個(gè)高脈沖讀走高四位數(shù)據(jù)(mingling)delay(5);en=0;//把使能端拉回低電平//============================================讀走低四位delay(5); P2=di;//讓數(shù)據(jù)(mingling)低四位有效rs=0;//rs端為低電平時(shí),為接收命令delay(5);en=1 ;//en一個(gè)高電平讀走低四位命令(mingling)delay(5);en=0;//把使能端拉回低電平}void write_date(uchar shuju)//數(shù)據(jù)輸入函數(shù){uchar gao,di;gao=shuju0xf0;//分出高四位di=(shuju4)0xf0;//分出低四位//=======================================讀走高四位P2=gao;//讓數(shù)據(jù)(shuju)高四位有效rs=1;//rs端為高電平時(shí),為接收數(shù)據(jù)delay(5);en=1;//en一個(gè)高電平讀走低四位數(shù)據(jù) (shuju)delay(5);en=0;//把使能端拉回低電平//============================================讀走低四位delay(5);P2=di;//讓數(shù)據(jù)(shuju)低四位有效rs=1;//rs端為高電平時(shí),為接收數(shù)據(jù)delay(5);en=1;//en一個(gè)高電平讀走低四位數(shù)據(jù)(shuju)delay(5);en=0;//把使能端拉回低電平}void chushihua(){rw=0;//把數(shù)據(jù)/命令選擇端先置為零en=0;//把使能端先置為零write_com(0x28);//設(shè)置16*12顯示,5*7點(diǎn)陣,4位數(shù)據(jù)接口write_com(0x01);//清屏write_com(0x0c);//顯示開(kāi)啟,不顯示光標(biāo)write_com(0x06);//整屏不移動(dòng)}void main()//主函數(shù){uint i,j; chushihua();//對(duì)液晶初始化while(1)//死循環(huán){write_com(0x80);for(i=0;i16;i++){write_date(mingzi[i]);}write_com(0x80+0x40);for(j=0;j16;j++){write_date(num[j]);}write_com(0x18);//寫控制字,在英文文檔里介紹。0x18為左移,0x1c為右移}}
評(píng)論