第5次上機實驗 PCF8563.doc_第1頁
第5次上機實驗 PCF8563.doc_第2頁
第5次上機實驗 PCF8563.doc_第3頁
第5次上機實驗 PCF8563.doc_第4頁
第5次上機實驗 PCF8563.doc_第5頁
已閱讀5頁,還剩1頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

第五次實驗main.c#include#include#includevoid delay_1s(unsigned int);void separate(unsigned char sec,min,hou);unsigned char j0,j1,j2=17,j3;j4,j5=17,j6,j7;main() unsigned LastSec; delay_1s(2); Init_pcf8563(); /初始化時間 write_time_8563(); /初始化時間 while(1) read_time_8563(); if(sec!=LastSec)/秒變化時,才進行顯示 LastSec=sec;/保存現在的秒值,準備與下一個讀出的秒比較 separate(sec,min,hou); display(j0,j1,j2,j3,j4,j5,j6,j7); delay_1s(10000); void separate(unsigned char sec,min,hou) j0=sec%10; j1=sec/10; j3=min%10; j4=min/10; j6=hou%10; j7=hou/10;/=void delay_1s(unsigned int x ) while(x-);Display.hvoid shift(unsigned char);void display(unsigned char j0,j1,j2,j3,j4,j5,j6,j7);sbit sda=P02;sbit scl=P03;code char led_code19= /display code0x11,0xd7,0x32,0x92,0xd4,/0,1,2,3,40x98,0x18,0xd3,0x10,0x90,/5,6,7,8,90x50,0x1c,0x39,0x16,0x38,/a,b,c,d,e0x78,0xfe,0xef,0xff / f- dot darkf; Display.c#include void display(unsigned char j0,j1,j2,j3,j4,j5,j6,j7)shift(j0);shift(j1);shift(j2);shift(j3);shift(j4);shift(j5);shift(j6);shift(j7);void shift(unsigned char n) unsigned char m,i; m=led_coden; scl=0; for(i=0;i8;i+) if (m & 0x80) sda=1; else sda=0; scl=1; scl=0; m0;i-) if(dat&0x80)sda_8563 = 1; else sda_8563 = 0; scl_8563 = 1; scl_8563 = 0; dat0;i-) scl_8563 = 1; dat=dat1; if(sda_8563)dat|=0x01; scl_8563 = 0; sda_8563 = 1;scl_8563 = 1;scl_8563 = 0;return(dat);void Init_pcf8563(void)/初始化pcf8563 unsigned char i,j;for(i=8;i8;i-) if(i=4)j=(timei)&0x07; else j=(timei/10)4 )&0xf0 )|(timei%10)&0x0f ); start(); writebyte_8563(0xa2); /選擇寫8563芯片 writebyte_8563(i+0x02); /寫地址 writebyte_8563(j); /寫數據 stop(); void read_time_8563(void) /讀日期unsigned char i;for(i=0;i4&0x0f)*10+(sec&0x0f);min=(min&0xf0)4&0x0f)*10+(min&0x0f);hou=(hou&0xf0)4&0x0f)*10+(hou&0x0f);day=(day&0xf0)4&0x0f)*10+(day&0x0f);mon=(mon&0xf0)4&0x0f)*10+(mon&0x0f);year=(year&0xf0)4&0x0f)*10+(year&0x0f);/BCD碼轉換成10進制數void write_time_8563(void) /寫日期start(); /寫年份writebyte_8563(0xa2);writebyte_8563(0x08);writebyte_8563(year);stop();start(); /寫月份writebyte_8563(0xa2);writebyte_8563(0x07);writebyte_8563(mon);stop();start(); /寫日writebyte_8563(0xa2);writebyte_8563(0x05);writebyte_8563(day);stop();start(); /寫時writebyte_8563(0xa2);writebyte_8563(0x04);writebyte_8563(hou);stop(); start();/寫分writebyte_8563(0xa2);writebyte_8563(0x03);writebyte_8563(min);stop();start(); /寫秒writebyte_8563(0xa2);writebyte_8

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論