|
怎样把设定的时间存入eeprom中,重新上电后直接调取
[复制链接]
#include
sbit kh=P3^7;//时
sbit km=P3^6;//分
sbit ks=P3^5;//秒
sbit st=P3^4;//开始
sbit b=P2^0;//指示
unsigned char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char i=0,hour=0,minute=0,second=0;
void delayms(unsigned int x)
{
unsigned char a=160;
while(x--)
{
while(a--);
a=160;
}
}
main()
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TMOD=1;
TR0=0;
ET0=1;
EA=1;
while(1)
{
P0=table[hour/10];
P1=~32;
delayms(1);
P1=0xff;
P0=table[hour%10];
P1=~16;
delayms(1);
P1=0xff;
P0=table[minute/10];
P1=~1;
delayms(1);
P1=0xff;
P0=table[minute%10];
P1=~2;
delayms(1);
P1=0xff;
P0=table[second/10];
P1=~4;
delayms(1);
P1=0xff;
P0=table[second%10];
P1=~8;
delayms(1);
P1=0xff;
if(!kh)
{
delayms(200);
hour++;
if(hour>23)
hour=23;
}
else if(!km)
{
delayms(200);
minute++;
if(minute>59)
minute=59;
}
else if(!ks)
{
delayms(200);
second++;
if(second>59)
second=59;
}
if(!st)
{
delayms(200);
TR0=1;
}
if(TR0==1&&hour==0&&minute==0&&second<3)
b=!b;
delayms(1);
}
}
void t0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
i++;
if(i>=20)
{
i=0;
second--;
if(second>59)
{
second=59;
minute--;
if(minute>59)
{
minute=59;
hour--;
if(hour>23)
{
hour=0;
minute=0;
second=0;
TR0=0;
}
}
}
}
}
|
|