基于51单片机与DS1302时钟芯片和LCD1602液晶显示的数字时钟(共9页).docx
《基于51单片机与DS1302时钟芯片和LCD1602液晶显示的数字时钟(共9页).docx》由会员分享,可在线阅读,更多相关《基于51单片机与DS1302时钟芯片和LCD1602液晶显示的数字时钟(共9页).docx(9页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上PROTEUS仿真图:KEIL C程序:#include #include LCD1602.h#include DS1302.hvoid Delay1ms(unsigned int count)unsigned int i,j;for(i=0;icount;i+)for(j=0;j120;j+);main()SYSTEMTIME CurrentTime;LCD_Initial();Initial_DS1302();GotoXY(0,0);Print( tian ma dian zi);GotoXY(0,1);Print(Time: );while(1)DS1302_G
2、etTime(&CurrentTime);TimeToStr(&CurrentTime);GotoXY(6,1);Print(CurrentTime.TimeString);Delay1ms(400);#ifndef LCD_CHAR_1602_2005_4_9#define LCD_CHAR_1602_2005_4_9#include /Port Definitions*sbit LcdRs= P20;sbit LcdRw= P21;sbit LcdEn = P22;sfr DBPort = 0x80;/P0=0x80,P1=0x90,P2=0xA0,P3=0xB0.数据端口/内部等待函数*
3、unsigned char LCD_Wait(void)LcdRs=0;LcdRw=1;_nop_();LcdEn=1;_nop_();/while(DBPort&0x80);/在用Proteus仿真时,注意用屏蔽此语句,在调用GotoXY()时,会进入死循环, /可能在写该控制字时,该模块没有返回写入完备命令,即DBPort&0x80=0x80 /实际硬件时打开此语句LcdEn=0;return DBPort;/向LCD写入命令或数据*#define LCD_COMMAND0 / Command#define LCD_DATA1 / Data#define LCD_CLEAR_SCREEN0
4、x01 / 清屏#define LCD_HOMING 0x02 / 光标返回原点void LCD_Write(bit style, unsigned char input)LcdEn=0;LcdRs=style;LcdRw=0;_nop_();DBPort=input;_nop_();/注意顺序LcdEn=1;_nop_();/注意顺序LcdEn=0;_nop_();LCD_Wait();/设置显示模式*#define LCD_SHOW0x04 /显示开#define LCD_HIDE0x00 /显示关 #define LCD_CURSOR0x02 /显示光标#define LCD_NO_CU
5、RSOR0x00 /无光标 #define LCD_FLASH0x01 /光标闪动#define LCD_NO_FLASH0x00 /光标不闪动void LCD_SetDisplay(unsigned char DisplayMode)LCD_Write(LCD_COMMAND, 0x08|DisplayMode);/设置输入模式*#define LCD_AC_UP0x02#define LCD_AC_DOWN0x00 / default#define LCD_MOVE0x01 / 画面可平移#define LCD_NO_MOVE0x00 /defaultvoid LCD_SetInput(u
6、nsigned char InputMode)LCD_Write(LCD_COMMAND, 0x04|InputMode);/移动光标或屏幕*/*#define LCD_CURSOR0x02 #define LCD_SCREEN0x08#define LCD_LEFT0x00#define LCD_RIGHT0x04void LCD_Move(unsigned char object, unsigned char direction)if(object=LCD_CURSOR)LCD_Write(LCD_COMMAND,0x10|direction);if(object=LCD_SCREEN)L
7、CD_Write(LCD_COMMAND,0x18|direction);*/初始化LCD*void LCD_Initial()LcdEn=0;LCD_Write(LCD_COMMAND,0x38); /8位数据端口,2行显示,5*7点阵LCD_Write(LCD_COMMAND,0x38);LCD_SetDisplay(LCD_SHOW|LCD_NO_CURSOR); /开启显示, 无光标LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); /清屏LCD_SetInput(LCD_AC_UP|LCD_NO_MOVE); /AC递增, 画面不动/*void Goto
8、XY(unsigned char x, unsigned char y)if(y=0)LCD_Write(LCD_COMMAND,0x80|x);if(y=1)LCD_Write(LCD_COMMAND,0x80|(x-0x40);void Print(unsigned char *str)while(*str!=0)LCD_Write(LCD_DATA,*str);str+;/*void LCD_LoadChar(unsigned char user8, unsigned char place)unsigned char i;LCD_Write(LCD_COMMAND,0x40|(place
9、*8);for(i=0; i0; i-) DS1302_IO = ACC0; /相当于汇编中的 RRC DS1302_CLK = 1; DS1302_CLK = 0; ACC = ACC 1; unsigned char DS1302OutputByte(void) /实时时钟读取一字节(内部函数) unsigned char i; for(i=8; i0; i-) ACC = ACC 1; /相当于汇编中的 RRC ACC7 = DS1302_IO; DS1302_CLK = 1; DS1302_CLK = 0; return(ACC); void Write1302(unsigned ch
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 51 单片机 DS1302 时钟 芯片 LCD1602 液晶显示 数字
限制150内