掉電保護24c02_第1頁
掉電保護24c02_第2頁
掉電保護24c02_第3頁
全文預覽已結束

下載本文檔

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

文檔簡介

1、#include #include #include unsigned char code table= 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x40;unsigned char sec; /定義計數值,每過1 秒,sec加1unsigned int tcnt; /定時中斷次數bit write=0; /寫24C08 的標志;sbit gewei=P25; /個位選通定義sbit shiwei=P24; /十位選通定義/24C08 讀寫驅動程序/sbit scl=P34; / 24c08 SCLsbit sda=P35; / 24

2、c08 SDAvoid delay1(unsigned char x) unsigned int i;for(i=0;ix;i+);void flash() ; ; void x24c08_init() /24c08 初始化子程序scl=1; flash(); sda=1; flash();void start() /啟動(I方C)總線sda=1; flash(); scl=1; flash(); sda=0; flash(); scl=0; flash();void stop() /停止(I方C)總線sda=0; flash(); scl=1; flash(); sda=1; flash()

3、;void writex(unsigned char j) /寫一個字節(jié) unsigned char i,temp;temp=j;for (i=0;i8;i+)temp=temp1; scl=0; flash(); sda=CY; flash(); scl=1; flash();scl=0; flash(); sda=1; flash();unsigned char readx() /讀一個字節(jié)unsigned char i,j,k=0;scl=0; flash(); sda=1;for (i=0;i8;i+)flash(); scl=1; flash();if (sda=1) j=1;els

4、e j=0;k=(k1)|j;scl=0;flash(); return(k);void clock() /(I方C)線時鐘unsigned char i=0;scl=1; flash();while (sda=1)&(i255)i+;scl=0; flash();/從24c02 的地址address 中讀取一個字節(jié)數據/unsigned char x24c08_read(unsigned char address)unsigned char i;start(); writex(0xa0);clock(); writex(address);clock(); start();writex(0xa

5、1); clock();i=readx(); stop();delay1(10);return(i);/向24c02 的address 地址中寫入一字節(jié)數據info/void x24c08_write(unsigned char address,unsigned char info)EA=0;start(); writex(0xa0);clock(); writex(address);clock(); writex(info);clock(); stop();EA=1;delay1(50);/24C08 讀寫驅動程序完/void Delay(unsigned int tc) /延時程序whil

6、e( tc != 0 )unsigned int i;for(i=0; i100; i+);tc-;void LED() /LED顯示函數shiwei=0; P0=tablesec/10; Delay(8); shiwei=1;gewei=0; P0=tablesec%10; Delay(5); gewei=1;void t0(void) interrupt 1 using 0 /定時中斷服務函數TH0=(65536-50000)/256; /對TH0 TL0 賦值TL0=(65536-50000)%256; /重裝計數初值tcnt+; /每過250ust tcnt 加一if(tcnt=20) /計滿20次(1 秒)時tcnt=0; /重新再計sec+;write=1; /1 秒寫一次24C08if(sec=100) /定時100 秒,在從零開始計時sec=0;void main(void)TMOD=0x01; /定時器工作在方式1ET0=1; EA=1;x24c08_init(); /初始化24C08sec=x24c08_read(2);/讀出保存的數據賦于secTH0=(65536-50000)/256; /對TH0 TL0 賦值TL0=(65536-50000)%256; /使定時器0.05 秒

溫馨提示

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

評論

0/150

提交評論