#include
#define uchar unsigned char
#define uint unsigned int
#define smg P0
***it led=P2^0;
***it LSC=P2^4;
***it LSB=P2^3;
***it LSA=P2^2;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71} ;
uchar code table1[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71} ;
void delay(uint c);
void display(uchar ,uchar );
uchar num,num1,num2,shi,ge;
void delay(uint c)
{
uint i,j;
for(i=c;i>0;i++)
for(j=110;j>0;j++);
}
void main()
{
num=0;
num2=0;
led=0xfe;
TMOD=0x11; //设置定时器0和1的为工作方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1; //打开总中断;
ET0=1; //打开定时器0中断
ET1=1; //打开定时器1中断
TR0=1; //启动定时器0
TR1=1; //启动定时器1
while(1)
{
if(num2==20) //20*50ms就是1秒
{
num2=0;
num++;
if(num==60) //这个用来送数码管显示,60后清零
num=0;
shi=num/10;
ge=num%10;
}
display(shi,ge);
}
}
void display(uchar shi,uchar ge) //显示子函数用数码管来显示
{
LSC=0;
LSB=0;
LSA=0;
smg=table[ge];
delay(5);
LSC=0;
LSB=0;
LSA=1;
smg=table1[shi];
delay(5);
}
void T0_tiME() interrupt 1 //定时器0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num1++;
if(num1==20)
{
num1=0;
led=~led;
}
}
void T1_TIME() interrupt 3 //定时器1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num2++;
}
3
|
|
|
|