标题:
LCD1602&DS1302时钟测试程序+仿真图分享
[打印本页]
作者:
HI-XM
时间:
2018-12-17 16:50
标题:
LCD1602&DS1302时钟测试程序+仿真图分享
comments :
1、八线制驱动LCD1602B:PB0-PB7为数据线,PD3/PD4/PD6控制LCD1602B的RS,RW,EN。
2、设置和读取DS1302内部时钟,并通过LCD1602显示。
3、进行此实验请插上JP1、JP2的所有8个短路块,PC2、PC3、PC4、PC7短路块。
4、DS1302芯片接口占用JTAG仿真接口,在做实验时需要关闭mega16的JTAG功能,否则
不正常显示。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
0.png
(17.39 KB, 下载次数: 115)
下载附件
2018-12-18 01:39 上传
0.png
(15.38 KB, 下载次数: 119)
下载附件
2018-12-18 01:38 上传
单片机源程序如下:
#include <iom16v.h>
#include <macros.h>
#include "ds1302.h"
#include "LCD1602.h"
void main(void)
{
unsigned char temp;
Port_init(); //端口初始化
LCD_init(); //LCD初始化
LCD_clear(); //清屏
ds1302_init(); //DS1302初始化
delay_ms(10);
ds1302_write_time(); //写入初始值
while (1)
{
delay_ms(200); //每200ms更新一次时间
ds1302_read_time(); //读取时间
//LCD_clear(); //清屏
temp = (time_buf[0] >> 4) + '0';
LCD_write_char(0, 0, temp);/*年*/
temp = (time_buf[0] & 0x0F) + '0';
LCD_write_char(1, 0, temp);
temp = (time_buf[1] >> 4) + '0';
LCD_write_char(2, 0, temp);
temp = (time_buf[1] & 0x0F) + '0';
LCD_write_char(3, 0, temp);
LCD_write_char(4, 0, '-');
temp = (time_buf[2] >> 4) + '0';
LCD_write_char(5, 0, temp);/*月*/
temp = (time_buf[2] & 0x0F) + '0';
LCD_write_char(6, 0, temp);
LCD_write_char(7, 0, '-');
temp = (time_buf[3] >> 4) + '0';
LCD_write_char(8, 0, temp);/*日*/
temp = (time_buf[3] & 0x0F) + '0';
LCD_write_char(9, 0, temp);
LCD_write_str(0,1,"week:");
temp = (time_buf[7]) + '0';
LCD_write_char(5, 1, temp); //周
temp = (time_buf[4] >> 4) + '0';
LCD_write_char(8, 1, temp); //时
temp = (time_buf[4] & 0x0F) + '0';
LCD_write_char(9, 1, temp);
LCD_write_char(10, 1, ':');
temp = (time_buf[5] >> 4) + '0';
LCD_write_char(11, 1, temp);/*分*/
temp = (time_buf[5] & 0x0F) + '0';
LCD_write_char(12, 1, temp);
LCD_write_char(13, 1, ':');
temp = (time_buf[6] >> 4) + '0';
LCD_write_char(14, 1, temp);/*秒*/
temp = (time_buf[6] & 0x0F) + '0';
LCD_write_char(15, 1, temp);
}
}
复制代码
所有资料51hei提供下载:
LCD1602&DS1302时钟测试.zip
(183.08 KB, 下载次数: 53)
2018-12-17 16:50 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
xiedong77777
时间:
2019-9-11 11:55
没显示啊 哥
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1