|
发表于 2010-5-31 12:28:49
|
显示全部楼层
我先把自己写的有问题程序
#include <reg52.h>
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
unsigned char code table[]={7,6,5,4,3,2,1,0};
unsigned char second;
unsigned char keycnt;
unsigned int tcnt,tt;
sbit P32=P3^2;
void delay()
{
for(tt=0;tt<=1000;tt++);
}
void main()
{
unsigned char i,j;
TMOD=0x02;
ET0=1;
EA=1;
second=0;
P0=dispcode[second/10];
P2=table[0];
delay();
P0=dispcode[second%10];
P2=table[1];
delay();
while(1)
{
if(P32==0)
{
for(i=20;i>0;i--)
for(j=248;j>0;j--);
if(P32==0)
{
keycnt++;
switch(keycnt)
{
case 1:
TH0=0x06;
TL0=0x06;
TR0=1;
break;
case 2:
TR0=0;
break;
case 3:
keycnt=0;
second=0;
P0=dispcode[second/10];
P2=table[0];
delay();
P0=dispcode[second%10];
P2=table[1];
delay();
break;
}
while(P32==0);
}
}
}
}
void t0(void) interrupt 1 using 0
{
tcnt++;
if(tcnt==400)
{
tcnt=0;
second++;
if(second==100)
{
second=0;
}
P0=dispcode[second/10];
P2=table[0];
delay();
P0=dispcode[second%10];
P2=table[1];
delay();
}
} |
|