|
#define uint unsigned int
#define uchar unsigned char
unsigned char timer1,num,i,k;
sbit PWM=P1^7;
uchar code LEDData[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
sbit OE =P1^0;
sbit EOC=P1^1;
sbit ST=P1^2;
sbit CLK=P1^3;
void DelayMS(uint ms)
{
uchar j;
while(ms--)
{
for(j=0;j<120;j++);
}
}
void system_Ini()
{
TMOD|=0x11;
TH1=0xfe;//11.0592
TL1=0x33;
IE=0x8a;
TR1=1;
}
void deal()
{
if(k<235&&k>188)
{
i=20;
DelayMS(5);
}
if(k<=180)
{
i=0;
DelayMS(5);
}
if(250>k&&k>=235)
{
i=60;
DelayMS(5);
}
if(k>=250)
{
i=80;
DelayMS(5);
}
}
void Display_Result(uchar d)
{
P2=0x06;
P0=LEDData[d%10];
DelayMS(5);
P2=0x05;
P0=LEDData[d%100/10];
DelayMS(5);
P2=0x03;
P0=LEDData[d/100];
DelayMS(5);
}
void main()
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
IE =0x82;
TR0=1;
P1=0x3f;
system_Ini();
while(1)
{
ST=0;
ST=1;
ST=0;
while(EOC==0);
OE=1;
Display_Result(P3);
k=P3;
OE=0;
deal();
if(timer1>100)timer1=0;
if(timer1
else PWM=1;
}
}
void Timer0_INT()interrupt 1
{
CLK=!CLK;
}
void T1zd(void)interrupt 3
{
TH1=0xfe;
TL1=0x33;
num++;
if(num==10)
{
num==0;
timer1++;
}
}
|
|