#include
typedef unsigned int uint;
typedef unsigned char uchar;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//送给P3段码
uchar code table1[]={0xe3,0xe7,0xeb,0xef,0xf3,0xf7,0xfb,0xff}; //送给P2 位码
uchar no1,no2,no3,i;
***it duan=P1^0;
uchar temp;
void delay(uchar);
void display(uchar) ;
void init() ;
void main()
{
init(); //初始化函数
while(1) //主循环
{
if(no1==20)
{
no1=0;
temp=temp++;
if(temp==255) //0加到255??可惜一直显示0 ?????
temp=0;
}
display(temp);
}
}
void timer0() interrupt 1
{
TH0=0xec;
TL0=0x77; //1ms
no1++;
}
void timer1() interrupt 3
{
TH1=0x3c; //50ms
TL1=0xb0;
no2++;
}
void init()
{
EA=1; P3=0x3f;
ET0=1;ET1=1;
TR0=1;TR1=1;
TMOD=0x11;
TH0=0xec; TH1=0x3c;
TL0=0x77; TL1=0xb0;
no1=no2=no3=0;
temp=123;
duan=1;
i=0;
}
void delay(uchar a)
{ uchar i,j;
for (i=a;i>0;i--)
for(j=110;j>0;j--) ;
}
void display(uchar a)
{ uchar i, j,k,h;
i=a/100; //百位
j=a%100/10; //十位
k=a%10; //各位
for(h=0;h<3;h++)
{
if(no1==1)
{
switch(h)
{
case 0:P2=table1[0],P3=table; break;
case 1:P2=table1[1], P3=table[j];break;
case 2: P2=table1[2], P3=table[k];break;
}
no1=0;
}
}
}
|