完整代碼如下。還望各位知道的告知小弟一聲是什么原因。
普中的板子
#include <REGX52.H>
sbit L1=P3^1;
sbit L2=P3^0;
unsigned char t_005s;
unsigned char t_s;
unsigned char t_m;
//==============================
void delay(unsigned int j)
{
while(j--);
}
unsigned char code smg_duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};
unsigned char code smg_wei[]={0x00,0x04,0x08,0x0c,0x10,0x14,0x18,0x1c};
void display()
{
P2=smg_wei[0];
//delay(1000);
P0=smg_duan[t_005s%10];
delay(100);
P2=smg_wei[1];
//delay(1000);
P0=smg_duan[t_005s/10];
delay(100);
P2=smg_wei[2];
//delay(1000);
P0=smg_duan[16];
delay(100);
P2=smg_wei[3];
//delay(1000);
P0=smg_duan[t_s%10];
delay(100);
P2=smg_wei[4];
//delay(1000);
P0=smg_duan[t_s/10];
delay(100);
P2=smg_wei[5];
//delay(1000);
P0=smg_duan[16];
delay(100);
P2=smg_wei[6];
//delay(1000);
P0=smg_duan[t_m%10];
delay(100);
P2=smg_wei[7];
//delay(1000);
P0=smg_duan[t_m/10];
delay(100);
}
//=============================
void InitTimer0()
{
TMOD=0x01;
TH1=(65535-50000)/256;
TH1=(65535-50000)%256;
ET0=1;
EA=1;
TR0=1;
}
void ServiceTimer0() interrupt 1
{
TH1=(65535-50000)/256;
TH1=(65535-50000)%256;
t_005s++;
if(t_005s==20)
{
t_s++;
t_005s=0;
if(t_s==60)
{
t_m++;
t_s=0;
}
if(t_m==99)
{
t_m=0;
}
}
}
//=============================
void Scnkey()
{
if (L1==0)
{
delay(500);
if(L1==0)
{
TR0=~TR0;
}
while(L1==0)
{
display();
}
}
if (L2==0)
{
InitTimer0();
delay(500);
if(L2==0)
{
t_005s=0;
t_s=0;
t_m=0;
}
while(L2==0)
{
display();
}
}
}
void main()
{
while(1)
{
Scnkey();
display();
}
}
|