12864液晶代码(很实用的)
12864液晶经典驱动程序,一看就懂,有详细的注释(C语言编写,不看后悔)
这个程序写得很好,自己也是看的别人写的很好的程序,但是它代码不够完整,注释不详细,经过自己的修改加以完善。
另外我发现很多的测试代码都没有附上测试代码效果图,在本人的代码下面有自己拍的效果图,填补不足之处。
自己在找资料的过程中花掉很多的财富值,如果大家看得起该代码请评五分加以下载,在下感激不尽!/*******************************************程序名称:12864液晶经典驱动程序(带中文字库)功能:12864测试程序修改作者:王程修改时间:2014年2月5日23:22:32********************************************/#include<reg52.h>#define uchar unsigned char#define uint unsigned int// P0 为数据口sbit LCD_RS=P2^0; //数据、命令选择端口sbit LCD_RW=P2^1; //液晶读写控制sbit LCD_EN=P2^2; //液晶使能控制sbit PSB = P2^4; //模式选择1为并行0为串行sbit RES = P2^5;//复位端口低电平复位,上电之前进行复位,为了稳定!unsigned char code DAT[] = "我爱我家"; //测试显示的汉字,下面的A为测试显示的英文/*******************************************函数名称:Delay_1ms (晶振为12M)功能:延时约1ms的时间参数:无返回值:无********************************************/void delay_1ms(uint x){uint i,j;for(j = 0;j < x;j++)for(i=0;i<110;i++);}/*******************************************函数名称:write_cmd功能:向液晶中写控制命令参数:cmd--控制命令返回值:无********************************************/void write_cmd(uchar cmd){uchar lcdtemp = 0;LCD_RS=0;LCD_RW=1;do //经典判忙方式,精简{LCD_EN=1;delay_1ms(2);lcdtemp = P0;LCD_EN=0;}while(lcdtemp & 0x80);LCD_RW=0;P0 = cmd;LCD_EN=1;delay_1ms(5);LCD_EN=0;}/*******************************************函数名称:write_data功能:向液晶中写显示数据参数:dat--显示数据返回值:无********************************************/ void write_data(uchar dat){uchar lcdtemp = 0;LCD_RS=0;LCD_RW=1;do //经典判忙方式{LCD_EN=1;delay_1ms(2);lcdtemp = P0;LCD_EN=0;}while(lcdtemp & 0x80);LCD_RS=1;LCD_RW=0;P0 = dat;LCD_EN=1;delay_1ms(5);LCD_EN=0;}/*******************************************函数名称:lcd_int功能:初始化液晶模块参数:无返回值:无********************************************/void lcd_int(void){delay_1ms(40); //大于40MS的延时程序PSB=1; //设置为8BIT并口工作模式delay_1ms(1); //延时RES=0; //复位delay_1ms(1); //延时RES=1; //复位置高delay_1ms(10);write_cmd(0x30); //基本指令集delay_1ms(5);write_cmd(0x30); //基本指令集delay_1ms(5);write_cmd(0x08); // 地址归位delay_1ms(5);write_cmd(0x10); //光标设置delay_1ms(5);write_cmd(0x0c); //整体显示打开,游标关闭delay_1ms(5);write_cmd(0x01); //清除显示delay_1ms(5);write_cmd(0x06); //游标右移delay_1ms(5);write_cmd(0x80); //设定显示的起始地址delay_1ms(5);}函数名称:main功能:测试1602初始化函数模块参数:无返回值:无********************************************/void main(){uchar i;char *a = DAT;//使用指针,指向字符串地址lcd_int();write_data('A'); //每个显示都是用的两个字节,必须写两次write_data(' ');//再写一次,不然乱显示(如果不加就再显示一个别的字母)for(i=0;i<8;i++){write_data(*a);//将地址当作数据传给12864a++;//一个汉字传送两次,因为一个汉字占用两个字节,两次传完}write_cmd(0x90);//一行显示八个汉字,第一行0x80-87,第二行0x90开始a = DAT;for(i=0;i<8;i++){write_data(*a);a++;}while(1); //停住,不然重复的初始化显示,作为测试用}/*******************************************代码测试效果图片两两张由于曝光度影响,拍了两张********************************************/。
12864显示屏编程总结
12864显示屏编程总结第一步:初始化。
void lcd_init(void){wr_lcd (comm,0x30); /*30---基本指令动作*/wr_lcd (comm,0x01); /*清屏,地址指针指向00H*/wr_lcd (comm,0x06); /*光标的移动方向*/wr_lcd (comm,0x0c); /*开显示,关游标*/}第二步:清DDRAM.voidclrram (void){wr_lcd (comm,0x30);wr_lcd (comm,0x01);}第三步:显示程序主体设计。
1.输入命令:命令分为基本命令(0x30)和扩展命令(0x34)。
先写是基本命令还是扩展命令,即wr_lcd (comm,0x30); /*30---基本指令动作*/………………………………..如果是扩展命令则:wr_lcd (comm,0x34);//扩展命令……………………………….注意:第一句程序将会一直有效。
2.写入数据我把数据分为两大类:文本数据和图形数据。
文本数据又分为ASCII码和汉字,两者的编程非常类似,先确定要输入文本在屏上的地址,然后输入文本对应的码号(需要查表)。
在输入图片的时候就需要先形成BMP格式的图片的128*64分辨率的数组。
有了数组后,首先要关闭绘图显示(0x34,扩展命令),然后设定图片的Y轴地址,然后设定图片的X轴地址,然后在输入在该地址的数组元素。
注意,只要输入地址是连续的,可只输入首地址然后连续输入数据,在连续输入数据的过程中,地址会自动+1。
最后再打开绘图显示(0x36,扩展命令)。
例子:unsignedinti,j;wr_lcd (comm,0x34);//扩展命令wr_lcd (comm,0x34);//扩展命令,关闭绘图显示for(i=0;i<32;i++){wr_lcd (comm,0x80);//设置x轴坐标for(j=0;j<16;j++){wr_lcd (dat,0);}}for(i=0;i<32;i++){wr_lcd (comm,0x80+i);//设置y轴坐标wr_lcd (comm,0x88);//设置x轴坐标/*初学者在这个地方的地址肯定是搞不清楚的,具体见后面的有关地址讨论*/for(j=0;j<16;j++){wr_lcd (dat,0);//地址连续,可以连续输入数据}}3.操作命令与硬件设计和编程。
按键检测12864LCD显示汇编代码
r16 .set 280hr17 .set 282hr18 .set 284hr21 .set 286hr22 .set 288hr23 .set 28ahr24 .set 28chr25 .set 28ehr26 .set 290hr28 .set 27ehkeydata .set 292hrowdata .set 294hscandata .set 296hkeybuffer .set 298hdp_user .set 5hkeydata1 .set 29ahlcdtab .set 29chlcddata .set 29ehpbdatdir .set 709ahdp_pf2 .set 0e1hpadatdir .set 7098hpcdatdir .set 709chmcra .set 7090hmcrb .set 7092hmcrc .set 7094hpedatdir .set 7095hpfdatdir .set 7096h.datatab00:;-- 文字: E --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,007H,006H,004H,004H,004H,00 4H,004H,004H,004H,007H,007H,004H,004H ,000H.word000H,0C0H,080H,000H,01FH,007H,002H,00 2H,002H,002H,002H,0FFH,0FFH,000H,000H ,000H.word000H,006H,001H,000H,0C0H,000H,000H,00 0H,000H,000H,000H,0FFH,0FFH,000H,000H ,000H .word000H,000H,0C0H,0C0H,040H,040H,040H,04 0H,040H,040H,040H,0C0H,0C0H,040H,040H ,000Htab01:;-- 文字: 0 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,000H,001H,003H,006H,004H,00 4H,004H,006H,003H,001H,000H,000H,000H ,000H.word000H,01FH,0FFH,0C0H,000H,000H,000H,00 0H,000H,000H,000H,0E0H,0FFH,01FH,000H ,000H.word000H,0F0H,0FEH,007H,001H,000H,000H,00 0H,000H,000H,001H,00FH,0FEH,0F0H,000H ,000H.word000H,000H,000H,000H,080H,0C0H,040H,04 0H,040H,0C0H,080H,000H,000H,000H,000H ,000Htab02:;-- 文字: F --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,007H,006H,006H,004H,004H,004H,00 4H,004H,004H,004H,007H,007H,004H,004H ,000H.word0C0H,080H,000H,01FH,007H,002H,002H,00 2H,002H,002H,002H,0FFH,0FFH,000H,000H ,000H.word000H,000H,000H,0C0H,000H,000H,000H,00 0H,000H,000H,000H,0FFH,0FFH,000H,000H ,000H.word000H,000H,000H,000H,000H,000H,000H,00 0H,000H,040H,040H,0C0H,0C0H,040H,040H ,000Htab03:;-- 文字: D --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,000H,001H,003H,002H,006H,00 4H,004H,004H,004H,007H,007H,004H,004H ,000H.word000H,01FH,0FFH,0E0H,000H,000H,000H,00 0H,000H,000H,000H,0FFH,0FFH,000H,000H ,000H.word000H,0F0H,0FCH,00FH,001H,000H,000H,00 0H,000H,000H,000H,0FFH,0FFH,000H,000H ,000H.word000H,000H,000H,000H,080H,080H,0C0H,04 0H,040H,040H,040H,0C0H,0C0H,040H,040H ,000Htab04:;-- 文字: 7 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,006H,007H,006H,006H,006H,00 6H,006H,006H,006H,007H,007H,001H,000H ,000H.word000H,000H,000H,000H,0C0H,030H,00CH,00 3H,000H,000H,000H,000H,080H,0E0H,000H ,000H.word000H,000H,000H,000H,000H,000H,000H,08 0H,07FH,00FH,000H,000H,000H,000H,000H ,000H.word000H,000H,000H,000H,000H,000H,000H,00 0H,0C0H,0C0H,000H,000H,000H,000H,000H ,000Htab05:;-- 文字: 8 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 -- .word000H,000H,000H,001H,003H,006H,004H,00 4H,004H,004H,006H,003H,001H,000H,000H ,000H.word000H,000H,0F0H,0F8H,00CH,003H,003H,00 3H,003H,006H,00FH,01DH,0F8H,0F0H,000H ,000H.word000H,000H,03EH,07FH,0E1H,0C0H,080H,00 0H,000H,000H,000H,080H,0C1H,07FH,03EH ,000H.word000H,000H,000H,000H,080H,080H,040H,04 0H,040H,040H,040H,080H,080H,000H,000H ,000Htab06:;-- 文字: 9 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,000H,000H,001H,002H,004H,00 4H,004H,004H,004H,002H,003H,001H,000H ,000H.word000H,000H,03FH,0FFH,083H,001H,000H,00 0H,000H,000H,000H,000H,081H,0FFH,07EH ,000H.word000H,000H,0E0H,0FCH,01EH,083H,081H,04 0H,040H,040H,040H,0C0H,083H,003H,000H ,000H.word000H,000H,000H,000H,000H,000H,080H,0C 0H,040H,040H,040H,040H,080H,080H,000H ,000Htab07:;-- 文字: C --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,007H,003H,002H,004H,004H,00 4H,004H,006H,002H,001H,000H,000H,000H.word000H,060H,080H,000H,000H,000H,000H,00 0H,000H,000H,000H,080H,0E0H,07FH,00FH ,000H.word000H,00CH,003H,001H,000H,000H,000H,00 0H,000H,000H,000H,001H,00FH,0FEH,0F0H ,000H.word000H,000H,000H,080H,080H,040H,040H,04 0H,040H,040H,080H,080H,000H,000H,000H ,000Htab08:;-- 文字: 4 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,000H,000H,007H,007H,003H,00 0H,000H,000H,000H,000H,000H,000H,000H ,000H.word000H,000H,000H,000H,0FFH,0FFH,0FFH,08 0H,060H,018H,00CH,003H,000H,000H,000H ,000H.word000H,010H,010H,010H,0FFH,0FFH,0FFH,01 0H,010H,010H,010H,010H,090H,070H,010H ,000H.word000H,020H,020H,020H,0E0H,0E0H,0E0H,02 0H,020H,020H,000H,000H,000H,000H,000H ,000Htab09:;-- 文字: 5 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,006H,006H,006H,006H,006H,00 6H,006H,006H,006H,007H,000H,000H,000H ,000H.word000H,000H,000H,003H,006H,00CH,008H,00 8H,008H,008H,004H,0C2H,03FH,000H,000H .word000H,000H,0FCH,0FFH,003H,000H,000H,00 0H,000H,000H,000H,000H,00CH,00FH,000H ,000H.word000H,000H,000H,000H,080H,080H,040H,04 0H,040H,040H,040H,040H,080H,000H,000H ,000Htab10:;-- 文字: 6 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,001H,003H,004H,004H,004H,00 4H,006H,002H,001H,000H,000H,000H,000H ,000H.word000H,000H,081H,083H,006H,004H,004H,00 4H,004H,002H,003H,0E1H,07FH,00FH,000H ,000H.word000H,0FCH,0FFH,001H,000H,000H,000H,00 0H,000H,000H,001H,087H,0FEH,0F8H,000H ,000H.word000H,000H,000H,080H,080H,040H,040H,04 0H,040H,0C0H,080H,000H,000H,000H,000H ,000Htab11:;-- 文字: B --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,001H,003H,003H,006H,004H,00 4H,004H,004H,004H,007H,007H,004H,004H ,000H.word000H,000H,0F0H,0F9H,00DH,006H,002H,00 2H,002H,002H,002H,0FFH,0FFH,000H,000H ,000H.word000H,03EH,0FFH,081H,000H,000H,000H,00 0H,000H,000H,000H,0FFH,0FFH,000H,000H.word000H,000H,000H,080H,0C0H,040H,040H,04 0H,040H,040H,040H,0C0H,0C0H,040H,040H ,000Htab12:;-- 文字: 1 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,000H,000H,000H,000H,000H,00 7H,003H,001H,001H,001H,001H,000H,000H ,000H.word000H,000H,000H,000H,000H,000H,000H,0F FH,0FFH,000H,000H,000H,000H,000H,000H ,000H.word000H,000H,000H,000H,000H,000H,000H,0F FH,0FFH,000H,000H,000H,000H,000H,000H ,000H.word000H,000H,000H,040H,040H,040H,0C0H,0C 0H,0C0H,0C0H,040H,040H,040H,000H,000H ,000Htab13:;-- 文字: 2 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,000H,003H,003H,006H,004H,00 4H,004H,004H,004H,002H,001H,000H,000H ,000H.word000H,000H,0F8H,0FCH,006H,001H,000H,00 0H,000H,000H,000H,000H,030H,0F0H,000H ,000H.word000H,000H,00FH,001H,000H,000H,080H,04 0H,020H,010H,008H,004H,002H,001H,000H ,000H.word000H,000H,000H,0C0H,0C0H,0C0H,0C0H,0C 0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,000H tab14:;-- 文字: 3 --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,000H,000H,003H,003H,006H,00 4H,004H,004H,004H,002H,003H,001H,000H ,000H.word000H,000H,000H,0F0H,0F9H,00DH,007H,00 2H,002H,002H,000H,000H,0E0H,0E0H,000H ,000H.word000H,000H,03CH,0FFH,081H,000H,000H,00 0H,000H,000H,000H,000H,00FH,00FH,000H ,000H.word000H,000H,000H,000H,080H,080H,040H,04 0H,040H,040H,040H,080H,080H,000H,000H ,000Htab15:;-- 文字: A --;-- 宋体24; 此字体下对应的点阵为:宽x高=16x32 --.word000H,000H,000H,000H,000H,000H,000H,00 FH,007H,007H,000H,000H,000H,000H,000H ,000H.word000H,000H,000H,000H,000H,007H,07FH,0F 8H,000H,0C0H,07CH,007H,000H,000H,000H ,000H.word000H,000H,000H,003H,07FH,0FCH,0C0H,04 0H,040H,040H,040H,0C0H,07CH,007H,000H ,000H.word000H,040H,040H,0C0H,0C0H,040H,000H,00 0H,000H,000H,000H,040H,040H,0C0H,0C0H ,040H.include "240xa.inc".def _c_int0.text_c_int0setc INTMclrc SXMclrc OVMclrc CNFldp #0e0hsplk #0e8h,WDCRldp #0Splk #0h,IMRsplk #0ffffh,IFRldp #dp_usersplk #0FFFH,r22out r22,WSGRldp #dp_pf2lacl #00hsacl mcralacl mcrblacl #0ff00hsacl mcrblacl #000hsacl mcrcnopldp #5lacl #0sacl lcdtabsacl keydatalong1:lacl #0ff00h ldp #0e1hsacl PADATDIRrpt #20 noplacl #0ff00hsacl PCDATDIR rpt #20noplacl #0ff00h sacl pedatdirrpt #20nop ldp #dp_usersplk #3eh,r16call write_ins0rpt #100 noprpt #100 noprpt #100nop ldp #dp_usersplk #3fh,r16call write_ins0 call write_ins1rpt #100nop rpt #100nopl1: ldp #dp_user splk #0c0h,r16call write_ins0noplong2:ldp #dp_user splk #0bfh,r16call write_ins0ldp #dp_usersplk #40h,r16call write_ins0ldp #dp_user call display_cs0call display_cs1long100: LAR AR4,#07Hcall display_cs0 SAR AR4,r28scan_again:call scan_keylacl keydatabcnd scan_again,eqlacl #0ff00hldp #0e1hsacl PADATDIRrpt #20noplacl #0ff00hsacl PCDATDIR noplacl #0ff00hsacl pedatdirlacl #0hldp #5hsacl lcdtablacc #0mar *,ar5ldp #5hlacl keydatasub #01hsacl keydatalar ar5,keydatalar ar0,#00hlacl #00lay1:LACL lcdtabadd #6sacl lcdtabsbrk #1hnopcmpr 00bcnd lay1,NTCsacl lcdtablong35:ldp #dp_usersplk #10h,r22ldp #dp_usersplk #0beh,r23ldp #dp_userlt r28mpy #16SPL r24ldp #dp_usersplk #0bbh,r25lacc lcdtabadd #tab00sacl lcdtabcall display4 ldp #dp_user LAR AR4,r28mar *,ar4long4:BANZ long444,*-b long100long444:SAR AR4,r28call delaylong445:call scan_key lacl keydatabcnd scan_again,eqcall delayb long445scan_key:lacl #0ff00hldp #0e1hsacl pfdatdirrpt #20noplacl #000hsacl pcdatdirrpt #20noplacl #0ff00hsacl pedatdirldp #dp_userlacl #00hsacl keydatalacl #04hSaclrowdata Lacl #0fff7hsacl scandataLDP #0e1hmmm:lacl #0ff00hsacl pfdatdirnoplacl pcdatdirnopldp #5hsacl keybufferand #0ffhor #1ehxor #0ffhbcnd scanout ,eqscan:ldp #5hlacl scandataldp #0e1hsacl pfdatdirnoplacl pcdatdirnopand #0ffhor #1ehxor #0ffhbcnd scannext,eqldp #dp_userbit keybuffer,15bcnd key1,tcldp #5hlacl keydataadd #01hsacl keydatab scanoutkey1: bit keybuffer,10bcnd key2,tclacl keydataadd #02hsacl keydatab scanoutkey2: bit keybuffer,9bcnd key3,tclacl keydataadd #03hsacl keydatanopb scanoutkey3: bit keybuffer,8bcnd scanout,tclacl keydataadd #04hsacl keydatab scanout scannext:ldp #dp_userlacl scandatasfrldp #5hsacl scandatalacl keydataadd #04hsacl keydatalacl rowdatasub #01hsacl rowdatabcnd scan,neq scanout: retdisplay4:ldp #dp_userlacl r22sacl r21ldp #dp_userpage_cycle4:ldp #dp_userlacl r24sacl r16call write_ins0ldp #dp_userLaclr23sacl r16call write_ins0ldp #dp_userlacl #0c0hsacl r16call write_ins0arrange_cycle4:ldp #dp_userlacl lcdtabldp #dp_usertblr lcddatalacl lcddataldp #dp_usersacl r16call write_data0ldp #dp_userlacl lcdtabadd #1sacl lcdtabldp #dp_userlacl r22sub #1sacl r22lar ar0,#0ldp #dp_userlar ar6,r22mar *,ar6cmpr 00bcnd arrange_cycle4,NTC LDP #dp_userlacl r21sacl r22ldp #dp_userlar ar0,r23ldp #dp_userlar ar7,r25lacl r23sub #1hldp #dp_usersacl r23mar *,ar7cmpr 00bcnd page_cycle4,NTCretdisplay5:ldp #dp_userlacl r22sacl r21ldp #dp_userpage_cycle5:ldp #dp_userlacl r24sacl r16call write_ins1ldp #dp_userLaclr23sacl r16call write_ins1ldp #dp_userlacl #0c0h sacl r16call write_ins1arrange_cycle5:ldp #dp_userlacl lcdtabldp #dp_usertblr lcddatalacl lcddataldp #dp_usersacl r16call write_data1ldp #dp_userlacl lcdtabadd #1sacl lcdtab ldp #dp_userlacl r22sub #1sacl r22lar ar0,#0ldp #dp_userlar ar6,r22mar *,ar6cmpr 00bcnd arrange_cycle5,NTC LDP #dp_userlacl r21sacl r22ldp #dp_userlar ar0,r23ldp #dp_userlar ar7,r25lacl r23sub #1hldp #dp_usersacl r23mar *,ar7cmpr 00bcnd page_cycle5,NTCret write_ins1:ldp #dp_pf2lacl #03fchsacl padatdirnoplacl #1c08hsacl pcdatdirrpt #20nopldp #0e1hlacl #0301hsacl padatdirnopldp #dp_userlacl r16or #0ff00hldp #0e1hsacl pedatdirrpt #50nopldp #0e1hlacl #03fchsacl padatdirrpt #5nopldp #0e1h lacl #0302hsacl padatdirldp #dp_pf2lacl #1c0chsacl pcdatdirldp #dp_userrpt #5nopretwrite_ins0:ldp #dp_pf2lacl #03fchsacl padatdirnoplacl #1c04hsacl pcdatdirrpt #20nopldp #0e1h lacl #0301hsacl padatdir nopldp #dp_userlacl r16or #0ff00hldp #0e1hsacl pedatdirrpt #50nopldp #0e1hlacl #03fchsacl padatdirrpt #5nopldp #0e1h lacl #0302hsacl padatdir ldp #dp_pf2lacl #1c0chsacl pcdatdirldp #dp_userrpt #5nopretwrite_data1:ldp #0e1hlacl #0ff00hsacl padatdirnopldp #0e1hlacl #1c18hsacl pcdatdirrpt #10nopldp #0e1h lacl #0ff01hsacl padatdirnopldp #dp_userlacl r16or #0ff00hldp #0e1hsacl pedatdirrpt #5nopldp #0e1hlacl #0ff00hsacl padatdirrpt #5nopldp #0e1hlacl #0ff02hSaclpadatdir ldp #dp_pf2lacl #1c0chsacl pcdatdirldp #dp_userrpt #5nopretwrite_data0:ldp #0e1hlacl #0ff00hsacl padatdirnopldp #0e1hlacl #1c14hsacl pcdatdirrpt #10nopldp #0e1hlacl #0ff01hsacl padatdirnopldp #dp_userlacl r16or #0ff00hldp #0e1hsacl pedatdir rpt #5nopldp #0e1hlacl #0ff00hsacl padatdirrpt #5nopldp #0e1h lacl #0ff02hsacl padatdirldp #dp_pf2lacl #1c0chsacl pcdatdirldp #dp_userrpt #5nopretdisplay_cs0:ldp #5hsplk #0c0h,r16call write_ins0ldp #5hsplk #0b8h,r17 arrange00:ldp #5hsplk #040h,r18 ldp #5hlacl r17sacl r16call write_ins0ldp #5hlacl r18sacl r16call write_ins0arrange01:ldp #5hsplk #00h,r16call write_data0ldp #5hlacl r18Add#1hsacl r18ldp #5hmar *,ar6lar ar6,r18lar ar0,#128cmpr 01Bcndarrange01,TCldp #5hlacl r17add #1hsacl r17call delaylar ar5,r17lar ar0,#0c0hmar *,ar5cmpr 01bcndarrange00,tcretdisplay_cs1:ldp #5hsplk #0c0h,r16call write_ins1ldp #5hsplk #0b8h,r17 arrange10:ldp #5hsplk#040h,r18ldp #5hlacl r17Saclr16call write_ins1ldp #5hlaclr18sacl r16call write_ins1arrange11:ldp #5hsplk #00h,r16call write_data1ldp #5hlacl r18add #1h ;sacl r18ldp #5hmar *,ar6ar ar6,r18lar ar0,#128cmpr 01bcnd arrange11,TCldp #5hlacl r17add #1hsacl r17call delayar ar5,r17lar ar0,#0c0hmar *,ar5cmpr 01bcndarrange10,tc retdelay:mar *,ar3lar ar3,#0fffhlar ar0,#00hdelay1:sbrk #1hnopcmpr 00bcnd delay1,NTCretend。
12864液晶显示C语言程序代码
/******************************************************************/
/* 定义接口信息 */
DisplayGraphic(pic3); //显示图片3
delayms(200);
initinal(); //调用LCD字库初始化程序
delay(100); //大于100uS的延时程序
delay(100); //大于100uS的延时程序
TransferData(0x30,0); //Function Set
delay(37); ////大于37uS的延时程序
TransferData(0x08,0); //Display on Control
void TransferData(char data1,bit DI);
void display(void);
void display_grapic(void);
void delayms(unsigned int n);
void DisplayLine(unsigned char line1,unsigned char line2);
delay(100); //大于100uS的延时程序
TransferData(0x10,0); //Cursor Display Control光标设置
delay(100); //大于100uS的延时程序
/*-----------------------------------------------
名称:LCD12864 字库液晶 芯片组st7920
日期:2009.5
12864液晶时序
本帖最后由 zhaoshan413 于 2009-8-29 10:36 编辑
初始化操作如下: 1>芯片上电; 2>延时40ms 以上; 3>复位操作:RST 出现一个上升沿(RST=1;RST=0;RST=1;) ; 4>功能设定; 5>延时100us 以上; 6>再次进行功能设定; 7>延时37us; 8>显示开关控制; 9>延时100us 以上; 10>清除显示; 11>延时10ms 以上;
LCD液晶显示12864液晶资料
一、液晶显示模块概述12864A-1汉字图形点阵液晶显示模块,可显示汉字及图形,内置8192个中文汉字(16X16点阵)、128个字符(8X16点阵)及64X256点阵显示RAM(GDRAM)。
主要技术参数和显示特性:电源:VDD 3.3V~+5V(内置升压电路,无需负压);显示内容:128列× 64行显示颜色:黄绿显示角度:6:00钟直视LCD类型:STN与MCU接口:8位或4位并行/3位串行配置LED背光多种软件功能:光标显示、画面移位、自定义字符、睡眠模式等二、外形尺寸1.外形尺寸图2.主要外形尺寸二、模块引脚说明逻辑工作电压(VDD):4.5~5.5V电源地(GND):0V工作温度(Ta):0~60℃(常温) / -20~75℃(宽温)三、接口时序模块有并行和串行两种连接方法(时序如下):8位并行连接时序图MPU写资料到模块MPU从模块读出资料2、串行连接时序图串行数据传送共分三个字节完成: 第一字节:串口控制—格式 11111ABCA 为数据传送方向控制:H 表示数据从LCD 到MCU ,L 表示数据从MCU 到LCDB 为数据类型选择:H 表示数据是显示数据,L 表示数据是控制指令C 固定为0第二字节:(并行)8位数据的高4位—格式 DDDD0000 第三字节:(并行)8位数据的低4位—格式 0000DDDD 串行接口时序参数:(测试条件:T=25℃VDD=4.5V)四、用户指令集备注:1、当模块在接受指令前,微处理顺必须先确认模块内部处于非忙碌状态,即读取BF 标志时BF 需为0,方可接受新的指令;如果在送出一个指令前并不检查BF 标志,那么在前一个指令和这个指令中间必须延迟一段较长的时间,即是等待前一个指令确实执行完成,指令执行的时间请参考指令表中的个别指令说明。
2、“RE ”为基本指令集与扩充指令集的选择控制位元,当变更“RE ”位元后,往后的指令集将维持在最后的状态,除非再次变更“RE ”位元,否则使用相同指令集时,不需每次重设“RE ”位元。
12864液晶屏汇编程序
12864液晶屏汇编程序[ 作者:佚名 | 转贴自:本站原创 | 点击数:211 | 更新时间:2005-3-28 | 文章录入:qwll20000 ] XCS BIT 00H ;显示器片选0=CS1,1=CS2 ;20H-2FH为位寻址区,位地址从00H-7FH BZPD BIT 01H ;0=上8X8半字,1=下8X8半字HHBZ BIT 02H ;换行标志HZDH BIT 03H ;0=显示汉字,1=显示动画LCD_RW BIT P3.0LCD_DI BIT P3.1LCD_E BIT P3.3LCD_CS1 BIT P3.5LCD_CS2 BIT P3.4LCD_OPEN DA TA 30HLCD_LINE DATA 31HLCD_PAGE DATA 32HLCD_Y DA TA 33HYCPD DA TA 34H ;左右半屏溢出判断HHPD DA TA 35H ;换行判断XWPD DA TA 36H ;写完一整屏判断ORG 0000HMOV SP,#40HSETB XCS ;选择CS2MOV LCD_OPEN,#01H ;开显示器1,关显示器0LCALL LCDOPENMOV LCD_LINE,#00H ;设置起始行LCALL SETLINEMOV LCD_PAGE,#00H ;设置页地址 LCALL SETPAGEMOV LCD_Y,#00H ;设置列地址 LCALL SETYLJMP CLRST1CLR4:INC LCD_PAGECLRST1:LCALL SETPAGEMOV R7,#40HCLR5:MOV A,#0FFH ;显示校验LCALL LCDWRDATADJNZ R7,CLR5MOV A,LCD_PAGECJNE A,#07H,CLR4MOV LCD_LINE,#00HLCALL SETLINEMOV LCD_PAGE,#00HLCALL SETPAGEMOV LCD_Y,#00HLCALL SETYLJMP CLRST2CLR6:INC LCD_PAGECLRST2:LCALL SETPAGEMOV R7,#40HCLR7:MOV A,#00H ;清显示LCALL LCDWRDATADJNZ R7,CLR7MOV A,LCD_PAGECJNE A,#07H,CLR6CLR XCS ;选择CS1MOV LCD_OPEN,#01H ;开显示器1, 关显示器0 LCALL LCDOPENMOV LCD_LINE,#00HLCALL SETLINE ;设置起始行MOV LCD_PAGE,#00HLCALL SETPAGE ;设置页地址MOV LCD_Y,#00HLCALL SETY ;设置列地址LJMP CLRST3CLR0:INC LCD_PAGECLRST3:LCALL SETPAGEMOV R7,#40HCLR1:MOV A,#0FFH ;显示校验LCALL LCDWRDATADJNZ R7,CLR1MOV A,LCD_PAGECJNE A,#07H,CLR0MOV LCD_LINE,#00HLCALL SETLINEMOV LCD_PAGE,#00HLCALL SETPAGEMOV LCD_Y,#00HLCALL SETYLJMP CLRST4CLR2:INC LCD_PAGECLRST4:LCALL SETPAGEMOV R7,#40HCLR3:MOV A,#00H ;清显示LCALL LCDWRDATADJNZ R7,CLR3MOV A,LCD_PAGECJNE A,#07H,CLR2;初始化完毕************************************************************************* CLR HZDHWRLCD:JNB HZDH,XZFXDH:MOV DPTR,#DHDOT ;写动画或图片LJMP DH0XZF:MOV DPTR,#HZDOT ;写字符(汉字或字母或符号)MOV XWPD,#00HHZ0:CLR XCSMOV LCD_LINE,#00H ;置起始行LCALL SETLINEMOV LCD_PAGE,#00HLCALL SETPAGE ;置页MOV LCD_Y,#00H ;置列LCALL SETYMOV HHPD,#00HHZ7:MOV YCPD,#00HHZ8:CLR BZPDHZ3:MOV R0,#08H ;写左上8个Y列HZ1:MOV A,#00HMOVC A,@A+DPTRLCALL LCDWRDATAINC DPTRINC LCD_YDJNZ R0,HZ1JB BZPD,HZ2CLR C ;Y列减8, 即返回扫描MOV A,LCD_YSUBB A,#08HMOV LCD_Y,ALCALL SETYINC LCD_PAGE ;页地址加1,即换第2页扫描 LCALL SETPAGESETB BZPDLJMP HZ3HZ2:DEC LCD_PAGE ;返回到第1页中,准备下一个半字扫描 LCALL SETPAGEINC YCPDMOV A,YCPDCJNE A,#08H,HZ8JB XCS,HZ9SETB XCS ;换屏LCALL SETPAGEMOV LCD_Y,#00H ;置列LCALL SETYLJMP HZ7HZ9:CLR XCS ;写完一行后从CS2返回到CS1中INC LCD_PAGEINC LCD_PAGELCALL SETPAGE ;下一行开始MOV LCD_Y,#00HLCALL SETYINC HHPDMOV A,HHPDCJNE A,#04H,HZ7INC XWPD ;换第二幅画面MOV A,XWPDCJNE A,#02H,HZ0LJMP$DH0:MOV XWPD,#00HDH1:CLR XCSMOV LCD_LINE,#00H ;置起始行 LCALL SETLINEMOV LCD_PAGE,#00HLCALL SETPAGE ;置页MOV LCD_Y,#00H ;置列LCALL SETYMOV HHPD,#00HDH2:MOV R0,#40H ;写上64个Y列 DH3:MOV A,#00HMOVC A,@A+DPTRLCALL LCDWRDATAINC DPTRDJNZ R0,DH3JB XCS,DH4SETB XCSLCALL SETPAGEMOV LCD_Y,#00HLCALL SETYLJMP DH2DH4:CLR XCS ;写完一行后从CS2返回到CS1中 INC LCD_PAGELCALL SETPAGE ;下一行开始MOV LCD_Y,#00HLCALL SETYINC HHPDMOV A,HHPDCJNE A,#08H,DH2INC XWPD ;换第二幅画面MOV A,XWPDCJNE A,#02H,DH1LJMP$LCDWRINST:NOPJB XCS,INS0CLR LCD_CS1SETB LCD_CS2LJMP INS1INS0:SETB LCD_CS1CLR LCD_CS2INS1:SETB LCD_ECLR LCD_DICLR LCD_RWMOV P1,ALCALL DLY10CLR LCD_ELCALL DLY10RETLCDWRDATA:NOPJB XCS,DA T0CLR LCD_CS1SETB LCD_CS2LJMP DA T1DA T0:SETB LCD_CS1CLR LCD_CS2DA T1:SETB LCD_ESETB LCD_DICLR LCD_RWMOV P1,ALCALL DLY10CLR LCD_ELCALL DLY10NOPRETLCDOPEN:MOV A,LCD_OPEN ;开显示器 ANL A,#3FHORL A,#3EHLCALL LCDWRINSTNOPRETSETLINE:MOV A,LCD_LINEORL A,#0C0H ;设置起始行LCALL LCDWRINSTRETSETPAGE:MOV A,LCD_PAGEANL A,#0BFHORL A,#0B8H ;设置页地址 LCALL LCDWRINSTNOPRETSETY:MOV A,LCD_YANL A,#7FHORL A,#40HNOP ;设置列地址LCALL LCDWRINSTNOPRETDL Y10:NOPMOV R5,#01HDL1:MOV R4,#01HDL2:MOV R6,#0FHDL3:DJNZ R6,DL3DJNZ R4,DL2DJNZ R5,DL1NOPRETHZDOT:;新 CD0C2DB 000H,044H,04CH,07CH,0D7H,0E6H,07CH,05CH DB 000H,022H,01AH,04EH,0FFH,07FH,00EH,09AH DB 044H,0FEH,0FCH,046H,0C2H,0C3H,062H,040H DB 060H,03FH,01FH,000H,0FFH,0FFH,000H,000H;年 CC4EADB 000H,020H,010H,018H,0ECH,0CFH,04AH,048H DB 000H,004H,004H,004H,007H,007H,004H,004H DB 0F8H,0F8H,048H,048H,068H,04CH,008H,000H DB 0FFH,0FFH,004H,004H,004H,004H,006H,004H;快 CBFECDB 000H,0C0H,060H,0FFH,0FEH,030H,060H,008H DB 000H,000H,000H,0FFH,07FH,080H,041H,071H DB 008H,0FFH,0FEH,008H,0F8H,0FCH,008H,000H DB 03DH,00FH,007H,00DH,039H,071H,0E1H,041H;乐 CC0D6DB 000H,000H,080H,080H,0FEH,0FCH,084H,084H DB 000H,040H,020H,030H,01CH,00EH,024H,040H DB 0FEH,0F6H,082H,083H,0C2H,080H,000H,000H DB 0FFH,07FH,000H,002H,00CH,018H,070H,020H;欢 CBBB6DB 000H,034H,0C4H,004H,0C4H,0FCH,03EH,024H DB 000H,040H,038H,00FH,007H,03CH,098H,060H DB 018H,00EH,0EFH,0CAH,048H,038H,01CH,008H DB 030H,01CH,00FH,007H,01CH,070H,0E0H,040H;迎 CD3ADDB 000H,040H,046H,0DCH,0E8H,040H,0FEH,0FCH DB 000H,040H,0E0H,03FH,01FH,032H,067H,0C3H DB 006H,003H,0FDH,0FCH,004H,0FCH,0FEH,004H DB 0C2H,0C1H,0FFH,0DFH,0C2H,0C7H,0C3H,040H;使 CCAB9DB 000H,080H,060H,0F8H,0EFH,006H,008H,0F8H DB 000H,000H,000H,0FFH,07FH,080H,080H,043H DB 0E8H,028H,0FFH,0FEH,028H,0E8H,0FCH,028H DB 065H,039H,01FH,037H,061H,063H,0C1H,040H;用 CD3C3DB 000H,000H,000H,0FFH,0FEH,022H,022H,022H DB 000H,080H,070H,03FH,00FH,002H,002H,002H DB 0FEH,0FEH,022H,022H,022H,0FEH,0FFH,002H DB 07FH,03FH,002H,042H,042H,0FFH,07FH,000H;杭 CBABCDB 000H,010H,0D0H,0FFH,0FEH,090H,010H,008H DB 000H,006H,001H,0FFH,07FH,001H,083H,040H DB 0E8H,0C9H,04FH,04EH,0C8H,0E8H,04CH,008H DB 07FH,03FH,000H,000H,07FH,0FFH,0C0H,070H;州 CD6DDDB 000H,010H,0E0H,0C0H,0FFH,0FEH,010H,0E0H DB 000H,080H,041H,070H,03FH,00FH,000H,001H DB 0C0H,0FEH,0FCH,030H,0E0H,0C0H,0FFH,0FEH DB 000H,03FH,01FH,000H,001H,000H,0FFH,07FH;求 CC7F3DB 000H,000H,008H,068H,0C8H,088H,008H,0FFH DB 000H,010H,070H,038H,00DH,026H,041H,0FFH DB 0FEH,088H,0CBH,07EH,02CH,008H,000H,000H DB 07FH,003H,006H,01CH,038H,070H,020H,000H;是 CCAC7DB 000H,080H,080H,080H,0FFH,0BEH,0AAH,0AAH DB 000H,080H,060H,038H,00FH,01AH,030H,020H DB 0AAH,0AAH,0AAH,0FEH,0BFH,082H,0C0H,080H DB 07FH,07FH,044H,0C4H,0C6H,0C4H,0C0H,040H;医 CD2BDDB 000H,000H,0FFH,0FEH,042H,0A2H,0BAH,09EH DB 000H,040H,0FFH,07FH,060H,050H,058H,04CH DB 096H,0F2H,0F2H,092H,09AH,0D3H,082H,000H DB 046H,043H,041H,046H,04CH,058H,068H,040H;学 CD1A7DB 000H,010H,038H,01CH,00BH,04EH,048H,04BH DB 000H,000H,004H,004H,004H,004H,044H,044HDB 04EH,0C8H,0ECH,04FH,00AH,038H,01CH,008H DB 0FFH,07FH,004H,004H,004H,006H,004H,000H;科 CBFC6DB 000H,024H,0A4H,0FEH,0FEH,0A3H,022H,0C0H DB 000H,00CH,003H,0FFH,07FH,001H,00BH,008H DB 08CH,038H,010H,0FFH,0FEH,000H,000H,000HDB 00BH,005H,004H,0FFH,07FH,002H,003H,002H;技 CBCBCDB 000H,010H,010H,0FFH,0FEH,010H,098H,048H DB 000H,00CH,046H,0FFH,07FH,001H,080H,040H DB 0C8H,048H,07FH,07EH,0C8H,0E8H,04CH,008H DB 061H,037H,01CH,01EH,037H,061H,0E0H,040H;有 CD3D0DB 000H,084H,044H,064H,034H,0FCH,0EFH,026H DB 000H,000H,000H,000H,000H,0FFH,07FH,009H DB 024H,024H,024H,0E4H,0F4H,024H,006H,004H DB 009H,009H,049H,0FFH,07FH,000H,000H,000H;限 CCFDEDB 000H,0FFH,0FEH,042H,0BEH,01FH,002H,0FFH DB 000H,0FFH,0FFH,008H,01FH,00FH,040H,0FFH DB 0FEH,092H,092H,092H,0FEH,0FFH,002H,000H DB 07FH,061H,036H,01CH,039H,06EH,0E4H,040H;公 CB9ABDB 000H,000H,080H,0C0H,070H,03EH,00FH,082H DB 000H,001H,000H,060H,0F0H,078H,06EH,067H DB 0C0H,080H,00FH,03EH,070H,0E0H,0C0H,080H DB 021H,022H,026H,03CH,0F8H,070H,001H,000H;司 CCBBEDB 000H,000H,010H,0D2H,092H,092H,092H,092H DB 000H,000H,000H,01FH,00FH,008H,008H,008HDB 01FH,00FH,000H,040H,040H,0FFH,07FH,000H;地 CB5D8DB 000H,020H,020H,0FEH,0FCH,020H,060H,0F8H DB 000H,010H,030H,01FH,01FH,008H,004H,07FH DB 0F0H,020H,0FFH,0FEH,010H,0F0H,0F8H,010H DB 0FFH,0C0H,0C7H,0C7H,0C2H,0C7H,0F3H,040H;址 CD6B7DB 000H,020H,020H,0FEH,0FCH,020H,020H,0E0H DB 000H,010H,030H,03FH,01FH,058H,048H,07FH DB 0C0H,000H,000H,0FFH,0FEH,040H,060H,040H DB 07FH,040H,040H,07FH,07FH,040H,060H,040H;: CA3BADB 000H,000H,000H,000H,000H,000H,000H,000H DB 000H,000H,036H,036H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H;通 CCDA8DB 000H,040H,046H,0DCH,0E8H,040H,000H,0F9H DB 000H,040H,0E0H,03FH,01FH,030H,060H,0FFH DB 0F1H,055H,0FDH,0F9H,057H,0F3H,0F9H,010H DB 0DFH,0C2H,0DFH,0CFH,0D2H,0FFH,0DFH,040H;惠 CBBDDDB 000H,000H,002H,0FEH,0FAH,0AAH,0AAH,0FFHDB 0FFH,0AAH,0AAH,0FAH,0FEH,00AH,000H,000H DB 0FBH,0D2H,0C2H,0F2H,04FH,016H,070H,020H;北 CB1B1DB 000H,020H,020H,020H,020H,0FEH,0FEH,000H DB 000H,020H,060H,020H,010H,0FFH,0FFH,000H DB 000H,0FFH,0FEH,082H,0C0H,060H,038H,010H DB 000H,07FH,0FFH,0C1H,0C0H,0C0H,0F0H,040H;路 CC2B7DB 000H,07FH,03EH,0E2H,0BEH,07FH,002H,010H DB 000H,07CH,060H,03FH,03FH,012H,00BH,001H DB 08CH,0DFH,066H,074H,0DCH,08EH,004H,000H DB 0FFH,07EH,042H,042H,0FEH,07FH,003H,001H;2 CHAR_32DB 008H,00CH,084H,0C4H,064H,03CH,018H,000H DB 00EH,00FH,009H,008H,008H,00CH,00CH,000H;8 CHAR_38DB 0B8H,0FCH,044H,044H,044H,0FCH,0B8H,000H DB 007H,00FH,008H,008H,008H,00FH,007H,000H;号 CBAC5DB 000H,080H,080H,080H,0BFH,09EH,092H,092H DB 000H,000H,000H,000H,004H,00EH,007H,005H DB 092H,092H,092H,0BEH,09FH,082H,0C0H,080H DB 024H,044H,0E4H,07CH,01EH,004H,000H,000H;电 CB5E7DB 000H,000H,0F8H,0F0H,090H,090H,090H,0FFH DB 000H,000H,00FH,007H,004H,004H,004H,07FH DB 0FEH,090H,090H,090H,0F0H,0F8H,010H,000H DB 0FFH,0C4H,0C4H,0C4H,0CFH,0C7H,0F0H,040H;话 CBBB0DB 000H,040H,046H,0DCH,0E8H,040H,020H,024H DB 000H,000H,020H,07FH,03FH,010H,008H,0FFH DB 024H,024H,0FEH,0FEH,026H,023H,032H,020H DB 07EH,042H,043H,043H,042H,0FEH,07FH,002H;: CA3BADB 000H,000H,000H,000H,000H,000H,000H,000H DB 000H,000H,036H,036H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H;0 CHAR_30DB 0F8H,0FCH,004H,0C4H,024H,0FCH,0F8H,000H DB 007H,00FH,009H,008H,008H,00FH,007H,000H;5 CHAR_35DB 07CH,07CH,044H,044H,0C4H,0C4H,084H,000H DB 004H,00CH,008H,008H,008H,00FH,007H,000H;7 CHAR_37DB 00CH,00CH,004H,084H,0C4H,07CH,03CH,000HDB 000H,000H,00FH,00FH,000H,000H,000H,000H;1 CHAR_31DB 000H,010H,018H,0FCH,0FCH,000H,000H,000H DB 000H,008H,008H,00FH,00FH,008H,008H,000H;- CHAR_2DDB 080H,080H,080H,080H,080H,080H,080H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H;8 CHAR_38DB 0B8H,0FCH,044H,044H,044H,0FCH,0B8H,000H DB 007H,00FH,008H,008H,008H,00FH,007H,000H;2 CHAR_32DB 008H,00CH,084H,0C4H,064H,03CH,018H,000H DB 00EH,00FH,009H,008H,008H,00CH,00CH,000H;6 CHAR_36DB 0F0H,0F8H,04CH,044H,044H,0C0H,080H,000H DB 007H,00FH,008H,008H,008H,00FH,007H,000H;0 CHAR_30DB 0F8H,0FCH,004H,0C4H,024H,0FCH,0F8H,000H DB 007H,00FH,009H,008H,008H,00FH,007H,000H;4 CHAR_34DB 0C0H,0E0H,0B0H,098H,0FCH,0FCH,080H,000H DB 000H,000H,000H,008H,00FH,00FH,008H,000H;7 CHAR_37DB 00CH,00CH,004H,084H,0C4H,07CH,03CH,000HDB 000H,000H,00FH,00FH,000H,000H,000H,000H;1 CHAR_31DB 000H,010H,018H,0FCH,0FCH,000H,000H,000HDB 000H,008H,008H,00FH,00FH,008H,008H,000H;5 CHAR_35DB 07CH,07CH,044H,044H,0C4H,0C4H,084H,000HDB 004H,00CH,008H,008H,008H,00FH,007H,000HDHDOT:;-------------------------------------------------------------------------------DB000H,000H,000H,000H,000H,000H,000H,000H,007H,0E7H,0E3H,0E1H,0E1H,0E1H,0E1H,0C1H, DB0C1H,081H,081H,081H,083H,083H,083H,083H,087H,087H,08FH,08FH,09FH,0BFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0F3H,0F3H,0F1H,0E1H,061H,061H,020H, DB030H,030H,0B0H,0B0H,0B0H,0B8H,0B8H,0BCH,0BCH,03EH,03EH,03FH,03FH,07FH,07FH,07FH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FEH,0FEH,0FCH,0FCH,0FCH,0FEH,0FFH, DB0F7H,0E3H,0E7H,0EFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,001H,07FH,0FFH,0F3H,083H,083H,081H,DB001H,001H,000H,080H,080H,000H,002H,002H,002H,006H,004H,0A5H,0EDH,0EDH,0EBH,0DBH, DB0F7H,0BFH,07FH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0F7H,089H,080H,082H,0C0H,080H, DB000H,000H,000H,000H,000H,088H,0C0H,0F8H,0F8H,0F8H,0F0H,0F0H,0E0H,0C0H,0C0H,0F0H, DB0F8H,0F8H,0FCH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,00FH,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,07FH,0FFH,0FFH,0FFH,0FFH,DB0FFH,0FEH,0FFH,0FFH,0FFH,0FFH,0FEH,0FEH,0FEH,0FEH,0FEH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,03FH,00FH,003H,000H,000H,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,03FH,03FH,07FH,0BFH,03FH,03FH, DB03FH,01FH,01FH,00FH,007H,007H,001H,000H,000H,000H,000H,000H,000H,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,003H,03FH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,01FH,000H,000H,07CH,0FFH,0FFH,078H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,003H,0FFH,DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0E3H,0E3H,0C3H,087H,08FH,01FH,01FH,0BFH,0BFH,0FFH,0FFH, DB0FFH,0F7H,0F3H,0F3H,0FBH,0FBH,0FBH,0FBH,0FBH,0FBH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,07FH,07FH,07FH,07FH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,00FH,000H,000H,000H,000H,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,0E0H,0F8H,0FCH,0FEH,0FEH,0FEH,0FEH,0FEH,0FCH,0FCH, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0F8H,0FFH,DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,DB0FFH,0FDH,0F9H,0F3H,0E7H,0C7H,087H,007H,007H,0C7H,087H,087H,08FH,08FH,08FH,0CFH, DB0CFH,0DFH,0FFH,09FH,0DFH,0DFH,0FFH,0CFH,0EFH,0EFH,0FFH,0FFH,0CFH,0CFH,0E7H,0E7H, DB0E3H,0E3H,0E3H,0F1H,0F9H,0F9H,0F8H,0FCH,0FCH,0FEH,0FEH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,03FH,00FH,007H,000H,000H,000H,000H,000H,000H,000H,000H,000H,DB000H,000H,000H,000H,000H,000H,000H,007H,027H,07FH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0E0H,0FCH,0FFH,0FFH,DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0F8H,0F1H,0F3H,0E7H,0CFH,0CFH,0DFH,0DFH, DB09FH,09FH,0BFH,0BFH,0BFH,09FH,0DFH,0DFH,0DFH,0CFH,0EFH,0FFH,0FFH,0FFH,0FBH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0F7H,0FDH,0FCH,0FCH,0FEH,0FFH,0FCH,0C0H,000H,000H,000H,000H,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,001H,0F1H,0FFH,0FFH,。
12864液晶屏驱动程序
BMPwith=*PicData;
PicData++;
BMPheight=(*PicData)/8;
PicData++;
//BMPLen=BMPheight/8*BMPwith
for(BMPheightLen=0;BMPheightLen<BMPheight;BMPheightLen++)
Series = Series << 1;
}
}
/***********************************
** 函数名称: Write_Data
** 功能描述: 传送数据
** 输 入: dat
** 输 出 : 无
** 全局变量:无
** 调用模块: Busy,
******************************************/
//图像反色显示 0 否 1是
bit LCD_DisplayReserve_Driver;
//定义LCD显示的全局变量
#define CS_Port P3_0
#define A0_Port P3_1
#define SI_Port P3_2
{
switch (PIN)
{
case CS :
CS_Port=1;
break;
case A0 :
A0_Port=1;
break;
case SI :
SI_Port=1;
break;
case SCL :
SCL_Port=1;
12864的液晶显示程序(无字库)
12864的液晶显示程序(无字库)12864.h#ifndef __12864_H__#define __12864_H__#include#include/***************************************利用I/O口模拟点阵液晶所需时序点阵液晶控制端口定义,需根据硬件适当改变****************************************/sbit LCD_RS = P2^0;//控制端口定义sbit LCD_RW = P2^1;sbit LCD_E = P2^2;sbit LCD_CSA = P2^3;//H选通,即高电平有效sbit LCD_CSB = P2^4;#define LCD_Data P0//LCD数据端口8位#define R 1#define L 2/*****************************************函数声明*****************************************/void ReadStatusLCD(unsigned char select);//从LCD读出忙标志位unsigned char ReadDataLCD(unsigned char select);//从LCD 读出数据void WriteDataLCD(unsigned char WDLCD,unsigned char select);//向LED写入数据void WriteCommandLCD(unsigned char WCLCD , unsigned char BusyC,unsigned char select);//向LCD写入命令void LcdReset(void) ;//初始化函数,完成液晶模块的初始设置void clear_LCD(unsigned char select);//清屏函数void Clr_All_Lcd(void);//全清屏函数void set_XY(unsigned char Column,unsigned char Page);//设置数据写入或读出的地址,通过页号和列数可以唯一确定一个地址void xy_Write(unsigned char Column,unsigned char Page,unsigned char dataW);//向指定行列写数据void LcmPutDots(unsigned char Column,unsigned char Page, unsigned char DotByte );//显示点void whiteword(unsigned char Column,unsigned char Page, const unsigned char puts[][16] );//显示16×16点阵的编码void WhiteWord_Com(unsigned char Column,unsigned char Page,unsigned char C_num,unsigned char V_num, unsigned char * puts );//通用的显示函数void Drawing_dot(unsigned char x,unsigned char y);void Drawing_line_vertical(unsigned x);#endif12864.c/****************************************************LCD12864点阵液晶屏,通过I/O口直接控制,采用模拟时序控制****************************************************/#include"12864.h"#include/*********************************************************** 功能:从LCD读取状态位变量:select用于选择LCD屏的左右,1选择左屏,2选择右屏***********************************************************/ void ReadStatusLCD(unsigned char select){switch(select){case 1:{LCD_CSA=1;LCD_CSB=0;break;}//左case 2:{LCD_CSA=0;LCD_CSB=1;break;}//右default: break;}LCD_Data = 0xff;//置位输入口,已实现输入LCD_RS=0;LCD_RW=1;LCD_E=1;//高电平读取数据//_nop_(); //若晶振速度高,可在此作延时处理while(LCD_Data&0x80);//最高位为忙标志,检测忙信号状态LCD_E=0;//_nop_(); //若晶振速度高,可在此作延时处理}/*********************************************************** 功能:从LCD读取数据变量:select用于选择LCD屏的左右,1选择左屏,2选择右屏***********************************************************/ unsigned char ReadDataLCD(unsigned char select){unsigned char dataR;LCD_Data = 0xff;//置位输入口,已实现输入switch(select){case 1:{LCD_CSA=1;LCD_CSB=0;break;}//左case 2:{LCD_CSA=0;LCD_CSB=1;break;}//右default: break;}LCD_RW=1;LCD_RS=1;LCD_E = 1;// 操作允许脉冲信号,高电平读出//_nop_(); //若晶振速度高,可在此作延时处理dataR = LCD_Data;LCD_E= 0;return dataR;}/***********************************************************功能:向LCD写入数据参数:WDLCD待写入的字符数据select用于选择LCD屏的左右,1选择左屏,2选择右屏***********************************************************/void WriteDataLCD(unsigned char WDLCD,unsigned char select){switch(select){case 1:{LCD_CSA=1;LCD_CSB=0;break;}//左case 2:{LCD_CSA=0;LCD_CSB=1;break;}//右default: break;}ReadStatusLCD(select);//检测忙标志LCD_RS = 1;LCD_RW = 0;LCD_Data = WDLCD;LCD_E = 1;//_nop_(); //若晶振速度高,可在此作延时处理LCD_E = 0; //下降沿写入数据//_nop_(); //若晶振速度高,可在此作延时处理}/***********************************************************功能:向LCD写入命令参数:WDLCD待写入的字符数据BusyC是否要检查忙标志位选择标志,1为进行,0为不检测select用于选择LCD屏的左右,1选择左屏,2选择右屏***********************************************************/void WriteCommandLCD(unsigned char WCLCD , unsigned char BusyC,unsigned char select) {if(BusyC) ReadStatusLCD(select);//根据需要检测忙switch(select){case 1:{LCD_CSA=1;LCD_CSB=0;break;}//左case 2:{LCD_CSA=0;LCD_CSB=1;break;}//右default: break;}LCD_Data = WCLCD;LCD_RS = 0;LCD_RW = 0;LCD_E = 1;//_nop_(); //若晶振速度高,可在此作延时处理LCD_E = 0;}/************************************************************** **************** 功能:清显示RAM区(清屏)参数:select为驱动控制器选择1为左2为右*************************************************************** **************** */void clear_LCD(unsigned char select){unsigned char i,j;for(i=0;i<8;i++){ //8页,换页清零WriteCommandLCD( 0xb8|i,1 ,select);//页面地址设置,并分别写入左右模块中WriteCommandLCD( 0x40,1 ,select);//列地址设置,设置为0列,并分别写入左右三个模块中for(j=0;j<64;j++){ //页内清零WriteDataLCD( 0 ,select);}}}/************************************************************** *************** 功能:清LCD左右屏*************************************************************** **************/ void Clr_All_Lcd(void){clear_LCD(1);clear_LCD(2);}/************************************************************** **************** 功能:LCD初始化,分为左,右模块初始化参数:select为驱动控制器选择1为左2为右*************************************************************** **************** */void LcdReset(void){unsigned char i;for(i=0;i<5;i++){WriteCommandLCD( 0xc0,0 ,R);//设置显示起始行为第一行,并分别写入左右模块中,不检测忙标志WriteCommandLCD( 0xc0,0 ,L);//_nop_(); //若晶振速度高,可在此作延时处理}WriteCommandLCD( 0xc0,1 ,R);//设置显示起始行为第一行,并分别写入左右模块中,检测忙标志WriteCommandLCD( 0xc0,1 ,L);WriteCommandLCD( 0x3f,1 ,R);//开显示设置,并分别写入左右模块中WriteCommandLCD( 0x3f,1 ,L);clear_LCD(R);//清左屏clear_LCD(L);//清右屏}/************************************************************** **************** 功能:设置数据写入或读出的地址,通过页号和列数可以唯一确定一个地址参数:Column表示列号,Page表示页号*************************************************************** **************** */void set_XY(unsigned char Column,unsigned char Page){unsigned char x,y;unsigned char select;switch (Column&0x40) //完成左右屏的判断,根据列号完成区分,<64为左屏,>=64为右屏{case 0x00: {select = 1;ReadStatusLCD(select);break;}/*为左区*/case 0x40: {select = 2;ReadStatusLCD(select);break;}/*为右区*/}x = Column&0x3F|0x40; /* col.and.0x3f.or.Set Y Address*/ y = Page&0x07|0xB8; /* row.and.0x07.or.set Page */WriteCommandLCD( y,1 ,select);//设置页面地址WriteCommandLCD( x,1 ,select);//设置列地址}/************************************************************** **************** 功能:根据地址值(页数和列号),写入数据,即写入显示缓冲区,便可以显示在LCD屏上参数:Column表示列号,Page表示页号,dataW表示待写入的数据*************************************************************** **************** */void xy_Write(unsigned char Column,unsigned char Page,unsigned char dataW){set_XY(Column,Page);LCD_RW=0;LCD_RS=1;_nop_();//若晶振速度高,可在此作延时处理LCD_Data = dataW;// 送数据_nop_(); //若晶振速度高,可在此作延时处理LCD_E = 1;_nop_(); //若晶振速度高,可在此作延时处理LCD_E= 0; // 操作允许脉冲信号,下降沿写入}/************************************************************** **************** 功能:用于显示点阵参数:Column表示列号,Page表示页号,*************************************************************** **************** */void LcmPutDots(unsigned char Column,unsigned char Page, unsigned char DotByte ){unsigned char i;i=Column;for(;Page<8;Page++){for(;Column<128;Column++){xy_Write(Column,Page,DotByte);//DotByte = ~DotByte;}Column=i;}}/************************************************************** **************** 功能:在指定列,指定页显示待显示的点阵编码,用于显示16*16点阵码参数:Column表示列号,Page表示页号,puts待显示的点阵编码首指针*************************************************************** **************** */void whiteword(unsigned char Column,unsigned char Page, const unsigned char puts[][16] ){unsigned char i,j;for(i=0;i<2;i++)//此处的2为控制点阵行数,实际点阵行数为2*8=16行,此处的16(对应的点行数)应为8的倍数{for(j=0;j<16;j++)//此处控制每行显示的列数{xy_Write(Column+j,Page+i,puts[i][j]);}}}/****************************************************************************** 功能:在指定列,指定页显示待显示指定点阵的编码参数:Column表示列号,Page表示页号,C_num为显示点阵的行数(物理行8的倍数),V_num 为列(物理列)puts待显示的点阵编码首指针*************************************************************** **************** */void WhiteWord_Com(unsigned char Column,unsigned char Page,unsigned char C_num,unsigned char V_num, unsigned char * puts){unsigned char i,j;for(i=0;i<(C_num/8);i++)//此处的2为控制点阵行数,实际点阵行数为2*8=16行,此处的16(对应的点行数)应为8的倍数{for(j=0;j<="">{xy_Write(Column+j,Page+i,*(puts+i*V_num+j));//注意地址的变化规律}}}/************************************************************** **************** 功能:绘点参数:Column表示列号,Page表示页号,C_num为显示点阵的行数(物理行8的倍数),V_num 为列(物理列)puts待显示的点阵编码首指针*************************************************************** **************** */void Drawing_dot(unsigned char x,unsigned char y){unsigned char y_byte,x_bit,y_bit,reverse_y;//此处y_byte为page,y_bit为具体行号,x_bit 为行号unsigned char dot;reverse_y=63-y;x_bit=x;y_byte=reverse_y/8;y_bit=y%8;// for(;x_bit<128;x_bit++)if(y_bit==0) dot=0x80;if(y_bit==1) dot=0x40;if(y_bit==2) dot=0x20;if(y_bit==3) dot=0x10;if(y_bit==4) dot=0x08;if(y_bit==5) dot=0x04;if(y_bit==6) dot=0x02;if(y_bit==7) dot=0x01;xy_Write(x_bit,y_byte,dot);/* reverse_y=64-y;if(y_bit==7) y_byte=y_byte-1;y_bit=y%8;if(y_byte==(-1)) break;*/}/************************************************************** **************** 功能:绘垂直直线参数:x表示列号*************************************************************** **************** */void Drawing_line_vertical(unsigned char x){xy_Write(x,0,0xff);xy_Write(x,1,0xff);xy_Write(x,2,0xff);xy_Write(x,3,0xff);xy_Write(x,4,0xff);xy_Write(x,5,0xff);xy_Write(x,6,0xff);xy_Write(x,7,0xff);}主程序.c/************************************************************** **************** ****************12864液晶屏上显示"南京绝妙科技发展有限公司,025-******** 开发板欢迎使用","0~9",刷新后重显。
12864学习笔记及常用指令
12864学习笔记及常用指令12864液晶深入学习笔记_1——基于msp430g2553(2012-08-30 15:56:01)转载▼标签:msp430学分类:学习探讨设计12864液晶12864液晶学习笔记Created on: 2012-8-30Author: zhang bin学习笔记for 12864redesigned by zhang bin2012-08-30versions:12_08_01这是我对12864的学习笔记,12864液晶功能很全面,使用起来也很方便,能够满足一般的研究和工程应用的需求。
下面我就对几个方面讲述一下我对它学习过程中的一些体会。
我会尽量全面的介绍,并且会主要针对一些特殊的应用和一些我认为要特别注意的地方进行较为详细的说明。
而对于那些较为固定的,常用的方面会简略一些。
其中的不管串行模式还是并行模式,对液晶的写指令,写数据,读操作等这些基本的操作都是一些比较固定的,基础的东西。
我认为只要能够看懂,并且能够在不同的处理器上移植就够了,没有必要非要自己对着手册时序图写出来。
因为有人已经写好了,而且工作稳定,我们只要在它的基础上学会应用就可以了。
现在是知识爆炸时期,知识,信息迅速膨胀,我们要学会使用已有的成果,然后在这个基础上自己再进行开发应用的研究。
我们不必一定要从底层开始把别人已经做的很成熟的东西再做一遍,这样不但效率不高,而且我们一般人的精力也不允许。
好了,不说废话了,下面就开始介绍,当然,那些基础层面的东西我也会介绍的。
下面所涉及到的程序,是针对msp430g2553的,都是我已经调通的,可以直接应用。
一,12864的介绍1,液晶显示模块是128×64 点阵的汉字图形型液晶显示模块,可显示汉字及图形,内置国标GB2312 码简体中文字库(16X16 点阵)、128 个字符(8X16 点阵)及64X256 点阵显示RAM(GDRAM)。
可与CPU 直接接口,提供两种界面来连接微处理机:8-位并行及串行两种连接方式。
12864液晶代码(很实用的)
#include<reg52.h>#include<intrins.h>#include<stdlib.h>#define uchar unsigned char#define uint unsigned int/*端口定义*/#define LCD_data P0sbit LCD_RS=P3^5;sbit LCD_RW=P3^6;sbit LCD_EN=P3^4;sbit LCD_PSB=P3^7;uchar dis1[10];uchar code dis2[]={"XXXXXXXXXXX@"};uchar code dis3[]={"XXXXXXXX"};uchar code dis4[]={"-------"};void delay_ms(uint x){int i,j;for(j = 0; j < x; j++){for(i = 0; i < 110; i++){;}}}/*写指令数据到LCDRS=L——表示DB0-DB7为显示指令数据RW=L——表示DB0-DB7数据被write(当E=“H-L”,指令数据被写到IR或DR) E=高脉冲此时DB0-DB7=指令码*/void write_cmd(uchar cmd){LCD_RS=0;LCD_RW=0;LCD_EN=0;P0=cmd;delay_ms(5);delay_ms(5);LCD_EN=0;}/*设定显示位置*/void lcd_pos(uchar X, uchar Y){uchar pos;if(X == 0){X = 0x80;}else if(X == 1){X = 0x90;}else if(X == 2){X = 0x88;}else if(X == 3){X = 0x98;}pos = X + Y;write_cmd(pos); //显示地址}/*写显示数据到LCD*//*RS=H ——表示DB0-DB7为显示数据RW=L ——RW=L,E='H-L',DB0-DB7数据被写到IR或DR E=高脉冲DB0-DB7=显示数据*/void write_dat(uchar dat){LCD_RS=1;LCD_RW=0;LCD_EN=0;P0=dat;delay_ms(5);delay_ms(5);LCD_EN=0;}/*随机数发生函数*/void randmaker(){uint ran;ran=rand();dis1[0]=ran/10000+0x30;dis1[1]=ran%10000/1000+0x30;dis1[2]=ran%1000/100+0x30;dis1[3]=ran%100/10+0x30;dis1[4]=ran%10+0x30;ran=rand();dis1[5]=ran/10000+0x30;dis1[6]=ran%10000/1000+0x30;dis1[7]=ran%1000/100+0x30;dis1[8]=ran%100/10+0x30;dis1[9]=ran%10+0x30;}/*LCD初始化*/void lcd_init(){LCD_PSB=1;//并口方式write_cmd(0x30);//基本操作指令delay_ms(5);write_cmd(0x0c);//打开显示,光标关闭delay_ms(5);write_cmd(0x01);//清除LCD显示类容delay_ms(5);}/*主程序*/main(){uchar i;delay_ms(10);lcd_init();lcd_pos(1,0);i=0;while(dis2[i]!='\0'){write_dat(dis2[i]);i++;}lcd_pos(2,0);i=0;while(dis3[i]!='\0'){write_dat(dis3[i]);i++;}lcd_pos(3,0);i=0;while(dis4[i]!='\0'){write_dat(dis4[i]);i++;}while(1){lcd_pos(0,0);randmaker();for(i=0;i<10;i++){write_dat(dis1[i]);}}}。
12864液晶显示函数
lcd_display_shuzi(1,0,5,1);//LCD显示数字
lcd_display_hanzi(1,0,3,0);//LCD显示汉字
lcd_display_hanzi(2,0,0,1);//LCD显示汉字//LCD字符汉字
{//screen:选择屏幕参数,page:选择页参数0-3,col:选择列参数0-7,mun:显示第几个汉字的参数
int a;
mun=mun*16;
select_screen(screen);
w_com(0xb8+(page*2));
w_com(0x40+(col*8));
for (a=0;a<8;a++)
{
w_date(hanzi[mun++]);
}
w_com(0xb8+(page*2)+1);
w_com(0x40+(col*16));
for (a=0;a<16;a++)
{
w_date(hanzi[mun++]);
}
}
/*
LCD显示字符字库函数
*/
void lcd_display_zifuk(uchar screen,uchar page,uchar col,uchar mun)
} */
}
{
select_screen(0);
w_com(0xc0+x);
delayms(500);
}
}
/*
LCD清屏函数:清屏从第一页的第一列开始,总共8页,64列
液晶显示器 12864 代码
write(0,0x0c); //显示打开,光标关,反白关
write(0,0x01); //清屏,将DDRAM的地址计数器归零
}*/
write(0,0x80); for(i=0;i<16;i++) write(1,datas11[i]);
write(0,0x90); for(i=0;i<16;i++) write(1,datas2[i]);
write(0,0x88); for(i=0;i<16;i++) write(1,datas3[i]);
delaynms(1); //延时是必须的
}
/*void lcdinit(void) //初始化LCD
{
delaynms(10); //启动等待,等LCM讲入工作状态
//PSB=0; ; //串口驱动模式
// RESET=0; delaynms(1); RESET=1; //复位LCD
// CS=1;
Hdata=ddata&0xf0; //取高四位
Ldata=(ddata<<4)&0xf0; //取低四位
sendbyte(start_data); //发送起始信号
delaynms(5); //延时是必须的
sendbyte(Hdata); //发送高四位
delaynms(1); //延时是必须的
sendbyte(Ldata); //发送低四位
bbyte<<tart, unsigned char ddata) //写指令或数据
{
unsigned char start_data,Hdata,Ldata;
LCD lgm12864 程序代码
LCD lgm12864 程序代码/**************************************LCD:lgm12864,LCD control IC:KS0108**************************************/#define uchar unsigned char#define uint unsigned int#define DataPort P0 //LCD:D0-D7sbit RS=P2^1; //Data or Instrument Selectsbit RW=P2^2; //Write or Readsbit E=P2^3; // Enable singlesbit CS1=P2^4; //Master chip enablesbit CS2=P2^5;sbit RST=P2^6; //Lcm reset/*数字数组*/unsigned char code suzidot[160] ={/*0 CHAR_30 */0x00,0xE0,0xF0,0x18,0x08,0x18,0xF0,0xE0,0x00,0x0F,0x1F,0x30,0x20,0x30,0x1F,0x0F, /*1 CHAR_31 */0x00,0x10,0x10,0xF8,0xF8,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x3F,0x20,0x20,0x00, /*2 CHAR_32 */0x00,0x70,0x78,0x08,0x08,0x88,0xF8,0x70,0x00,0x30,0x38,0x2C,0x26,0x23,0x31,0x30, /*3 CHAR_33 */0x00,0x30,0x38,0x88,0x88,0xC8,0x78,0x30,0x00,0x18,0x38,0x20,0x20,0x31,0x1F,0x0E, /*4 CHAR_34 */0x00,0x00,0xC0,0xE0,0x30,0xF8,0xF8,0x00,0x00,0x07,0x07,0x24,0x24,0x3F,0x3F,0x24, /*5 CHAR_35 */0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x19,0x39,0x21,0x20,0x31,0x1F,0x0E, /*6 CHAR_36 */0x00,0xE0,0xF0,0x98,0x88,0x98,0x18,0x00,0x00,0x0F,0x1F,0x31,0x20,0x31,0x1F,0x0E, /*7 CHAR_37 */0x00,0x38,0x38,0x08,0xC8,0xF8,0x38,0x08,0x00,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00, /*8 CHAR_38 */0x00,0x70,0xF8,0x88,0x08,0x88,0xF8,0x70,0x00,0x1C,0x3E,0x23,0x21,0x23,0x3E,0x1C, /*9 CHAR_39 */0x00,0xE0,0xF0,0x18,0x08,0x18,0xF0,0xE0,0x00,0x00,0x31,0x33,0x22,0x33,0x1F,0x0F };/*盐CD1CE */0x80,0x88,0x88,0x88,0xFF,0x48,0x48,0x48,0x00,0xFF,0x00,0x08,0x30,0x60,0x00,0x00, 0x40,0x41,0x40,0x7E,0x42,0x42,0x7E,0x42,0x42,0x7E,0x42,0x42,0x7E,0x40,0x40,0x00,/*城CB3C7 */0x10,0x10,0xFF,0x10,0x10,0xF8,0x48,0x48,0xC8,0x08,0xFF,0x08,0x0A,0xEC,0x48,0x00, 0x04,0x0C,0x07,0x42,0x32,0x0F,0x08,0x58,0x4F,0x20,0x13,0x0C,0x33,0x40,0x38,0x00,/*工CB9A4 */0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,/*学CD1A7 */0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00,/*院CD4BA */0xFE,0x02,0x32,0x4A,0x86,0x0C,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x0C,0x04,0x00, 0xFF,0x00,0x02,0x04,0x83,0x41,0x31,0x0F,0x01,0x01,0x7F,0x81,0x81,0x81,0xF1,0x00,};unsigned char code hzdottime[] ={/*年CC4EA */0x00,0x20,0x10,0xCC,0x47,0x44,0x44,0xFC,0x44,0x44,0x44,0x64,0x46,0x04,0x00,0x00, 0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,/*月CD4C2 */0x00,0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0xFF,0x02,0x00,0x00,0x00, 0x00,0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,0x00, /*日CC8D5 */0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFF,0x02,0x00,0x00,0x00, 0x00,0x00,0x00,0x7F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,0x00,0x00, /*时CCAB1 */0x00,0xFC,0x84,0x84,0x84,0xFE,0x14,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x23,0x40,0x80,0x7F,0x00,0x00,0x00,/*分CB7D6 */0x00,0x80,0x40,0x20,0x98,0x86,0x80,0x80,0x83,0x8C,0x90,0x20,0xC0,0x80,0x80,0x00, 0x01,0x00,0x80,0x40,0x20,0x1F,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x01,0x00,0x00,/*秒CC3EB */0x20,0x24,0x24,0xA4,0xFE,0xA3,0x22,0x80,0x70,0x00,0xFF,0x00,0x10,0x20,0x60,0x00, 0x10,0x08,0x06,0x01,0xFF,0x00,0x81,0x80,0x40,0x20,0x17,0x08,0x04,0x03,0x00,0x00,/*周CD6DC */0x40,0x20,0x1F,0x00,0x00,0x7E,0x22,0x22,0x22,0x3F,0x42,0x80,0x7F,0x00,0x00,0x00,/*一CD2BB */0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*二CB6FE */0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0C,0x08,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00,/*三CC8FD */0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0xC4,0x86,0x04,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x30,0x20,0x00,/*四CCBC4 */0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFE,0x04,0x00,0x00,0x7F,0x20,0x28,0x24,0x23,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00,/*五CCEE5 */0x00,0x04,0x84,0x84,0x84,0x84,0xFC,0x84,0x84,0x84,0x84,0xC4,0x86,0x84,0x00,0x00,0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x60,0x40,0x00,/*六CC1F9 */0x20,0x20,0x20,0x20,0x20,0x22,0x2C,0x38,0x20,0x20,0x20,0x20,0x20,0x30,0x20,0x00,0x00,0x40,0x20,0x18,0x06,0x03,0x00,0x00,0x00,0x01,0x02,0x0C,0x38,0x70,0x00,0x00,/*星CD0C7 */0x00,0x00,0xBE,0x2A,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0xBF,0x02,0x00,0x00, 0x48,0x44,0x4B,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x4D,0x49,0x61,0x40,0x00,/*期CC6DA */0x00,0x08,0xFF,0xA8,0xA8,0xA8,0xFF,0x08,0x00,0xFE,0x22,0x22,0x22,0xFF,0x02,0x00, 0x84,0x44,0x37,0x04,0x04,0x14,0xA7,0x44,0x24,0x1F,0x02,0x42,0x82,0x7F,0x00,0x00};void Delay(void){ _nop_();_nop_();_nop_();_nop_();_nop_();}/*写一个字节数据或命令*/void out_byte(uchar byte,bit RW0,bit RS0){Delay();Delay();Delay();//Delay();RW=RW0;RS=RS0;Delay();DataPort=byte;Delay();E=1; Delay(); //LCD使能E=0;Delay();}void SetLine(uchar line){ line=line & 0x07; // 0<=line<=7line=line|0xb8; //1011 1xxxout_byte(line,0,0);//写行地址命令}//设定列地址--Y 0-63void SetColumn(uchar column){column=column &0x3f; // 0=<column<=63 column=column | 0x40; //01xx xxxxout_byte(column,0,0); //写列地址命令}//设定显示开始行--XXvoid SetStartLine(uchar startline) //0--63 {startline=startline & 0x3f;startline=startline|0xc0; //1100 0000out_byte(startline,0,0);}//选择屏幕//screen: 0-全屏,1-左屏,2-右屏void SelectScreen(uchar screen){switch(screen){case 0: CS1=1;Delay(); //全屏CS2=1;Delay();break;case 1: CS1=1;Delay(); //左屏CS2=0;Delay();break;case 2: CS1=0;Delay(); //右屏CS2=1;Delay();break;}}//清屏//screen: 0-全屏,1-左屏,2-右屏void ClearScreen(uchar screen){uchar i,j;SelectScreen(screen);{ SetLine(i);for(j=0;j<64;j++){out_byte(0x00,0,1); //写数据0x00清屏}}}void ClearScreen123(void){uchar i;ClearScreen(1);for(i=0;i<20;i++); //清屏ClearScreen(2);for(i=0;i<20;i++);}//显示8*8点阵//旋转90度:字模被竖着切分//lin:行(0-7), column: 列(0-7)//address : 字模区首地址void Show88(uchar lin,uchar column,uchar *str){uchar i;SetLine(lin);SetColumn(column<<3); //每隔八点为一列,共0-7列for(i=0;i<8;i++) out_byte(*(str+i) ,0,1);}//显示8*16字符//screen:屏幕选择//lin:行(0-3), column: 列(0-7)void ShowChar(uchar screen,uchar lin,uchar column,uchar *ch) { lin=lin<<1;SelectScreen(screen);Show88(lin ,column,ch);Show88(lin+1,column,ch+8);}//显示一个汉字//screen:屏幕选择//lin:行(0-3), column: 列(0-7)//hzcode: 汉字代码(自定义的)void ShowHZ(uchar screen,uchar lin,uchar column,uchar hzcode[]) { lin=lin<<1; //lin*2SelectScreen(screen);Show88(lin,column,hzcode);Show88(lin,column+1,hzcode+8);Show88(lin+1,column+1,hzcode+24);}//连续显示汉字-lin:行(0-3), column: 列(0-7)//N:一行连续显示汉字个数void ShowHZL(uchar screen,uchar lin,uchar column,uchar N,uchar hz[]) {uchar i;uchar idata n0,n1,n2,col;col=column<<3;n0=(64-col)/16; //一屏可显示汉字个数(<=4)if(N<=n0){for(i=0;i<N;i++){ShowHZ(screen,lin,column,hz+i*32);//hz+i*32表示连续的汉字column=column+2;}}else if(N>n0) //超出一屏可显示汉字个数(<=4){for(i=0;i<n0;i++) //当前屏显示n0个字{ShowHZ(screen,lin,column,hz+i*32);column=column+2;}n1=N-n0; //剩余字数if(++screen>2) return; //在下一屏显示剩余字数,如屏幕超出则返回col=0; //在下一屏0列开始显示剩余字数if(n1<=4){for(i=0;i<n1;i++){ShowHZ(screen,lin,col,(hz+n0*32)+i*32);col=col+2;}}else if(n1>4) //超出一屏可显示汉字个数(<=4){for(i=0;i<4;i++){ShowHZ(screen,lin,col,(hz+n0*32)+i*32);col=col+2;}n2=n1-4; //剩余字数if(++screen>2) return;col=0;for(i=0;i<n2;i++){ShowHZ(screen,lin,col,(hz+n0*32+128)+i*32);col=col+2;}}//连续显示数字或字母//N:一行连续显示字符个数void ShowCharL(uchar screen,uchar lin,uchar column,uchar N,uchar ch[]) {uchar i;uchar idata n0,n1,n2,col;col=column<<3;n0=(64-col)/8; //一屏可显示字符个数(<=8)if(N<=n0){for(i=0;i<N;i++){ShowChar(screen,lin,column,ch+i*16);column=column+1;}}else if(N>n0){for(i=0;i<n0;i++){ShowChar(screen,lin,column,ch+i*16);column=column+1;}n1=N-n0; //剩余字数if(++screen>2) return;col=0;if(n1<=8){for(i=0;i<n1;i++){ShowChar(screen,lin,col,(ch+n0*16)+i*16);col=col+1;}}else if(n1>8){for(i=0;i<8;i++){ShowChar(screen,lin,col,(ch+n0*16)+i*16);col=col+1;}n2=n1-8; //剩余字数if(++screen>2) return;col=0;for(i=0;i<n2;i++){ShowChar(screen,lin,col,(ch+n0*16+128)+i*16);col=col+1;}}//读显示数据uchar ReadByte(){uchar dat;//CheckState();RS=1; RW=1;DataPort=0xff;E=1;dat=DataPort;Delay();//for(i=0;i<10;i++);E=0;return(dat);}//反显一个8*8字块//lin:行(0-3), column: 列(0-7)void ReverseShow88(uchar lin,uchar column){uchar i;uchar tab[8];SetLine(lin);//读上部8列,每个方块8*8大小SetColumn(column<<3);tab[0]=ReadByte(); //空读!!!!! //?for(i=0;i<8;i++) tab[i]=~ReadByte();//写回SetLine(lin);SetColumn(column<<3);for(i=0;i<8;i++) out_byte(tab[i] ,0,1);}//反显一个字符8*16//lin:行(0-3), column: 列(0-7)void ReverseShowChar(uchar screen,uchar lin,uchar column) {lin=lin<<1;SelectScreen(screen);ReverseShow88(lin ,column);ReverseShow88(lin+1,column);}//lin:行(0-3), column: 列(0-7)void ReverseShowHZ(uchar screen,uchar lin,uchar column){lin=lin<<1;SelectScreen(screen);ReverseShow88(lin ,column );ReverseShow88(lin ,column+1);ReverseShow88(lin+1,column );ReverseShow88(lin+1,column+1);}//连续反白显示汉字//N:一行连续显示汉字个数void ReverseShowHZL(uchar screen,uchar lin,uchar column,uchar N) {uchar i;uchar idata n0,n1,n2,col;col=column<<3;n0=(64-col)/16; //一屏可显示汉字个数(<=4)if(N<=n0){for(i=0;i<N;i++){ReverseShowHZ( screen, lin, column);column=column+2;}}else if(N>n0){for(i=0;i<n0;i++){ReverseShowHZ( screen, lin, column);column=column+2;}n1=N-n0; //剩余字数if(++screen>2) return;col=0;if(n1<=4){for(i=0;i<n1;i++){ReverseShowHZ( screen, lin, col);col=col+2;}}else if(n1>4){for(i=0;i<4;i++){ReverseShowHZ( screen, lin, col);}n2=n1-4; //剩余字数if(++screen>2) return;col=0;for(i=0;i<n2;i++){ReverseShowHZ( screen, lin, col);col=col+2;}}}}void ShowSz(uchar screen0,uchar lin,uchar column,uchar szcode) {switch(szcode){case 0: ShowChar(screen0, lin, column,suzidot); break;case 1: ShowChar(screen0, lin, column,suzidot+16); break;case 2: ShowChar(screen0, lin, column,suzidot+32); break;case 3: ShowChar(screen0, lin, column,suzidot+48); break;case 4: ShowChar(screen0, lin, column,suzidot+64); break;case 5: ShowChar(screen0, lin, column,suzidot+80); break;case 6: ShowChar(screen0, lin, column,suzidot+96); break;case 7: ShowChar(screen0, lin, column,suzidot+112);break;case 8: ShowChar(screen0, lin, column,suzidot+128);break;case 9: ShowChar(screen0, lin, column,suzidot+144);break;default:ShowChar(screen0, lin, column,suzidot+128);//ReverseShowChar(screen0,lin,column); //反白显示'8' }}void iniLCD(void){uint i;for(i=0;i<10000;i++);RST=0;for(i=0;i<1000;i++);RST=1;SelectScreen(0);out_byte(0x3e,0,0); //关显示for(i=0;i<=100;i++);ClearScreen(0); for(i=0;i<=100;i++);//清屏SelectScreen(0);for(i=0;i<=100;i++);out_byte(0x3f,0,0); for(i=0;i<=100;i++);//开显示SelectScreen(0);for(i=0;i<=100;i++);SetStartLine(0); //开始行:0LCD lgm12864}- 11 -。
JDH529(12864液晶屏)指令集说明(绝对全绝对易懂)
JDH529(12864液晶屏)指令集说明(绝对全绝对易懂)JDH529(12864)指令集说明李进整理VER.2009-07-28基本指令集说明☆清除显示RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 代0 0 0 0 0 0 0 0 0 1 码功能:将DDRAM 填满"20H"(space code),并且设定DDRAM 的地址计数器(AC)到"00H",重设进入点设定将I/D 设为"1",游标右移AC 加 1指令:RS=1;RW=1;DB=01H // 清除显示☆地址归位RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0代0 0 0 0 0 0 0 0 1 X 码功能:设定DDRAM 的地址计数器(AC)到"00H",并且将光标移到开头原点位置;这个指令并不改变DDRAM 的内容指令:RS=0;RW=0;DB=3H // 地址归位☆进入点设定RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 代0 0 0 0 0 0 0 1 I/D S 码功能:指定在数据的读取与写入时,设定光标的移动方向及指定显示的移位I/D :地址计数器递增递减选择当I/D = "1", 光标右移,DDRAM 地址计数器(AC)加1当I/D = "0", 光标左移,DDRAM 地址计数器(AC)减1S: 显示画面整体位移S I/D 功能1 1 画面整体左移1 0 画面整体右移指令:RS = 0;RW = 0;DB = 06H; // 光标右移,画面不移动,AC加1RS = 0;RW = 0;DB = 05H; // 画面整体右移。
RS = 0;RW = 0;DB = 07H // 画面整体左移。
☆显示状态开关RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 代0 0 0 0 0 0 1 D C B 码功能:控制整体显示,光标,光标位置反白ON/OFFD : 整体显示ON/OFF 控制位当 D = "1",整体显示ON当 D = "0",整体显示OFF ,但不改变DDRAM 的内容C : 光标ON/OFF 控制位当 C = "1",光标显示ON.当 C = "0",光标显示OFF.B : 光标位置反白ON/OFF 控制位当 B = "1",光标位置显示反白ON,将光标所在之地址㆖的数据反白显示.当 B = "0", .光标位置显示反白OFF指令:RS=0;RW=0;DB=0CH // 开显示,无光标,光标不闪烁RS=0;RW=0;DB=0EH // 开显示,有光标,光标不闪烁RS=0;RW=0;DB=0FH // 开显示,有光标,光标闪烁☆光标或显示移位控制RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 代码0 0 0 0 0 1 S/C R/L X X功能:设定光标的移动与显示的移位控制位;这个指令并不改变DDRAM 的内容S/C R/L 功能AC 值0 0 光标向左移动AC=AC-1 0 1 光标向右移动AC=AC+11 0 显示(display)向左移动,且光标跟着移动AC=AC1 1 显示(display)向右移动,且光标跟着移动AC=AC指令:RS = 0;RW = 0;DB=10; // 光标向左移动RS = 0;RW = 0;DB=14; // 光标向右移动☆功能设定RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 代0 0 0 0 1 DL X RE X X码DL : 4/8 BIT 界面控制位当DL = "1", 为8 BIT MPU 控制界面当DL = "0", 为4 BIT MPU 控制界面RE : 指令集选择控制位当RE = "1", 为扩充指令集动作当RE = "0", 为基本指令集动作同一指令之动作不可同时改变RE 及DL 需先改变DL 后在改变RE 才可确保FLAG 正确设定指令:注意:需分别设置DL和RERS=0;RW=0;DB=30H // 设定8位控制界面RS=0;RW=0;DB=00H // 设定基本指令集RS=0;RW=0;DB=34H // 设定扩展指令集☆设定CGRAM 地址RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 代0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0 码功能:设定CGRAM 地址到地址计数器(AC)AC 范围为00H~3FH需确认扩充指令中SR=0 (卷动地址或RAM 地址选择)☆设定DDRAM 地址RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 代0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 码功能:设定DDRAM 地址到地址计数器(AC).第一行AC 范围为80H~87H第二行AC 范围为90H~97H第三行AC 范围为88H~8FH第四行AC 范围为98H~9FH指令:汉字的起始地址必须是X0H和偶数字符显示时,每一行最多显示16个ASCII字符或8个汉字。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include<reg52.h>
#include<intrins.h>
#include<stdlib.h>
#define uchar unsigned char
#define uint unsigned int
/*端口定义*/
#define LCD_data P0
sbit LCD_RS=P3^5;
sbit LCD_RW=P3^6;
sbit LCD_EN=P3^4;
sbit LCD_PSB=P3^7;
uchar dis1[10];
uchar code dis2[]={"XXXXXXXXXXX@"};
uchar code dis3[]={"XXXXXXXX"};
uchar code dis4[]={"-------"};
void delay_ms(uint x)
{
int i,j;
for(j = 0; j < x; j++)
{
for(i = 0; i < 110; i++)
{
;
}
}
}
/*写指令数据到LCD
RS=L——表示DB0-DB7为显示指令数据
RW=L——表示DB0-DB7数据被write(当E=“H-L”,指令数据被写到IR或DR) E=高脉冲
此时DB0-DB7=指令码*/
void write_cmd(uchar cmd)
{
LCD_RS=0;
LCD_RW=0;
LCD_EN=0;
P0=cmd;
delay_ms(5);
delay_ms(5);
LCD_EN=0;
}
/*设定显示位置*/
void lcd_pos(uchar X, uchar Y)
{
uchar pos;
if(X == 0)
{
X = 0x80;
}
else if(X == 1)
{
X = 0x90;
}
else if(X == 2)
{
X = 0x88;
}
else if(X == 3)
{
X = 0x98;
}
pos = X + Y;
write_cmd(pos); //显示地址
}
/*写显示数据到LCD*/
/*
RS=H ——表示DB0-DB7为显示数据
RW=L ——RW=L,E='H-L',DB0-DB7数据被写到IR或DR E=高脉冲
DB0-DB7=显示数据
*/
void write_dat(uchar dat)
{
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
P0=dat;
delay_ms(5);
delay_ms(5);
LCD_EN=0;
}
/*随机数发生函数*/
void randmaker()
{
uint ran;
ran=rand();
dis1[0]=ran/10000+0x30;
dis1[1]=ran%10000/1000+0x30;
dis1[2]=ran%1000/100+0x30;
dis1[3]=ran%100/10+0x30;
dis1[4]=ran%10+0x30;
ran=rand();
dis1[5]=ran/10000+0x30;
dis1[6]=ran%10000/1000+0x30;
dis1[7]=ran%1000/100+0x30;
dis1[8]=ran%100/10+0x30;
dis1[9]=ran%10+0x30;
}
/*LCD初始化*/
void lcd_init()
{
LCD_PSB=1;//并口方式
write_cmd(0x30);//基本操作指令
delay_ms(5);
write_cmd(0x0c);//打开显示,光标关闭
delay_ms(5);
write_cmd(0x01);//清除LCD显示类容
delay_ms(5);
}
/*主程序*/
main()
{
uchar i;
delay_ms(10);
lcd_init();
lcd_pos(1,0);
i=0;
while(dis2[i]!='\0')
{
write_dat(dis2[i]);
i++;
}
lcd_pos(2,0);
i=0;
while(dis3[i]!='\0')
{
write_dat(dis3[i]);
i++;
}
lcd_pos(3,0);
i=0;
while(dis4[i]!='\0')
{
write_dat(dis4[i]);
i++;
}
while(1)
{
lcd_pos(0,0);
randmaker();
for(i=0;i<10;i++)
{
write_dat(dis1[i]);
}
}
}。