![1602显示万年历_第1页](http://file3.renrendoc.com/fileroot_temp3/2022-4/17/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d1.gif)
![1602显示万年历_第2页](http://file3.renrendoc.com/fileroot_temp3/2022-4/17/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d2.gif)
![1602显示万年历_第3页](http://file3.renrendoc.com/fileroot_temp3/2022-4/17/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d3.gif)
![1602显示万年历_第4页](http://file3.renrendoc.com/fileroot_temp3/2022-4/17/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d4.gif)
![1602显示万年历_第5页](http://file3.renrendoc.com/fileroot_temp3/2022-4/17/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d/aab98d3e-572e-4444-a56f-b8e9b8cb8e1d5.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1602显示万年历#include<reg52.h> / 包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义#include <intrins.h> sbit SCK=P2八7; 时钟sbit SDA=P2八6; 数据sbit RST = P2八5; DS1302 复位sbit RS = P2A0;定义端口sbit RW = P2A1;sbit EN = P2A2;#define RS_CLR RS=0#define RS_SET RS=1#define RW_CLR RW=0#define RW_SET RW=1#define EN_CLR EN=0#de
2、fine EN_SET EN=1 #define DataPort P0bit ReadRTC_Flag;/ 定义读 DS1302标志unsignedcharl_tmpdate7=59,42,22,22,1,2,13;/ 秒分时日月 周年unsigned char l_tmpdisplay18;codeunsignedcharwrite_rtc_address7=0x80,0x82,0x84,0x86,0x88,0x8a,0x8c; /秒分时日月周年 最低位读写位codeunsignedcharread_rtc_address7=0x81,0x83,0x85,0x87,0x89 ,0x8b,0
3、x8d; /读的地址/*/*函 数 声 明*/*/void Write_Ds1302_byte(unsigned char temp);void Write_Ds1302( unsigned char address,unsigned char dat );unsigned char Read_Ds1302 ( unsigned char address );void Read_RTC(void);/read RTCvoid Set_RTC(void); /set RTCvoid InitTIMER0(void);/inital timer0/*uS 延时函数,含有输入参数 unsigned
4、char t , 无返回值unsigned char 是定义无符号字符变量, 其值的 范围是0255 这里使用晶振 12M ,精确延时请使用汇 编 ,大致延时长度如下 T=tx2+5 uS*/void DelayUs2x(unsigned char t)while(-t);/*mS 延时函数,含有输入参数unsigned char t ,无返回值unsigned char 是定义无符号字符变量, 其值的范围是0255 这里使用晶振 12M ,精确延时请使用汇编*/void DelayMs(unsigned char t)while(t-)/大致延时1mSDelayUs2x(245);Delay
5、Us2x(245);/*判忙函数*/bit LCD_Check_Busy(void)DataPort= 0xFF;RS_CLR;RW_SET;EN_CLR;_nop_();EN_SET;return (bit)(DataPort & 0x80);/*写入命令函数*/void LCD_Write_Com(unsigned char com)while(LCD_Check_Busy(); / 忙则等待RS_CLR;RW_CLR;EN_SET;DataPort= com;_nop_();EN_CLR;/*写入数据函数*/void LCD_Write_Data(unsigned char Da
6、ta)while(LCD_Check_Busy(); / 忙则等待RS_SET;RW_CLR;EN_SET;DataPort= Data;_nop_();EN_CLR;/*清屏函数*/void LCD_Clear(void)LCD_Write_Com(0x01);DelayMs(5);/*写入字符串函数*/charvoid LCD_Write_String(unsignedx,unsigned char y,unsigned char *s)if (y = 0)LCD_Write_Com(0x80 + x);elseLCD_Write_Com(0xC0 + x);while (*s)LCD_W
7、rite_Data( *s);s +;/*写入字符函数void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data)if (y = 0)LCD_Write_Com(0x80 + x);elseLCD_Write_Com(0xC0 + x);LCD_Write_Data( Data); */*写入数字函数 字符的地址加 0x30显示数字*/void LCD_Write_num(unsigned charx,unsigned char y,unsigned char num)if (y = 0)LCD_Write_Co
8、m(0x80 + x);elseLCD_Write_Com(0xC0 + x);LCD_Write_Data( 0x30+num);/*初始化函数*/ void LCD_Init(void)LCD_Write_Com(0x38); /* 显示模式设 置*/DelayMs(5);LCD_Write_Com(0x38);DelayMs(5);LCD_Write_Com(0x38);DelayMs(5);LCD_Write_Com(0x38);LCD_Write_Com(0x08);/* 显示关闭*/LCD_Write_Com(0x01);/*显示清屏*/LCD_Write_Com(0x06); /
9、* 显示光标移动设置 */DelayMs(5);LCD_Write_Com(0x0C); /* 显示开及光标设置 */*/*写 一 个 字 节*/ /* */void Write_Ds1302_Byte(unsigned char temp)unsigned char i;for (i=0;i<8;i+)/循环8 次 写入数据SCK=0;SDA=temp&0x01;/每次传输低字节temp>>=1;/右移一位SCK=1;/*/*入 DS1302*/ /* */void Write_Ds1302(address,unsigned char dat )RST=0;_nop
10、_();SCK=0;_nop_();RST=1;unsigned char/启动_nop_();Write_Ds1302_Byte(address); /发送地址Write_Ds1302_Byte(dat);/发送数据RST=0;/恢复/*/*读出 DS1302 数据*/*/unsigned char Read_Ds1302 ( unsigned char address )unsigned char i,temp=0x00;RST=0;_nop_();_nop_();SCK=0;_nop_();_nop_();RST=1;_nop_();_nop_();Write_Ds1302_Byte(a
11、ddress);for (i=0;i<8;i+)/循环8 次 读取数据if(SDA)temp|=0x80;/每次传输低字节SCK=0;temp>>=1;/右移一位_nop_();_nop_();_nop_();SCK=1;RST=0;_nop_();以下为DS1302复位的稳定时间_nop_();RST=0;SCK=0;_nop_();_nop_();_nop_();_nop_();SCK=1;_nop_();_nop_();SDA=0;_nop_();_nop_();SDA=1;_nop_();/返回_nop_();return (temp);/*/*读时钟数据*/*/ v
12、oid Read_RTC(void) unsigned char i,*p;p=read_rtc_address;/读取 日历/地址传递for(i=0;i<7;i+)月周年/分 7 次读取 秒分时日l_tmpdatei=Read_Ds1302(*p);p+;/*/*设定时钟数据*/ /*/设定 日历*/ void Set_RTC(void)unsigned char i,*p,tmp;for(i=0;i<7;i+) /BCD 处理tmp=l_tmpdatei/10;l_tmpdatei=l_tmpdatei%10;l_tmpdatei=l_tmpdatei+tmp*16;Write
13、_Ds1302(0x8E,0X00);p=write_rtc_address; / 传地址 for(i=0;i<7;i+)/7 次写入秒分时日月周年Write_Ds1302(*p,l_tmpdatei); p+;Write_Ds1302(0x8E,0x80);/* */*定时器中断函数*/ /* */ void tim(void) interrupt 1 using 1/中断,用于数码管扫描 static unsigned char num;TH0=0xf5;TL0=0xe0;num+;1302if(10=num)/ 隔段时间读取的数据。时间间隔可以调整ReadRTC_Flag=1; /
14、使用标志位判断 num=0;/*显示部分*/ void displaylcd(void)LCD_Init();LCD_Clear();LCD_Write_num(0,1,l_tmpdisplay0);LCD_Write_num(1,1,l_tmpdisplay1); / 秒LCD_Write_String(2,1,":");LCD_Write_num(3,1,l_tmpdisplay3);LCD_Write_num(4,1,l_tmpdisplay4); /分LCD_Write_String(5,1,":");LCD_Write_num(6,1,l_tm
15、pdisplay6);LCD_Write_num(7,1,l_tmpdisplay7); /时LCD_Write_String(9,0,"w");LCD_Write_String(10,0,"e");LCD_Write_String(11,0,"e");LCD_Write_String(12,0,"k");LCD_Write_String(13,0,":");LCD_Write_num(14,0,l_tmpdisplay8);LCD_Write_num(15,0,l_tmpdisplay9);/
16、 周LCD_Write_String(2,0,"-");LCD_Write_num(3,0,l_tmpdisplay11);/ 日LCD_Write_num(4,0,l_tmpdisplay12);LCD_Write_String(5,0,"-");LCD_Write_num(6,0,l_tmpdisplay16);/ 月LCD_Write_num(7,0,l_tmpdisplay17);LCD_Write_num(0,0,l_tmpdisplay14);/LCD_Write_num(1,0,l_tmpdisplay15); 年l_tmpdisplay0
17、=l_tmpdate2/16;l_tmpdisplay1=l_tmpdate2&0x0f;l_tmpdisplay3=l_tmpdate1/16;l_tmpdisplay4=l_tmpdate1&0x0f;l_tmpdisplay6=l_tmpdate0/16;l_tmpdisplay7=l_tmpdate0&0x0f;l_tmpdisplay8=l_tmpdate5/16;l_tmpdisplay9=l_tmpdate5&0x0f;l_tmpdisplay11=l_tmpdate4/16;l_tmpdisplay12=l_tmpdate4&0x0f;l_tmpdisplay14=l_tmpdate6/16;l_tmpdisplay15=l_tmpdate6&0x0f;l_tmpdisplay16=l_tmpdate3/16;l_tmpdisplay17=l_tmpdate3&0x0f;/*/*定时器 0
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024-2029年轻型车漆和涂料行业市场现状供需分析及市场深度研究发展前景及规划投资研究报告
- 2024-2029年转子式塑料造粒机行业市场现状供需分析及市场深度研究发展前景及规划投资研究报告
- 2024-2029年超导带行业市场现状供需分析及重点企业投资评估规划分析研究报告
- 2024-2029年资料储存装置行业市场现状供需分析及市场深度研究发展前景及规划投资研究报告
- 2024-2029年视觉尺寸测量行业市场现状供需分析及市场深度研究发展前景及规划投资研究报告
- 2024-2029年装料口行业市场现状供需分析及市场深度研究发展前景及规划投资研究报告
- 2024-2029年血糖仪行业市场深度分析及竞争格局与投资研究报告
- 2024-2029年虚拟电厂行业市场现状供需分析及重点企业投资评估规划分析研究报告
- 2024-2029年菠萝蛋白酶和木瓜蛋白酶行业市场现状供需分析及市场深度研究发展前景及规划投资研究报告
- 2024-2029年药丸分配器和提醒行业市场现状供需分析及重点企业投资评估规划分析研究报告
- 部编版四年级下册道德与法治期末测试卷及参考答案(巩固)
- 高中生典型事例500字【五篇】
- 2024年普通高等学校招生全国统一考试高三第三次联合诊断检测语文试题
- 中国老年糖尿病诊疗指南(2024)解读
- 2024年吉林省公安机关面向新疆警察学院定向生考试录用人民警察拟录用人员招聘笔试参考题库附带答案详解
- 小学作业设计比赛评分标准
- “学习任务群”视阈下习作单元教学研究-以统编版语文四年级下册《海上日出》为例
- 轴承精密热处理工艺
- 羌族地区旅游产业融合发展研究
- 北斗系统应用创意设计
- 2024-2029全球及中国麻醉性镇痛药行业市场发展分析及前景趋势与投资发展研究报告
评论
0/150
提交评论