1602显示万年历_第1页
1602显示万年历_第2页
1602显示万年历_第3页
1602显示万年历_第4页
1602显示万年历_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

include 包含头文件 一般情况不需要改动 头文件包含特殊功能寄存器的定义 include sbit SCK P2 7 时钟 sbit SDA P2 6 数据 sbit RST P2 5 DS1302 复位 sbit RS P2 0 定义端口 sbit RW P2 1 sbit EN P2 2 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 define EN SET EN 1 define DataPort P0 bit ReadRTC Flag 定义读 DS1302 标志 unsigned char l tmpdate 7 59 42 22 22 1 2 13 秒分时日月周年 unsigned char l tmpdisplay 18 code unsigned char write rtc address 7 0 x80 0 x82 0 x84 0 x86 0 x88 0 x8a 0 x8c 秒分时日月 周年 最低位读写位 code unsigned char read rtc address 7 0 x81 0 x83 0 x85 0 x87 0 x89 0 x8b 0 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 RTC void Set RTC void set RTC void InitTIMER0 void inital timer0 uS 延时函数 含有输入参数 unsigned char t 无返回值 unsigned char 是定义无符号字符变量 其值的范围是 0 255 这里使用晶振 12M 精确延时请使用汇编 大致延时 长度如下 T tx2 5 uS void DelayUs2x unsigned char t while t mS 延时函数 含有输入参数 unsigned char t 无返回值 unsigned char 是定义无符号字符变量 其值的范围是 0 255 这里使用晶振 12M 精确延时请使用汇编 void DelayMs unsigned char t while t 大致延时 1mS DelayUs2x 245 DelayUs2x 245 判忙函数 bit LCD Check Busy void DataPort 0 xFF RS CLR RW SET EN CLR nop EN SET return bit DataPort 写入命令函数 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 Data while LCD Check Busy 忙则等待 RS SET RW CLR EN SET DataPort Data nop EN CLR 清屏函数 void LCD Clear void LCD Write Com 0 x01 DelayMs 5 写入字符串函数 void LCD Write String unsigned char x unsigned char y unsigned char s if y 0 LCD Write Com 0 x80 x else LCD Write Com 0 xC0 x while s LCD Write Data s s 写入字符函数 void LCD Write Char unsigned char x unsigned char y unsigned char Data if y 0 LCD Write Com 0 x80 x else LCD Write Com 0 xC0 x LCD Write Data Data 写入数字函数 字符的地址加 0 x30 显示数字 void LCD Write num unsigned char x unsigned char y unsigned char num if y 0 LCD Write Com 0 x80 x else LCD Write Com 0 xC0 x LCD Write Data 0 x30 num 初始化函数 void LCD Init void LCD Write Com 0 x38 显示模式设置 DelayMs 5 LCD Write Com 0 x38 DelayMs 5 LCD Write Com 0 x38 DelayMs 5 LCD Write Com 0 x38 LCD Write Com 0 x08 显示关闭 LCD Write Com 0 x01 显示清屏 LCD Write Com 0 x06 显示光标移动设置 DelayMs 5 LCD Write Com 0 x0C 显示开及光标设置 写一个字节 void Write Ds1302 Byte unsigned char temp unsigned char i for i 0 i 1 右移一位 SCK 1 写入 DS1302 void Write Ds1302 unsigned char address unsigned char dat RST 0 nop SCK 0 nop RST 1 nop 启动 Write Ds1302 Byte address 发送地址 Write Ds1302 Byte dat 发送数据 RST 0 恢复 读出 DS1302 数据 unsigned char Read Ds1302 unsigned char address unsigned char i temp 0 x00 RST 0 nop nop SCK 0 nop nop RST 1 nop nop Write Ds1302 Byte address for i 0 i 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 返回 读时钟数据 void Read RTC void 读取 日历 unsigned char i p p read rtc address 地址传递 for i 0 i 7 i 分 7 次读取 秒分时日月周年 l tmpdate i Read Ds1302 p p 设定时钟数据 void Set RTC void 设定 日历 unsigned char i p tmp for i 0 i 7 i BCD 处理 tmp l tmpdate i 10 l tmpdate i l tmpdate i 10 l tmpdate i l tmpdate i tmp 16 Write Ds1302 0 x8E 0X00 p write rtc address 传地址 for i 0 i 7 i 7 次写入 秒分时日月周年 Write Ds1302 p l tmpdate i p Write Ds1302 0 x8E 0 x80 定时器中断函数 void tim void interrupt 1 using 1 中断 用于数码管扫描 static unsigned char num TH0 0 xf5 TL0 0 xe0 num if 10 num 隔段时间读取 1302 的数据 时间间隔可以调整 ReadRTC Flag 1 使用标志位判断 num 0 显示部分 void displaylcd void LCD Init LCD Clear LCD Write num 0 1 l tmpdisplay 0 LCD Write num 1 1 l tmpdisplay 1 秒 LCD Write String 2 1 LCD Write num 3 1 l tmpdisplay 3 LCD Write num 4 1 l tmpdisplay 4 分 LCD Write String 5 1 LCD Write num 6 1 l tmpdisplay 6 LCD Write num 7 1 l tmpdisplay 7 时 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 tmpdisplay 8 LCD Write num 15 0 l tmpdisplay 9 周 LCD Write String 2 0 LCD Write num 3 0 l tmpdisplay 11 日 LCD Write num 4 0 l tmpdisplay 12 LCD Write String 5 0 LCD Write num 6 0 l tmpdisplay 16 月 LCD Write num 7 0 l tmpdisplay 17 LCD Write num 0 0 l tmpdisplay 14 LCD Write num 1 0 l tmpdisplay 15 年 l tmpdisplay 0 l tmpdate 2 16 l tmpdisplay 1 l tmpdate 2 l tmpdisplay 3 l tmpdate 1 16 l tmpdisplay 4 l tmpdate 1 l tmpdisplay 6 l tmpdate 0 16 l tmpdisplay 7 l tmpdate 0 l tmpdisplay 8 l tmpdate 5 16 l tmpdisplay 9 l tmpdate 5 l tmpdisplay 11 l tmpdate 4 16 l tmpdisplay 12 l tmpdate 4 l tmpdisplay 14 l tmpdate 6 16 l tmpdisplay 15 l tmpdate 6 l tmpdisplay 16 l tmpdate 3 16 l tmpdisplay 17 l tmpdate 3 定时器 0 初始化 void In

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论