標(biāo)題: 關(guān)于DS1302的實(shí)時(shí)時(shí)鐘程序 [打印本頁]

作者: lzj1998    時(shí)間: 2018-12-12 10:12
標(biāo)題: 關(guān)于DS1302的實(shí)時(shí)時(shí)鐘程序
包括LCD1602顯示和數(shù)碼管顯示

單片機(jī)源程序如下:
  1. /*******************************************************************************
  2. *                 
  3. *                                        普中科技
  4. --------------------------------------------------------------------------------
  5. * 實(shí) 驗(yàn) 名                 : DS1302時(shí)鐘顯示試驗(yàn)
  6. * 實(shí)驗(yàn)說明       : LCD1602顯示時(shí)鐘信息
  7. * 連接方式       : 見連接圖
  8. * 注    意                 :
  9. *******************************************************************************/

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

  13. void LcdDisplay();

  14. /*******************************************************************************
  15. * 函數(shù)名         : main
  16. * 函數(shù)功能                   : 主函數(shù)
  17. * 輸入           : 無
  18. * 輸出                  : 無
  19. *******************************************************************************/

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

  37. void LcdDisplay()
  38. {
  39.         LcdWriteCom(0x80+0X40);
  40.         LcdWriteData('0'+TIME[2]/16);                                //時(shí)
  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. }
復(fù)制代碼

所有資料51hei提供下載:
14、實(shí)時(shí)時(shí)鐘DS1302.rar (358.34 KB, 下載次數(shù): 6)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1