#include<reg51.h>
unsigned char msec,sec;
void delay(unsigned char i)
{
unsigned int j,k;
for(k=0;k<i;k++)
for(j=0;j<255;j++);
}
void To_INT(void) interrupt 1
{
TH0=0x3c;
TL0=0xb0;
msec++;
if(msec==20)
{
msec=0;
sec++;
if(sec==60)
{
sec=0;
}
}
}
void main()
{
unsigned char led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char temp;
TMOD=0x01;
TH0=0x3C;
TL0=0xb0;
EA=1;
ET0=1;
P3=0xff;
while(1)
{
P2=0x01;
P1=led[sec%10];
delay(10);
P2=0x02;
P1=led[sec/10];
delay(10);
temp=~P3;
temp=temp&0x2c;
if(temp==0x28)
TR0=0;
if(temp==0x24)
TR0=1;
if(temp==0x0c)
{TR0=0;sec=0;msec=0;}
}
}
请哪位高手看下为什么不能实现秒表功能,急用啊,谢谢啦
temp=~P3改为temp=P3;不用取羡缺顷反。
P3.2 扮携停止,P3.3 开始,P3.5 复位。数码兄陆管共阳极,验证通过。
#include<reg51.h>
unsigned char msec,sec;
void delay(unsigned char i)
{
unsigned int j,k;
for(k=0;k<i;k++)
for(j=0;j<255;j++);
}
void To_INT(void) interrupt 1
{
TH0=0x3c;
TL0=0xb0;
msec++;
if(msec==20)
{
msec=0;
sec++;
if(sec==60)
{
sec=0;
}
}
}
void main()
{
unsigned char led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
TMOD=0x01;
TH0=0x3C;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
while(1)
{
P2=0x01;
P1=led[sec%10];
delay(10);
P2=0x02;
P1=led[sec/10];
delay(10);
}
我觉得这槐租孙样就行了吧,其他的程型好序做什么用的铅链?