欢迎来到天天文库
浏览记录
ID:52693324
大小:17.46 KB
页数:4页
时间:2020-03-29
《在LCD1602上显示0--99999-源程序.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、========================================作者:Ni的年少W^o轻狂创建时间:2008.06.25========================================//==========程序功能===========//在LCD1602上显示0--99999//=============================#include#include"LCD1602.h"voidIntTOStr(uintn,uchar*str);ucharstr[10];//存储数据main(){uintcount;LCD_init();
2、LCD_write_command(0x01);//清屏显示delay(200);gotoxy(2,1);LCD_display("2008/06/27");gotoxy(3,2);LCD_display("01:56:56");delay1(2000);LCD_write_command(0x01);//清屏显示delay(200);gotoxy(2,1);LCD_display("LCD1602TEST");gotoxy(4,2);LCD_display("SUCCESS");delay1(2000);LCD_write_command(0x01);//清屏显示delay(200);whi
3、le(1){IntTOStr(count++,str);gotoxy(4,2);LCD_display(str);delay1(100);}}voidIntTOStr(uintn,uchar*str){uchara[5];uchari,j;a[0]=(n/10000)%10;a[1]=(n/1000)%10;a[2]=(n/100)%10;a[3]=(n/10)%10;a[4]=(n/1)%10;for(i=0;i<5;i++)a[i]='0'+a[i];for(i=0;a[i]=='0'&&i<=3;i++);for(j=0;j
4、i++){*str=a[i];str++;}*str=' ';}========LCD驱动程序========#defineLCD_DBP0//定义LCD的数据端口sbitLCD_RS=P2^0;sbitLCD_RW=P2^1;sbitLCD_E=P2^2;#defineucharunsignedchar#defineuintunsignedint//===========延时子函数========================voiddelay(uintx){uinti,j;for(i=x;i>0;i--)for(j=0;j<2;j++);}//==================写指令
5、函数=================voidLCD_write_command(ucharcommand){LCD_DB=command;LCD_RS=0;//指令LCD_RW=0;//写入LCD_E=1;LCD_E=0;delay(1);//等待执行完毕。。。}//===================写数据函数=================voidLCD_write_data(uchardat){LCD_DB=dat;LCD_RS=1;//数据寄存器LCD_RW=0;//写入数据LCD_E=1;LCD_E=0;delay(1);//等待程序执行完毕。。。}/*============
6、显示一个字符子函数===============voidLCD_disp_char(ucharx,uchary,uchardat){ucharaddress;if(y==1)address=0x80+x;elseaddress=0xc0+x;LCD_write_command(address);LCD_write_data(dat);}===================================*///==========延时1====================voiddelay1(uintx){uinti,j;for(j=0;j7、);}//===========初始化函数=============voidLCD_init(void){LCD_write_command(0x38);//设置8位格式,2行,5*7LCD_write_command(0x0c);//整体显示,关光标,不闪烁LCD_write_command(0x06);//设定输入方式,增量不移位LCD_write_command(0x01);//清屏显示de
7、);}//===========初始化函数=============voidLCD_init(void){LCD_write_command(0x38);//设置8位格式,2行,5*7LCD_write_command(0x0c);//整体显示,关光标,不闪烁LCD_write_command(0x06);//设定输入方式,增量不移位LCD_write_command(0x01);//清屏显示de
此文档下载收益归作者所有