資源簡介
定時器定時顯示時間并將數據存儲,可以應對斷電數據丟失

代碼片段和文件信息
??//////////////////////////////////////////////
??///程序功能:數碼管顯示?采用24c02?存儲?
??///////掉電后上電能從掉電處顯示
??/////////////////////////////////////////////////
#include
#define?uchar?unsigned?char
sbit?sda=P2^0;
sbit?scl=P2^1;
uchar?aa=0;
sbit?led2=?P2^7;
sbit?led1=?P2^6;
sbit?led4=?P2^5;
sbit?led3=?P2^4;
unsigned?char?const?table[]={0x280xEB0x320xA20xE10xA40x240xEA0x200xA00xFF};
uchar??table1[]={00};
uchar??table2[]={00};
uchar?ashushu1shu2shu3flag=0;
void?delay1(uchar?x)
{
uchar?ab;
for(a=x;a>0;a--)
?//?for(c=100;c>0;c--);
?for(b=100;b>0;b--);
}?
void?delay()
{?;;}
void?start()??//開始信號
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
void?stop()???//停止
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
void?respons()??//應答
{
uchar?i;
scl=1;
delay();
while((sda==1)&&(i<250))i++;
scl=0;
delay();
}
void?init()
{
sda=1;
delay();
scl=1;
delay();
}
?void?write_byte(uchar?date)
{
uchar?itemp;
temp=date;
for(i=0;i<8;i++)
{ scl=0;
????delay();
temp=temp<<1;
sda=CY;
delay();
scl=1;
delay();
}
scl=0;
delay();
sda=1;
delay();
}?
uchar?read_byte()
{
uchar?ik;
for(i=0;i<8;i++)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
return?k;
}
void?write_add(uchar?addressuchar?date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
}
uchar?read_add(uchar?address)
{
uchar?date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return?date;
}??
void?time0_init()
{
?TMOD?|=?0x01; ??//使用模式1,16位定時器,使用“|“符號可以在使用多個定時器時不受影響 ?????
?TH0=(65536-50000)/256; ??????
?TL0=(65536-50000)%256;
?ET0=1;???????????//定時器中斷打開
?TR0=1;???????????//定時器開關打開
??EA=1;????????????//總中斷打開
}
?void?time0()?interrupt?1
?{
???TH0=(65536-50000)/256; ??????
???TL0=(65536-50000)%256;
aa++;
????? ? if(aa==20)
{
aa=0;
shu++;
shu2++;
??flag++;
if(shu==10)?
shu=0;
if(shu2=9)
shu2=0; ?
}
?
?}
?void?disp() ???///數碼管掃描
{ ????
?shu1=read_add(4);
?????table1[0]=shu1/10;
?table1[1]?=shu1%10;
led2=0;
P0=table[table1[0]]?;
delay1(11);
led2=1;
?
led1=0;
????P0=table[table1[1]]?;
delay1(11);
led1=1?;
?shu3=read_add(5);
?? ???????table2[0]=shu3/10;
???????table2[1]?=shu3%10;
led4=0;
P0=table[table2[0]]?;
delay1(11);
led4=1;
?
led3=0;
????? P0=table[table2[1]]?;
delay1(11);
led3=1?;?
}
void?main()
{ // uchar?date?;
??init();
??????time0_init(); ??
??? ?shu=read_add(4);
?shu2=read_add(5);?
while(1)?
{?? ?
????if(flag==1)
???{
??? flag=0;
?write_add(4shu);
?delay1(40);
?write_add(5shu2);??
???}? ? ?
?? disp(); ??? ?
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9920??2011-12-05?22:16??I2C-shu?ma?guan\1
?????文件???????3095??2011-12-05?22:15??I2C-shu?ma?guan\1.c
?????文件???????1823??2011-12-05?22:16??I2C-shu?ma?guan\1.hex
?????文件?????????34??2011-12-05?22:16??I2C-shu?ma?guan\1.lnp
?????文件???????8773??2011-12-05?22:16??I2C-shu?ma?guan\1.LST
?????文件??????14358??2011-12-05?22:16??I2C-shu?ma?guan\1.M51
?????文件??????11539??2011-12-05?22:16??I2C-shu?ma?guan\1.OBJ
?????文件???????1565??2011-12-05?21:22??I2C-shu?ma?guan\1.plg
?????文件??????64966??2011-11-28?16:53??I2C-shu?ma?guan\1.uvopt
?????文件??????13228??2011-11-08?17:30??I2C-shu?ma?guan\1.uvproj
?????文件??????65598??2011-11-10?18:08??I2C-shu?ma?guan\1_uvopt.bak
?????文件??????13217??2011-09-08?11:57??I2C-shu?ma?guan\1_uvproj.bak
?????目錄??????????0??2011-12-10?08:50??I2C-shu?ma?guan
-----------?---------??----------?-----??----
???????????????208116????????????????????13
- 上一篇:OsgQt已經編譯好的版本
- 下一篇:小環天線計算軟件
評論
共有 條評論