欢迎来到天天文库
浏览记录
ID:14392614
大小:43.00 KB
页数:14页
时间:2018-07-28
《lcd12864全部子函数》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、LCD12864全部子函数#includevoiddelayu(){_nop_();}//延时a*1msvoiddelaym(uinta){uinti,j;for(i=a;i>0;i--)for(j=110;j>0;j--);}//检测LCD是否处于忙状态,若忙返回1,空闲返回0bitcheckBusy(){bitbusy;RS=0;RW=1;E=1;delayu();busy=(bit)(LCD_DATA&0x80);E=0;returnbusy;}//等待LCD到空闲voidwait(){while(checkBusy());}//写命令voidwri
2、te_com(ucharcmd){wait();RS=0;RW=0;E=0;LCD_DATA=cmd;delayu();E=1;E=0;}//写数据voidwrite_data(uchardat){wait();RS=1;RW=0;E=0;LCD_DATA=dat;delayu();E=1;E=0;}//读数据ucharread_data(void){uchardsp_data;wait();LCD_DATA=0xFF;RS=1;RW=1;E=0;E=1;delayu();dsp_data=LCD_DATA;E=0;return(dsp_data);}//初始化LCDvoidinit(
3、){write_com(0x30);//基本指令,扩充指令为34Hwrite_com(0x0c);//显示开,关光标write_com(0x01);//清屏delaym(10);}voidsetPosition(ucharx,uchary){ucharp;switch(y%4){case0:p=0x80;break;//第一行开始地址case1:p=0x90;break;//第二行case2:p=0x88;break;//第三行case3:p=0x98;break;//第四行}p+=x;write_com(p);}voidwritestring(uchar*str){uchari=0;
4、while(str[i]!=' '){write_data(str[i++]);}}voidlcd_DisplayImage(unsignedchar*str){unsignedchari;unsignedcharj;unsignedchark;unsignedcharbGDRAMAddrX=0x80;//GDRAM水平地址unsignedcharbGDRAMAddrY=0x80;//GDRAM垂直地址for(i=0;i<2;i++)//在绘图GDRAM中写满屏图片数据{for(j=0;j<32;j++){for(k=0;k<8;k++){write_com(0x34);write_
5、com(bGDRAMAddrY+j);//垂直地址write_com(bGDRAMAddrX+k);//水平地址write_com(0x30);write_data(*str++);write_data(*str++);}}bGDRAMAddrX=0x88;}write_com(0x36);write_com(0x30);}//任意坐标写汉字voidwrite_sfm(ucharx,uchary,uchardate){ucharshi,ge;shi=date/10;ge=date%10;switch(y){case0:{write_com(0x80+x);write_data(0x30
6、+shi);write_data(0x30+ge);}break;case1:{write_com(0x90+x);write_data(0x30+shi);write_data(0x30+ge);}break;case2:{write_com(0x88+x);write_data(0x30+shi);write_data(0x30+ge);}break;case3:{write_com(0x98+x);write_data(0x30+shi);write_data(0x30+ge);}break;}}//*************点显示子程序*********************
7、***//***0<=x<=127表示横坐标,0<=y<=63表示纵坐标colour=0表示删除点colour=1表示现实点voidlcd_DisplayDot(ucharx,uchary,ucharcolour){uchari,j,l,h,h1,l1;uintk=0x01;unsignedcharbGDRAMAddrX=0x80;//GDRAM水平地址unsignedcharbGDRAMAddrY=0x80;if(y>31){y-=32;bG
此文档下载收益归作者所有