找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2813|回復: 0
打印 上一主題 下一主題
收起左側

PCF8563+LCD1602的單片機源碼

[復制鏈接]
跳轉到指定樓層
樓主
ID:297622 發(fā)表于 2018-7-7 20:24 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
我在網(wǎng)上找的一個比較完整的程序。自己也進行了一點兒完善。注釋比較清晰,需要用的拿去

單片機源程序如下:
  1. /*PCF8563+1602LCD*/
  2. /*BCD:將一字節(jié)二進制空間分為2個4bit來存儲數(shù)據(jù),每4bit來表示一個一位10進制數(shù)*/

  3. #include<reg52.h>
  4. #include<stdio.h>
  5. #include<intrins.h>
  6. #include"I2C.h"
  7. #include "lcd1602.h"

  8. //typedef unsigned int uint;
  9. //typedef unsigned char uchar;

  10. code unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //共陰數(shù)碼管 0-9  '-' '熄滅‘表

  11. uchar tmpdisplay[8]; //定義顯示緩存數(shù)組

  12. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  13. /*+++++*/uchar tmpdate[7]={0,39,19,07,6,07,18}; //時間初始化:秒、分、時、日、星期、月、年;+++++++++++/**/
  14. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


  15. uchar rtc_address[7]={0x02,0x03,0x04,0x05,0x06,0x07,0x08};  //PCF8563中的秒、分、時、日、星期、月、年寄存器地址

  16. /**************************************************
  17. 函數(shù)名稱:set_rtc()
  18. 函數(shù)功能:BCD處理,將十進制數(shù)轉化為BCD編碼(按十六進制數(shù)計算)
  19. ***************************************************/                                
  20. void set_rtc()          //設定時鐘數(shù)據(jù)(pcf8563芯片中的數(shù)據(jù)是以bcd形式存儲和處理)
  21. {
  22.         uchar i,tmp;
  23.         for(i=0;i<7;i++)    //BCD處理,將十進制數(shù)轉化為BCD編碼(按十六進制數(shù)計算)
  24.         {      
  25.                 tmp=tmpdate[i]/10;                        //將十位分離出
  26.                 tmpdate[i]=tmpdate[i]%10;                //將個位分離出
  27.                 tmpdate[i]=tmpdate[i]+tmp*16;                        //合成1個由2個BCD碼組成的數(shù)
  28.         }  
  29.         ISendStr(0x02,tmpdate,7); //將數(shù)據(jù)寫入PCF8563相應寄存器
  30. }

  31. /**************************************************
  32. 函數(shù)名稱:rtc_init()
  33. 函數(shù)功能:時鐘初始化       
  34. ***************************************************/       
  35. void rtc_init()                //時鐘初始化
  36. {
  37.         set_rtc();                                                        //將預設的時間進行DEC->BCD轉換
  38.         ISendByte(0x00,0x00);
  39. }

  40. /**************************************************
  41. 函數(shù)名稱:ead_rtc()
  42. 函數(shù)功能:讀時鐘函數(shù),將讀出的數(shù)據(jù)存入tmpdate緩存數(shù)組中
  43. ***************************************************/       
  44. void read_rtc()          //讀時鐘函數(shù),將讀出的數(shù)據(jù)存入tmpdate緩存數(shù)組中
  45. {
  46.         IRcvStr(0x02,tmpdate,7);
  47.         tmpdate[0]=tmpdate[0]&0x7f;        //秒
  48.         tmpdate[1]=tmpdate[1]&0x7f;        //分
  49.         tmpdate[2]=tmpdate[2]&0x3f;        //時
  50.         tmpdate[3]=tmpdate[3]&0x3f;        //日
  51.         tmpdate[4]=tmpdate[4]&0x07;        //星期
  52.         tmpdate[5]=tmpdate[5]&0x0f;        //月
  53.         tmpdate[6]=tmpdate[6]&0xff;        //年  
  54.        
  55. }

  56. /**********************主函數(shù)*******************************************/
  57. void main()
  58. {
  59.         init_lcd1602();                                        //1602初始化
  60. //        rtc_init();                                                        //時間初始化
  61.        
  62.         while(1)
  63.         {         
  64.                           read_rtc();                                                                                                                //讀時間并處理

  65.                           write_firstline(5,tmpdate[6]);                    //顯示年
  66.                           write_com(0x80+5);
  67.                           
  68.                           write_firstline(8,tmpdate[5]);                    //顯示月
  69.                           write_com(0x80+8);
  70.                           
  71.                           write_firstline(11,tmpdate[3]);                    //顯示日
  72.                           write_com(0x80+11);
  73.                           
  74.                           write_firstline(14,tmpdate[4]);                    //顯示星期
  75.                           write_com(0x80+14);
  76. ……………………

  77. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
pcf8563 lcd1602.zip (35.86 KB, 下載次數(shù): 85)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏4 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表