欢迎来到天天文库
浏览记录
ID:62276099
大小:15.54 KB
页数:7页
时间:2021-04-25
《lcd1602显示及测试程序.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、.....................最新资料整理推荐.....................本程序共分为三个文件:Main.cLcd1602.cLcd1602.h/************文件Main.c*************/#include#include#defineucharunsignedchar#defineuintunsignedintvoiddelay_ms(uintx){uinti,j;for(i=0;i2、main(){Lcd_init();Write_char(0,10,'a');Write_string(1,0,"bb");delay_ms(1000);Clear_line(0);Write_string(0,0,"clear0lineOK!");delay_ms(1000);7.....................最新资料整理推荐.....................Clear_line(1);Write_string(1,0,"clear1lineOK!");delay_ms(1000);Clear_all();Writ3、e_string(0,1,"ClearallOk!");while(1);}/********文件Lcd1602.c**************/#include#include#defineucharunsignedchar#defineuintunsignedint#defineNop_nop_()#defineLcd_dataP0/*数据口*/#definebusy0x80/*检测忙状态*/sbitrs=P2^4;sbitrw=P2^5;sbiten=P2^6;voiddelay(ucha4、rx){7.....................最新资料整理推荐.....................uchari,j;for(i=0;i5、整理推荐.....................rs=1;delay(5);rw=0;delay(5);Lcd_data=dat;delay(10);en=0;delay(5);en=1;delay(10);}/*初始化*/voidLcd_init(){Lcd_data=0x00;delay(15);Write_com(0x38);delay(5);Write_com(0x38);delay(5);Write_com(0x38);delay(5);7.....................最新资料整理推荐.............6、........Write_com(0x38);/*显示模式设置*/Write_com(0x08);/*显示关闭*/Write_com(0x01);/*显示清屏*/Write_com(0x06);/*显示光标移动设置*/Write_com(0x0c);/*显示开及光标设置*/}voidWrite_char(ucharx,uchary,uchardat){x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/if(x)y7、=0x40;/*如果y大于1,则在第二行显示*/y8、=0x80;Write_com(y);W9、rite_data(dat);}voidWrite_string(ucharx,uchary,uchar*str){ucharlength=0;x&=0x1;/*限制x不能大于1*/7.....................最新资料整理推荐.....................y&=0xf;/*限制y不能大于15*/while(*str!=' '){Write_char(x,y,*str);y++;str++;}}voidClear_line(ucharline){Write_string(line,0,"");switch(10、line){case0:Write_com(0x80);case1:Write_com(0x80+0x40);default:break;}}voidClear_all(){7.....................最
2、main(){Lcd_init();Write_char(0,10,'a');Write_string(1,0,"bb");delay_ms(1000);Clear_line(0);Write_string(0,0,"clear0lineOK!");delay_ms(1000);7.....................最新资料整理推荐.....................Clear_line(1);Write_string(1,0,"clear1lineOK!");delay_ms(1000);Clear_all();Writ
3、e_string(0,1,"ClearallOk!");while(1);}/********文件Lcd1602.c**************/#include#include#defineucharunsignedchar#defineuintunsignedint#defineNop_nop_()#defineLcd_dataP0/*数据口*/#definebusy0x80/*检测忙状态*/sbitrs=P2^4;sbitrw=P2^5;sbiten=P2^6;voiddelay(ucha
4、rx){7.....................最新资料整理推荐.....................uchari,j;for(i=0;i5、整理推荐.....................rs=1;delay(5);rw=0;delay(5);Lcd_data=dat;delay(10);en=0;delay(5);en=1;delay(10);}/*初始化*/voidLcd_init(){Lcd_data=0x00;delay(15);Write_com(0x38);delay(5);Write_com(0x38);delay(5);Write_com(0x38);delay(5);7.....................最新资料整理推荐.............6、........Write_com(0x38);/*显示模式设置*/Write_com(0x08);/*显示关闭*/Write_com(0x01);/*显示清屏*/Write_com(0x06);/*显示光标移动设置*/Write_com(0x0c);/*显示开及光标设置*/}voidWrite_char(ucharx,uchary,uchardat){x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/if(x)y7、=0x40;/*如果y大于1,则在第二行显示*/y8、=0x80;Write_com(y);W9、rite_data(dat);}voidWrite_string(ucharx,uchary,uchar*str){ucharlength=0;x&=0x1;/*限制x不能大于1*/7.....................最新资料整理推荐.....................y&=0xf;/*限制y不能大于15*/while(*str!=' '){Write_char(x,y,*str);y++;str++;}}voidClear_line(ucharline){Write_string(line,0,"");switch(10、line){case0:Write_com(0x80);case1:Write_com(0x80+0x40);default:break;}}voidClear_all(){7.....................最
5、整理推荐.....................rs=1;delay(5);rw=0;delay(5);Lcd_data=dat;delay(10);en=0;delay(5);en=1;delay(10);}/*初始化*/voidLcd_init(){Lcd_data=0x00;delay(15);Write_com(0x38);delay(5);Write_com(0x38);delay(5);Write_com(0x38);delay(5);7.....................最新资料整理推荐.............
6、........Write_com(0x38);/*显示模式设置*/Write_com(0x08);/*显示关闭*/Write_com(0x01);/*显示清屏*/Write_com(0x06);/*显示光标移动设置*/Write_com(0x0c);/*显示开及光标设置*/}voidWrite_char(ucharx,uchary,uchardat){x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/if(x)y
7、=0x40;/*如果y大于1,则在第二行显示*/y
8、=0x80;Write_com(y);W
9、rite_data(dat);}voidWrite_string(ucharx,uchary,uchar*str){ucharlength=0;x&=0x1;/*限制x不能大于1*/7.....................最新资料整理推荐.....................y&=0xf;/*限制y不能大于15*/while(*str!=' '){Write_char(x,y,*str);y++;str++;}}voidClear_line(ucharline){Write_string(line,0,"");switch(
10、line){case0:Write_com(0x80);case1:Write_com(0x80+0x40);default:break;}}voidClear_all(){7.....................最
此文档下载收益归作者所有