欢迎来到天天文库
浏览记录
ID:49822705
大小:90.86 KB
页数:5页
时间:2020-03-04
《lcd1602显示及测试程序.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、本程序共分为三个文件:Main.cLcd1602.cLcd1602.h/************文件Main.c*************/#include#include#defineucharunsignedchar#defineuintunsignedintvoiddelay_ms(uintx){uinti,j;for(i=0;i2、ear_line(0);Write_string(0,0,"clear0lineOK!");delay_ms(1000);Clear_line(1);Write_string(1,0,"clear1lineOK!");delay_ms(1000);Clear_all();Write_string(0,1,"ClearallOk!");while(1);}/********文件Lcd1602.c**************/#include#include#defineucharunsignedchar#defineuintunsignedint#def3、ineNop_nop_()#defineLcd_dataP0/*数据口*/#definebusy0x80/*检测忙状态*/sbitrs=P2^4;sbitrw=P2^5;sbiten=P2^6;voiddelay(ucharx){uchari,j;for(i=0;i4、dat){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);Write_com(0x38);/*显示模式设置*/Write_com(0x08);/*显示关闭*/Write_com(0x01);/*显示清屏*/Write_com(0x06);/*5、显示光标移动设置*/Write_com(0x0c);/*显示开及光标设置*/}voidWrite_char(ucharx,uchary,uchardat){x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/if(x)y6、=0x40;/*如果y大于1,则在第二行显示*/y7、=0x80;Write_com(y);Write_data(dat);}voidWrite_string(ucharx,uchary,uchar*str){ucharlength=0;x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/while(*str!=' '){8、Write_char(x,y,*str);y++;str++;}}voidClear_line(ucharline){Write_string(line,0,"");switch(line){case0:Write_com(0x80);case1:Write_com(0x80+0x40);default:break;}}voidClear_all(){Write_com(0x01);Write_com(0x80);}/**********文件Lcd1602.h**************/#defineucharunsignedchar#defineuintunsignedint#ifnde9、fLcd1602_h#defineLcd1602_hexternLcd_init();externWrite_data(uchardat);externWrite_char(ucharx,uchary,uchardat);externWrite_string(ucharx,uchary,uchar*dat);externClear_line(ucharline);externClear_all();#endi
2、ear_line(0);Write_string(0,0,"clear0lineOK!");delay_ms(1000);Clear_line(1);Write_string(1,0,"clear1lineOK!");delay_ms(1000);Clear_all();Write_string(0,1,"ClearallOk!");while(1);}/********文件Lcd1602.c**************/#include#include#defineucharunsignedchar#defineuintunsignedint#def
3、ineNop_nop_()#defineLcd_dataP0/*数据口*/#definebusy0x80/*检测忙状态*/sbitrs=P2^4;sbitrw=P2^5;sbiten=P2^6;voiddelay(ucharx){uchari,j;for(i=0;i4、dat){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);Write_com(0x38);/*显示模式设置*/Write_com(0x08);/*显示关闭*/Write_com(0x01);/*显示清屏*/Write_com(0x06);/*5、显示光标移动设置*/Write_com(0x0c);/*显示开及光标设置*/}voidWrite_char(ucharx,uchary,uchardat){x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/if(x)y6、=0x40;/*如果y大于1,则在第二行显示*/y7、=0x80;Write_com(y);Write_data(dat);}voidWrite_string(ucharx,uchary,uchar*str){ucharlength=0;x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/while(*str!=' '){8、Write_char(x,y,*str);y++;str++;}}voidClear_line(ucharline){Write_string(line,0,"");switch(line){case0:Write_com(0x80);case1:Write_com(0x80+0x40);default:break;}}voidClear_all(){Write_com(0x01);Write_com(0x80);}/**********文件Lcd1602.h**************/#defineucharunsignedchar#defineuintunsignedint#ifnde9、fLcd1602_h#defineLcd1602_hexternLcd_init();externWrite_data(uchardat);externWrite_char(ucharx,uchary,uchardat);externWrite_string(ucharx,uchary,uchar*dat);externClear_line(ucharline);externClear_all();#endi
4、dat){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);Write_com(0x38);/*显示模式设置*/Write_com(0x08);/*显示关闭*/Write_com(0x01);/*显示清屏*/Write_com(0x06);/*
5、显示光标移动设置*/Write_com(0x0c);/*显示开及光标设置*/}voidWrite_char(ucharx,uchary,uchardat){x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/if(x)y
6、=0x40;/*如果y大于1,则在第二行显示*/y
7、=0x80;Write_com(y);Write_data(dat);}voidWrite_string(ucharx,uchary,uchar*str){ucharlength=0;x&=0x1;/*限制x不能大于1*/y&=0xf;/*限制y不能大于15*/while(*str!=' '){
8、Write_char(x,y,*str);y++;str++;}}voidClear_line(ucharline){Write_string(line,0,"");switch(line){case0:Write_com(0x80);case1:Write_com(0x80+0x40);default:break;}}voidClear_all(){Write_com(0x01);Write_com(0x80);}/**********文件Lcd1602.h**************/#defineucharunsignedchar#defineuintunsignedint#ifnde
9、fLcd1602_h#defineLcd1602_hexternLcd_init();externWrite_data(uchardat);externWrite_char(ucharx,uchary,uchardat);externWrite_string(ucharx,uchary,uchar*dat);externClear_line(ucharline);externClear_all();#endi
此文档下载收益归作者所有