资源描述
第二讲点阵、液晶显示模块的应用设计,点阵式汉字显示原理8*8点阵应用设计16*16点阵应用设计24*24点阵应用设计液晶显示模块1602的显示原理及应用液晶显示器12864的显示原理及应用,8*8点阵外型和结构,项目1:8*8点阵应用设计,与单片机连接图,一、题目要求:用8051控制8*8点阵,使其先从左到右动态点亮3次,后从右到左动态点亮3次,;再从上到下点亮3次,最后从下到上点亮3次,如此动态循环。,原理说明,8X8点阵LED工作原理说明:8X8点阵共由64个发光二极管组成,且每个发光二极管是放置在行线和列线的交叉点上,当对应的某一列置1电平,某一行置0电平,则相应的二极管就会点亮;因此要实现一根柱形的亮法,对应的一列为一根竖柱,或者对应的一行为一根横柱,实现柱的亮的方法如下:一根竖柱:对应的列置1,而行则采用扫描的方法来实现。一根横柱:对应的行置0,而列则采用扫描的方法来实现。,/*程序分析*/#includeunsignedcharcodetaba=0 xfe,0 xfd,0 xfb,0 xf7,0 xef,0 xdf,0 xbf,0 x7f;unsignedcharcodetabb=0 x01,0 x02,0 x04,0 x08,0 x10,0 x20,0 x40,0 x80;voiddelay(void)unsignedchari,j;for(i=10;i0;i-)for(j=248;j0;j-);,voiddelay1(void)unsignedchari,j,k;for(k=10;k0;k-)for(i=20;i0;i-)for(j=248;j0;j-);voidmain(void)unsignedchari,j;while(1),for(j=0;j3;j+)/fromlefttoright3timefor(i=0;i8;i+)P3=tabai;P1=0 xff;/列柱,列置1,行扫描delay1();,for(j=0;j3;j+)/fromrighttoleft3timefor(i=0;i8;i+)P3=taba7-i;P1=0 xff;delay1();for(j=0;j3;j+)/fromtoptobottom3timefor(i=0;i8;i+)P3=0 x00;P1=tabb7-i;/行柱,行清0,列扫描delay1();,for(j=0;j3;j+)/frombottomtotop3timefor(i=0;i8;i+)P3=0 x00;P1=tabbi;delay1();,一、题目要求:8X8LED点阵屏循环显示数字09,刷新过程由定时器中断完成。,/*程序分析*/#include#include#defineucharunsignedchar#defineuintunsignedintucharcodeTable_of_Digits=0 x00,0 x3e,0 x41,0 x41,0 x41,0 x3e,0 x00,0 x00,/00 x00,0 x00,0 x00,0 x21,0 x7f,0 x01,0 x00,0 x00,/10 x00,0 x27,0 x45,0 x45,0 x45,0 x39,0 x00,0 x00,/20 x00,0 x22,0 x49,0 x49,0 x49,0 x36,0 x00,0 x00,/30 x00,0 x0c,0 x14,0 x24,0 x7f,0 x04,0 x00,0 x00,/4,0 x00,0 x72,0 x51,0 x51,0 x51,0 x4e,0 x00,0 x00,/50 x00,0 x3e,0 x49,0 x49,0 x49,0 x26,0 x00,0 x00,/60 x00,0 x40,0 x40,0 x40,0 x4f,0 x70,0 x00,0 x00,/70 x00,0 x36,0 x49,0 x49,0 x49,0 x36,0 x00,0 x00,/80 x00,0 x32,0 x49,0 x49,0 x49,0 x3e,0 x00,0 x00/9;uchari=0,t=0,Num_Index;,/主程序voidmain()P3=0 x80;Num_Index=0;/从0开始显示TMOD=0 x00;/T0方式0TH0=(8192-2000)/32;/2ms定时,8192=213TL0=(8192-2000)%32;IE=0 x82;TR0=1;/启动T0while(1);,/T0中断函数voidLED_Screen_Display()interrupt1/1是T0中断服务程序代码TH0=(8192-2000)/32;/恢复初值TL0=(8192-2000)%32;P0=0 xff;/输出位码和段码P0=Table_of_DigitsNum_Index*8+i;/段码P3=P30;y-);voidlcd_wcom(ucharcom)/1602写命令函数rs=0;/选择指令寄存器rw=0;/选择写P0=com;/把命令字送入P0delay(5);/延时一小会儿,让1602准备接收数据en=1;/使能线电平变化,命令送入1602的8位数据en=0;,voidlcd_wdat(uchardat)/1602写数据函数rs=1;/选择数据寄存器rw=0;/选择写P0=dat;/把要显示的数据送入P0delay(5);/延时一小会儿,让1602准备接收数据en=1;/使能线电平变化,数据送入1602的8位数据口en=0;voidlcd_init()/1602初始化函数lcd_wcom(0 x38);/8位数据,双列,5*7字形lcd_wcom(0 x0c);/开启显示屏,关光标,光标不闪烁lcd_wcom(0 x06);/显示地址递增,即写一个数据后,显示位置右移一位lcd_wcom(0 x01);/清屏,voidmain()/主函数ucharn,m=0;lcd_init();/液晶初始化lcd_wcom(0 x80);/显示地址设为80H(即00H,)上排第一位for(m=0;m16;m+)/将table中的数据依次写入1602lcd_wdat(tablem);delay(200);lcd_wcom(0 x80+0 x44);/重新设定显示地址为0 xc4,即下排第5位for(n=0;n8;n+)/将table1中的数据依次写入1602显示lcd_wdat(table1n);delay(200);while(1);/动态停机,思考,查看1602的相关资料,试编程实现LCD显示心型图案。,LCD12864,功能介绍:12864是一种图形点阵液晶显示器,它主要由行驱动器/列驱动器及128*64全点阵液晶显示器组成。可完成图形显示,也可以显示8*4汉字,12864管脚,管脚说明:,项目三液晶显示器12864,一、题目要求:左右滚屏显示汉字(该12864不带字库),#include#include#defineucharunsignedchar#defineuintunsignedint#defineLCD_databusP0ucharnum;,程序分析,ucharcodezi1032=/*临*/0 x00,0 xF8,0 xF0,0 x00,0 xFF,0 xFE,0 x80,0 x60,0 x38,0 x1E,0 x3F,0 x6A,0 x68,0 xC8,0 x4C,0 x08,0 x00,0 x0F,0 x07,0 x00,0 xFF,0 x7F,0 x00,0 xFF,0 x7E,0 x42,0 x7E,0 x7E,0 x42,0 xFE,0 x7F,0 x02,/*沂*/0 x00,0 x10,0 xE1,0 xC6,0 x0C,0 x8C,0 xE0,0 xFE,0 xFC,0 x24,0 x26,0 xE2,0 xE3,0 x23,0 x32,0 x20,0 x00,0 x04,0 x78,0 xF8,0 x1E,0 x83,0 x40,0 x3F,0 x1F,0 x00,0 x00,0 xFF,0 x7F,0 x00,0 x00,0 x00,.略(要显示什么汉字,自己在字模提取软件中生成),sbitRS=P22;sbitRW=P21;sbitEN=P20;sbitCS1=P24;sbitCS2=P23;/对应的端口根据硬件电路图来确定voiddelay(uintx)uchari;while(x-)for(i=0;i120;i+);voidRead_busy()P0=0X00;RS=0;RW=1;EN=1;while(P0,voidwrite_LCD_command(ucharvalue)Read_busy();RS=0;RW=0;LCD_databus=value;EN=1;_nop_();_nop_();EN=0;voidwrite_LCD_data(ucharvalue)Read_busy();RS=1;RW=0;LCD_databus=value;EN=1;_nop_();_nop_();EN=0;,voidSet_page(ucharpage)page=0 xb8|page;write_LCD_command(page);voidSet_line(ucharstartline)startline=0 xc0|startline;write_LCD_command(startline);voidSet_colum(ucharcolum)colum=colum,voidSetonoff(ucharonoff)onoff=0 x3e|onoff;write_LCD_command(onoff);voidSelectScreen(ucharscreen)switch(screen)case0:CS1=0;CS2=0;break;case1:CS1=0;CS2=1;break;case2:CS1=1;CS2=0;break;default:break;,voidClearScreen(ucharscreen)uchari,j;SelectScreen(screen);for(i=0;i8;i+)Set_page(i);Set_colum(0);for(j=0;j64;j+)write_LCD_data(0 x00);,voidInitLCD()Read_busy();SelectScreen(0);Setonoff(0);SelectScreen(0);Setonoff(1);SelectScreen(0);ClearScreen(0);Set_line(0);,voidDisplay(ucharss,ucharpage,ucharcolum,uchar*p)uchari;SelectScreen(ss);Set_page(page);Set_colum(colum);for(i=0;i=10|d=10|e=10|f=10|g=10)a=a%10;b=b%10;c=c%10;d=d%10;e=e%10;f=f%10;g=g%10;Display(1,2,0*16,zii);Display(1,2,1*16,zia);Display(1,2,2*16,zib);Display(1,2,3*16,zic);Display(2,2,0*16,zid);Display(2,2,1*16,zie);Display(2,2,2*16,zif);Display(2,2,3*16,zig);delay(500);ClearScreen(0);,
展开阅读全文