找回密码
 立即注册

QQ登录

只需一步,快速开始

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

关于DS1302的实时时钟程序

[复制链接]
跳转到指定楼层
楼主
ID:443275 发表于 2018-12-12 10:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
包括LCD1602显示和数码管显示

单片机源程序如下:
  1. /*******************************************************************************
  2. *                 
  3. *                                        普中科技
  4. --------------------------------------------------------------------------------
  5. * 实 验 名                 : DS1302时钟显示试验
  6. * 实验说明       : LCD1602显示时钟信息
  7. * 连接方式       : 见连接图
  8. * 注    意                 :
  9. *******************************************************************************/

  10. #include<reg51.h>
  11. #include"lcd.h"
  12. #include"ds1302.h"

  13. void LcdDisplay();

  14. /*******************************************************************************
  15. * 函数名         : main
  16. * 函数功能                   : 主函数
  17. * 输入           : 无
  18. * 输出                  : 无
  19. *******************************************************************************/

  20. void main()
  21. {
  22.         LcdInit();
  23.         Ds1302Init();
  24.         while(1)
  25.         {       
  26.                 Ds1302ReadTime();
  27.                 LcdDisplay();       
  28.         }
  29.        
  30. }
  31. /*******************************************************************************
  32. * 函数名         : LcdDisplay()
  33. * 函数功能                   : 显示函数
  34. * 输入           : 无
  35. * 输出                  : 无
  36. *******************************************************************************/

  37. void LcdDisplay()
  38. {
  39.         LcdWriteCom(0x80+0X40);
  40.         LcdWriteData('0'+TIME[2]/16);                                //时
  41.         LcdWriteData('0'+(TIME[2]&0x0f));                                 
  42.         LcdWriteData('-');
  43.         LcdWriteData('0'+TIME[1]/16);                                //分
  44.         LcdWriteData('0'+(TIME[1]&0x0f));       
  45.         LcdWriteData('-');
  46.         LcdWriteData('0'+TIME[0]/16);                                //秒
  47.         LcdWriteData('0'+(TIME[0]&0x0f));

  48.         LcdWriteCom(0x80);
  49.         LcdWriteData('2');
  50.         LcdWriteData('0');
  51.         LcdWriteData('0'+TIME[6]/16);                        //年
  52.         LcdWriteData('0'+(TIME[6]&0x0f));
  53.         LcdWriteData('-');
  54.         LcdWriteData('0'+TIME[4]/16);                        //月
  55.         LcdWriteData('0'+(TIME[4]&0x0f));
  56.         LcdWriteData('-');
  57.         LcdWriteData('0'+TIME[3]/16);                        //日
  58.         LcdWriteData('0'+(TIME[3]&0x0f));
  59.         LcdWriteCom(0x8D);
  60.         LcdWriteData('0'+(TIME[5]&0x07));        //星期                         
  61. }
复制代码

所有资料51hei提供下载:
14、实时时钟DS1302.rar (358.34 KB, 下载次数: 6)


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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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