|
我在網(wǎng)上找的一個(gè)比較完整的程序。自己也進(jìn)行了一點(diǎn)兒完善。注釋比較清晰,需要用的拿去
單片機(jī)源程序如下:
- /*PCF8563+1602LCD*/
- /*BCD:將一字節(jié)二進(jìn)制空間分為2個(gè)4bit來(lái)存儲(chǔ)數(shù)據(jù),每4bit來(lái)表示一個(gè)一位10進(jìn)制數(shù)*/
- #include<reg52.h>
- #include<stdio.h>
- #include<intrins.h>
- #include"I2C.h"
- #include "lcd1602.h"
- //typedef unsigned int uint;
- //typedef unsigned char uchar;
-
- code unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //共陰數(shù)碼管 0-9 '-' '熄滅‘表
-
- uchar tmpdisplay[8]; //定義顯示緩存數(shù)組
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- /*+++++*/uchar tmpdate[7]={0,39,19,07,6,07,18}; //時(shí)間初始化:秒、分、時(shí)、日、星期、月、年;+++++++++++/**/
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- uchar rtc_address[7]={0x02,0x03,0x04,0x05,0x06,0x07,0x08}; //PCF8563中的秒、分、時(shí)、日、星期、月、年寄存器地址
- /**************************************************
- 函數(shù)名稱:set_rtc()
- 函數(shù)功能:BCD處理,將十進(jìn)制數(shù)轉(zhuǎn)化為BCD編碼(按十六進(jìn)制數(shù)計(jì)算)
- ***************************************************/
- void set_rtc() //設(shè)定時(shí)鐘數(shù)據(jù)(pcf8563芯片中的數(shù)據(jù)是以bcd形式存儲(chǔ)和處理)
- {
- uchar i,tmp;
- for(i=0;i<7;i++) //BCD處理,將十進(jìn)制數(shù)轉(zhuǎn)化為BCD編碼(按十六進(jìn)制數(shù)計(jì)算)
- {
- tmp=tmpdate[i]/10; //將十位分離出
- tmpdate[i]=tmpdate[i]%10; //將個(gè)位分離出
- tmpdate[i]=tmpdate[i]+tmp*16; //合成1個(gè)由2個(gè)BCD碼組成的數(shù)
- }
- ISendStr(0x02,tmpdate,7); //將數(shù)據(jù)寫入PCF8563相應(yīng)寄存器
- }
- /**************************************************
- 函數(shù)名稱:rtc_init()
- 函數(shù)功能:時(shí)鐘初始化
- ***************************************************/
- void rtc_init() //時(shí)鐘初始化
- {
- set_rtc(); //將預(yù)設(shè)的時(shí)間進(jìn)行DEC->BCD轉(zhuǎn)換
- ISendByte(0x00,0x00);
- }
- /**************************************************
- 函數(shù)名稱:ead_rtc()
- 函數(shù)功能:讀時(shí)鐘函數(shù),將讀出的數(shù)據(jù)存入tmpdate緩存數(shù)組中
- ***************************************************/
- void read_rtc() //讀時(shí)鐘函數(shù),將讀出的數(shù)據(jù)存入tmpdate緩存數(shù)組中
- {
- IRcvStr(0x02,tmpdate,7);
- tmpdate[0]=tmpdate[0]&0x7f; //秒
- tmpdate[1]=tmpdate[1]&0x7f; //分
- tmpdate[2]=tmpdate[2]&0x3f; //時(shí)
- tmpdate[3]=tmpdate[3]&0x3f; //日
- tmpdate[4]=tmpdate[4]&0x07; //星期
- tmpdate[5]=tmpdate[5]&0x0f; //月
- tmpdate[6]=tmpdate[6]&0xff; //年
-
- }
- /**********************主函數(shù)*******************************************/
- void main()
- {
- init_lcd1602(); //1602初始化
- // rtc_init(); //時(shí)間初始化
-
- while(1)
- {
- read_rtc(); //讀時(shí)間并處理
- write_firstline(5,tmpdate[6]); //顯示年
- write_com(0x80+5);
-
- write_firstline(8,tmpdate[5]); //顯示月
- write_com(0x80+8);
-
- write_firstline(11,tmpdate[3]); //顯示日
- write_com(0x80+11);
-
- write_firstline(14,tmpdate[4]); //顯示星期
- write_com(0x80+14);
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
pcf8563 lcd1602.zip
(35.86 KB, 下載次數(shù): 85)
2018-7-7 20:22 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|