二十掉電保護(hù)24c02_第1頁
二十掉電保護(hù)24c02_第2頁
二十掉電保護(hù)24c02_第3頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、#include #include #include unsigned char code table= 0 xc0,0 xf9,0 xa4,0 xb0,0 x99,0 x92, 0 x82,0 xf8,0 x80,0 x90,0 x40; unsigned char sec; /定義計(jì)數(shù)值,每過1 秒,sec加1 unsigned int tcnt; /定時(shí)中斷次數(shù) bit write=0; /寫24C08 的標(biāo)志; sbit gewei=P25; /個(gè)位選通定義 sbit shiwei=P24; /十位選通定義 /24C08 讀寫驅(qū)動(dòng)程序/ sbit scl=P34; / 24c08 SC

2、L sbit sda=P35; / 24c08 SDA void 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() /啟動(dòng)(I方C)總線 sda=1; flash(); scl=1; flash(); sda=0; flash(); scl=0; flash(); void stop() /停止(I方C)總線 sda=0; flash();

3、scl=1; flash(); sda=1; flash(); void writex(unsigned char j) /寫一個(gè)字節(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() /讀一個(gè)字節(jié) unsigned char i,j,k=0; scl=0; flash(); sda=1; for (i=0;i8;i+) fl

4、ash(); scl=1; flash(); if (sda=1) j=1; else j=0; k=(k1)|j; scl=0; flash(); return(k); void clock() /(I方C)線時(shí)鐘 unsigned char i=0; scl=1; flash(); while (sda=1) scl=0; flash(); /從24c02 的地址address 中讀取一個(gè)字節(jié)數(shù)據(jù)/ unsigned char x24c08_read(unsigned char address) unsigned char i; start(); writex(0 xa0); clock(

5、); writex(address); clock(); start(); writex(0 xa1); clock(); i=readx(); stop(); delay1(10); return(i); /向24c02 的address 地址中寫入一字節(jié)數(shù)據(jù)info/ void x24c08_write(unsigned char address,unsigned char info) EA=0; start(); writex(0 xa0); clock(); writex(address); clock(); writex(info); clock(); stop(); EA=1; d

6、elay1(50); /24C08 讀寫驅(qū)動(dòng)程序完/ void Delay(unsigned int tc) /延時(shí)程序 while( tc != 0 ) unsigned int i; for(i=0; i100; i+); tc-; void LED() /LED顯示函數(shù) 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 /定時(shí)中斷服務(wù)函數(shù) TH0=(65536-50000)/256; /對(duì)TH

7、0 TL0 賦值 TL0=(65536-50000)%256; /重裝計(jì)數(shù)初值 tcnt+; /每過250ust tcnt 加一 if(tcnt=20) /計(jì)滿20次(1 秒)時(shí) tcnt=0; /重新再計(jì) sec+; write=1; /1 秒寫一次24C08 if(sec=100) /定時(shí)100 秒,在從零開始計(jì)時(shí) sec=0; void main(void) TMOD=0 x01; /定時(shí)器工作在方式1 ET0=1; EA=1; x24c08_init(); /初始化24C08 sec=x24c08_read(2);/讀出保存的數(shù)據(jù)賦于sec TH0=(65536-50000)/256; /對(duì)TH0 TL0 賦值 TL0=(65536-50000)%256; /使定時(shí)器0.05 秒中

溫馨提示

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

評(píng)論

0/150

提交評(píng)論