#include "reg52.h"
#include"i2c.h"
typedef unsigned int u16;
typedef unsigned char u8;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
sbit led=P2^7;
int num,numt,i;
u8 disp[4];
u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(u16 i)
{
while(i--);
}
void datapros()
{
disp[0]=smgduan[num/1000];
disp[1]=smgduan[num%1000/100];
disp[2]=smgduan[num%1000%100/10];
disp[3]=smgduan[num%1000%100%10];
At24c02Write(1,num);
}
void DigDisplay()
{
u8 i;
for(i=0;i<4;i++)
{
switch(i)
{
case(0):
LSA=0;LSB=0;LSC=0; break;
case(1):
LSA=1;LSB=0;LSC=0; break;
case(2):
LSA=0;LSB=1;LSC=0; break;
case(3):
LSA=1;LSB=1;LSC=0; break;
}
P0=disp[3-i];
delay(100);
P0=0x00;
}
}
void main()
{
{
num=9999;
numt=0;
TMOD=0x01;
EA=1;
ET0=1;
TH0=0X0fc;
TL1=0X50;
TR0=1;
}
num=At24c02Read(1);
while(1)
{
datapros();
DigDisplay();
}
}
void T0time() interrupt 1
{
i=0;
numt++;
if(numt==16)
{
numt=0;
num--;
if(num==0)
num=0;
}
if(num<i)
led=0;
if(num<i)
num=0;
} |
|