您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > 12864液晶显示函数
#includereg51.h#includezifuku.h#defineucharunsignedchar#defineuintunsignedintsbitCS1=P2^3;//LCD右屏幕sbitCS2=P2^4;//LCD左屏幕sbitRS=P2^0;//LCD数据、指令寄存器sbitRW=P2^1;//LCD读、写操作sbitE=P2^2;//LCD使能信号,下降沿有效/*自定义延时子函数*/voiddelayms(ucharz){intx,y;for(x=z;x0;x--)for(y=110;y0;y--);}/*判断LCD忙信号状态*/voidbuys(){intdat;RW=1;RS=0;do{P0=0x00;E=1;dat=P0;E=0;dat=0x80&dat;}while(!(dat==0x00));}/*LCD写指令函数*/voidw_com(ucharcom){buys();RW=0;RS=0;E=1;P0=com;E=0;}/*LCD写数据函数*/voidw_date(uchardate){buys();RW=0;RS=1;E=1;P0=date;E=0;}/*LCD选屏函数*/voidselect_screen(ucharscreen){switch(screen){case0://选择全屏CS1=0;CS2=0;break;case1://选择左屏CS1=0;CS2=1;break;case2://选择右屏CS1=1;CS2=0;break;/*case3://选择右屏CS1=1;CS2=1;break;*/}}/*LCDx向上滚屏显示*/voidlcd_rol(){intx;for(x=0;x64;x++){select_screen(0);w_com(0xc0+x);delayms(500);}}/*LCD清屏函数:清屏从第一页的第一列开始,总共8页,64列*/voidclear_screen(screen){intx,y;select_screen(screen);//screen:0-选择全屏,1-选择左半屏,2-选择右半屏for(x=0xb8;x0xc0;x++)//从0xb8-0xbf,共8页{w_com(x);w_com(0x40);//列的初始地址是0x40for(y=0;y64;y++){w_date(0x00);}}}/*LCD显示汉字字库函数*/voidlcd_display_hanzi(ucharscreen,ucharpage,ucharcol,uintmun){//screen:选择屏幕参数,page:选择页参数0-3,col:选择列参数0-3,mun:显示第几个汉字的参数inta;mun=mun*32;select_screen(screen);w_com(0xb8+(page*2));w_com(0x40+(col*16));for(a=0;a16;a++){w_date(hanzi[mun++]);}w_com(0xb8+(page*2)+1);w_com(0x40+(col*16));for(a=0;a16;a++){w_date(hanzi[mun++]);}}/*LCD显示字符字库函数*/voidlcd_display_zifuk(ucharscreen,ucharpage,ucharcol,ucharmun){//screen:选择屏幕参数,page:选择页参数0-3,col:选择列参数0-7,mun:显示第几个汉字的参数inta;mun=mun*16;select_screen(screen);w_com(0xb8+(page*2));w_com(0x40+(col*8));for(a=0;a8;a++){w_date(zifu[mun++]);}w_com(0xb8+(page*2)+1);w_com(0x40+(col*8));for(a=0;a8;a++){w_date(zifu[mun++]);}}/*LCD显示数字字库函数*/voidlcd_display_shuzi(ucharscreen,ucharpage,ucharcol,ucharmun){//screen:选择屏幕参数,page:选择页参数0-3,col:选择列参数0-7,mun:显示第几个汉字的参数inta;mun=mun*16;select_screen(screen);w_com(0xb8+(page*2));w_com(0x40+(col*8));for(a=0;a8;a++){w_date(shuzi[mun++]);}w_com(0xb8+(page*2)+1);w_com(0x40+(col*8));for(a=0;a8;a++){w_date(shuzi[mun++]);}}/*LCD初始化函数*/voidlcd_init(){w_com(0x3f);//LCD开显示w_com(0xc0);//LCD行初始地址,共64行w_com(0xb8);//LCD页初始地址,共8页w_com(0x40);//LCD列初始地址,共64列}/*LCD显示主函数*/voidmain(){//第一行intx;lcd_init();//LCD初始化clear_screen(0);//LCD清屏幕lcd_display_shuzi(1,0,4,5);//LCD显示数字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字符汉字lcd_display_hanzi(2,0,1,2);//LCD显示汉字//第二行lcd_display_zifuk(1,1,2,0);//LCD显示字符lcd_display_zifuk(1,1,3,0);//LCD显示字符lcd_display_zifuk(1,1,4,0);//LCD显示字符lcd_display_zifuk(1,1,5,4);//LCD显示字符lcd_display_shuzi(1,1,6,8);//LCD显示字符lcd_display_shuzi(1,1,7,9);//LCD显示字符lcd_display_shuzi(2,1,0,5);//LCD显示字符lcd_display_shuzi(2,1,1,1);//LCD显示字符lcd_display_zifuk(2,1,2,4);lcd_display_zifuk(2,1,3,1);lcd_display_zifuk(2,1,4,2);lcd_display_zifuk(2,1,5,3);//第三行for(x=0;x4;x++){lcd_display_hanzi(1,2,x,3+x);//LCD显示汉字}for(x=0;x4;x++){lcd_display_hanzi(2,2,x,7+x);//LCD显示汉字}//第四行for(x=0;x4;x++){lcd_display_zifuk(1,3,x,5+x);//LCD显示汉字}lcd_display_shuzi(1,3,4,7);lcd_display_shuzi(1,3,5,5);lcd_display_shuzi(1,3,6,5);lcd_display_zifuk(1,3,7,9);lcd_display_shuzi(2,3,0,8);lcd_display_shuzi(2,3,1,9);lcd_display_shuzi(2,3,2,9);lcd_display_shuzi(2,3,3,5);lcd_display_shuzi(2,3,4,6);lcd_display_shuzi(2,3,5,8);lcd_display_shuzi(2,3,6,9);lcd_display_shuzi(2,3,7,2);while(1);/*while(1){//LCD向上滚屏显示lcd_rol();}*/}
本文标题:12864液晶显示函数
链接地址:https://www.777doc.com/doc-3059665 .html