《1602显示汉字.docx》由会员分享,可在线阅读,更多相关《1602显示汉字.docx(8页珍藏版)》请在优知文库上搜索。
1、1602显示汉字程序代码:1602.c:includeLCD1602/LCD1602.Hexternunsignedcharpattern;voidDelay_us(unsignedchart)(while(-t);)voidDelay_ms(unsignedchart)(whiIe(t一)(De1ayus(225);Delay_us(227);)voidInit_1602(void)(Delay_ms(15);Write_Char1602(0x38,CMD,0);/don,tcheckbusyDeIayJnS(5);Write_Char_1602(0x38,CMD,0);Delay_ms(5
2、);Write_Chaj1602(0x38,CMD,0);Write_Char_1602(0x38,CMD,1);/8wire,2linedisplay,5x10charWrite_Char_1602(0x08,CMD,1);/closedisplay,nocursor,don,tblinkWrite_Char_1602(0x01,CMD,1)clearscreenWrite_Char_1602(0x06,CMD,1);/thecursormovefromlefttoright,thetextdon,tmoveWrite_Char_1602(0x0c,CMD,1)jopendisplay)vo
3、idWrite_Char_1602(unsignedcharData,bitCMDDATA,bitCheck)(if(Check)Check_Busy_1602();RS602=CMD_DATA;RW_1602=WRITE;DATA_1602=Data;E_1602=l;_nop_();E_1602=0;)unsignedcharRead_Char_1602(unsignedcharAddr,bitCheck)(unsignedchartemp;Write_Char_1602(Addr,CMD,1);if(Check)Check_Busy_1602();DATA_1602=0xff;RS602
4、=DATA;RWI602=READ;E_1602=l;_nop_O;temp=DTA-1602;E_1602=O;returntemp;)voidWrite_String1602(unsignedchar*P)/onlycanwritefromstarttoend(unsignedchari,Ien;Ien=Strlen(P);Set_R_C(0,0);if(len16)(for(i=0;i16;i+)(Write_Char_1602(Pi,DATA,1);)Set_R_C(l,O);for(i=16;ilen;i+)(Write_Char_1602(Pi,DATA,1);elsefor(i=
5、0;ilen;i+)(Write_Char_1602(Pi,DATA,1);)voidSet_R_C(unsignedcharR,unsignedcharC)/setrowandcolumnR=0l;C=(TF(Rfe=OxOl;C&二OXOf;if(R)Write_Char_1602(0x80+0x40+C,CMD,1);elseWrite_Char_1602(0x80+C,CMD,1);voidCheckBusy_l602(void)(DATA_1602=0xff;/setasinputportRS_1602=CMD;RW_1602=READ;E.1602=l;while(DATA_160
6、2&0x80)E1602=0;这两句ProtUeS仿真必须加EJL602=1;/EJ602=0;)/writetheself_definedwordtoCGRAMandsettheDDRAM,saddressandDDRM,sinformationto/displaytheself_definedcharformpastion0to7/5x8dotcharvoidPattern(unsignedchar*pattern)unsignedcharcount;Write_Char_1602(0x40,CMD,1);/setCGRAMaddress0x00(063)8self_definedchar
7、for(count=0;count64;count+)(Write_Char_1602(patterncount,DATA,1);)main,c:#includeincludeLCD1602LCD1602.H,zincludeUARTUART.H/crystal11.0592MunsignedcharDisp_Buffer=z,LCD_1602Drive,writebymyself.zz;unsignedcharcodepattern=0x08,OxOf,0x12,OxOf,OxOa,Oxlf,0x02,0x02,年OxOf,0x09,OxOf,0x09,OxOf,0x09,0xll,0x00
8、,/月OxOf,0x09,0x09,OxOf,0x09,0x09,OxOf,0x00,日0x00,OxOf,0x09,OxOa,0x04,OxOa,0x10,OXO1,欢-左半部0x08,OxOf,0x11,0x04,0x04,OxOa,0xll,OXO0,欢-右半部OxOb,0x02,Oxla,OxOb,0x08,0x08,OxOe,0x13,迎一左半部0x17,0x05,0x15,0x17,0x14,0x14,0x04,OXIf,迎-右半部OxlF,OxlF,OxlF,OxlF,OxlF,OxlF,OxlF,0xlF);voidmain(void)(unsignedchari;Delay_
9、ms(100);Init_1602();Init.UART();/CGRAM的读写测试Pattern(pattern);写入CGRAMWrite_Char_1602(0xC0,CMD,1);二行方式显示:0x80时写的是第一行OxCO时写的是第二行for(i=0;i8;i+)范围:0x8(TOX80+0x27OXC(TOXCO+0x27一行方式显示:只有0x80显示第一行,第二行不显示Write_Char_1602(i,DATA,1);范围:0x8(TOX80+80for(i=0;i8;i+)Send_Char(Read_Char_1602(0x40+i,1);/while(l);)*DDRAM的读写测试Write_Char602(0x80,CMD,1);二行方式显示:0x80时写的是第一行OxCO时写的是第二行for(i=0;i40;i+)/范围:0x8(TOX80+0x27OXC(TOXCO+0x27一行方式显示:只有0x80显示第一行,第二行不显示Write_Char_1602(0x30,DATA,1);范围:0x8(TOX80+80)for(i=0;i40;i+)(Send_Char(Read_Char_1602(0x80+i,1);*/