找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5122|回复: 1
打印 上一主题 下一主题
收起左侧

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仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  1. #include <iom16v.h>
  2. #include <macros.h>
  3. #include "ds1302.h"
  4. #include "LCD1602.h"

  5. void main(void)
  6. {
  7.         unsigned char temp;

  8.         Port_init();   //端口初始化
  9.         LCD_init();    //LCD初始化
  10.         LCD_clear();   //清屏
  11.         ds1302_init(); //DS1302初始化
  12.         delay_ms(10);
  13.         ds1302_write_time(); //写入初始值

  14.         while (1)
  15.         {
  16.                 delay_ms(200);       //每200ms更新一次时间
  17.                 ds1302_read_time();  //读取时间
  18.                 //LCD_clear();       //清屏
  19.                                
  20.                 temp = (time_buf[0] >> 4) + '0';
  21.                 LCD_write_char(0, 0, temp);/*年*/
  22.                 temp = (time_buf[0] & 0x0F) + '0';
  23.                 LCD_write_char(1, 0, temp);
  24.                 temp = (time_buf[1] >> 4) + '0';
  25.                 LCD_write_char(2, 0, temp);
  26.                 temp = (time_buf[1] & 0x0F) + '0';
  27.                 LCD_write_char(3, 0, temp);
  28.                 LCD_write_char(4, 0, '-');
  29.                
  30.                 temp = (time_buf[2] >> 4) + '0';
  31.                 LCD_write_char(5, 0, temp);/*月*/
  32.                 temp = (time_buf[2] & 0x0F) + '0';
  33.                 LCD_write_char(6, 0, temp);
  34.                 LCD_write_char(7, 0, '-');
  35.                
  36.                 temp = (time_buf[3] >> 4) + '0';
  37.                 LCD_write_char(8, 0, temp);/*日*/
  38.                 temp = (time_buf[3] & 0x0F) + '0';
  39.                 LCD_write_char(9, 0, temp);
  40.                
  41.                 LCD_write_str(0,1,"week:");
  42.                 temp = (time_buf[7]) + '0';
  43.                 LCD_write_char(5, 1, temp);  //周
  44.                
  45.                 temp = (time_buf[4] >> 4) + '0';
  46.                 LCD_write_char(8, 1, temp);  //时
  47.                 temp = (time_buf[4] & 0x0F) + '0';
  48.                 LCD_write_char(9, 1, temp);
  49.                 LCD_write_char(10, 1, ':');
  50.                
  51.                 temp = (time_buf[5] >> 4) + '0';
  52.                 LCD_write_char(11, 1, temp);/*分*/
  53.                 temp = (time_buf[5] & 0x0F) + '0';
  54.                 LCD_write_char(12, 1, temp);
  55.                 LCD_write_char(13, 1, ':');
  56.                
  57.                 temp = (time_buf[6] >> 4) + '0';
  58.                 LCD_write_char(14, 1, temp);/*秒*/
  59.                 temp = (time_buf[6] & 0x0F) + '0';
  60.                 LCD_write_char(15, 1, temp);
  61.         }
  62. }
复制代码

所有资料51hei提供下载:
LCD1602&amp;DS1302时钟测试.zip (183.08 KB, 下载次数: 53)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:336195 发表于 2019-9-11 11:55 | 只看该作者
没显示啊 哥
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表