基于24C08帶掉電記憶功能的兩路電子跑表
void display_sec(uchar add,uchar dat)
{
uchar a,b;
a=dat/10;
b=dat%10;
write_com(0x80+add);
write_dat(0x30+a);
write_dat(0x30+b);
write_dat(.);
}本文引用地址:http://m.butianyuan.cn/article/201612/324662.htm
void display_sec1(uchar add,uchar dat)
{
uchar a,b;
a=dat/10;
b=dat%10;
write_com(0x80+0x40+add);
write_dat(0x30+a);
write_dat(0x30+b);
write_dat(.);
}
void display_min(uchar add,uchar dat)
{
uchar a,b;
a=dat/10;
b=dat%10;
write_com(0x80+add);
write_dat(0x30+a);
write_dat(0x30+b);
write_dat(:);
}
void display_min1(uchar add,uchar dat)
{
uchar a,b;
a=dat/10;
b=dat%10;
write_com(0x80+0x40+add);
write_dat(0x30+a);
write_dat(0x30+b);
write_dat(:);
}
void keyscan()
{
if (start==0)
{
TR0=~TR0;
TR1=~TR1;
}
if(puss==0)
{
delay(30);
while(!puss);
TR0=~TR0;
}
if(puss1==0)
{
delay(30);
while(!puss1);
TR1=~TR1;
}
if(clear==0)
{
delay(30);
while(!clear);
secbf=0;
write_add(0,0);
write_add(0,0);
sec=0;
write_add(1,0);
write_add(1,0);
min=0;
write_add(2,0);
write_add(2,0);
display_secbf(secbf);
display_sec(10,sec);
display_min(7,min);
TR0=0;
secbf1=0;
write_add(10,0);
write_add(10,0);
sec1=0;
write_add(11,0);
write_add(11,0);
min1=0;
write_add(12,0);
write_add(12,0);
display_secbf1(secbf);
display_sec1(10,sec);
display_min1(7,min);
TR1=0;
}
}
void N01()
{
display_secbf(secbf);
display_sec(10,sec);
display_min(7,min);
if(secbf==10)
{
secbf=0; //定時10秒,如果滿了,從0重新開始
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
min=0;
write_add(2,min);
}
write_add(1,sec);
}
if(write_secbf==1)
{
write_secbf=0;
write_add(0,secbf);
}
}
void N02()
{
display_secbf1(secbf1);
display_sec1(10,sec1);
display_min1(7,min1);
if(secbf1==10)
{
secbf1=0; //定時10秒,如果滿了,從0重新開始
sec1++;
if(sec1==60)
{
sec1=0;
min1++;
if(min1==60)
min1=0;
write_add(12,min1);
}
write_add(11,sec1);
}
if(write_secbf1==1)
{
write_secbf1=0;
write_add(10,secbf1);
}
}
void main()
{
gnd=0;
init_1602();
init_24();
secbf=read_add(0);//從地址2中讀出以前保存的數(shù)據(jù)
if(secbf==10) secbf=0;//防止首次讀出錯誤數(shù)據(jù)
sec=read_add(1);
min=read_add(2);
secbf1=read_add(10);//從地址2中讀出以前保存的數(shù)據(jù)
if(secbf1==10) secbf1=0;//防止首次讀出錯誤數(shù)據(jù)
sec1=read_add(11);
min1=read_add(12);
TMOD=0x11;//定時器工作方式1
ET0=1;//開啟 定時器中斷使能
EA=1;//總中斷打開
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TR0=0;//計(jì)時開始
ET1=1;//開啟 定時器中斷使能
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR1=0;//計(jì)時開始
while(1)
{
keyscan();
N01();
N02();
}
}
void t0()interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
tent++;//每中斷一次自加1,每次中斷約50MS
if(tent==20)
{
tent=0;
secbf++;
write_secbf=1;//數(shù)據(jù)更新標(biāo)志位,1/10秒寫一次24C08
}
}
void t1()interrupt 3
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
tent1++;//每中斷一次自加1,每次中斷約50MS
if(tent1==20)
{
tent1=0;
secbf1++;
write_secbf1=1;//數(shù)據(jù)更新標(biāo)志位,1/10秒寫一次24C08
}
}
評論