#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code segcode[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
uchar count;
uchar opcode=0;
void delay(uint num)
{
uint i,j;
for(i=0;i<num;i++)
for(j=0;j<330;j++);
}
void main()
{
TMOD=0x01;
TH0=(65535-2000)/256;
TL0=(65535-2000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
for(count=0;count<100;count++)
{
delay(500);
}
}
}
void timer0() interrupt 1
{
TH0=(65535-2000)/256;
TL0=(65535-2000)%256;
switch(opcode)
{
case 1:P1=0x01;
P3=segcode[count%10];
opcode=2;
break;
case 2:P1=0x02;
P3=segcode[count/10];
opcode=1;
break;
}
}
|