|
本人初学单片机,需要用数码管、AT89S51、按键实现一可调时秒表。在调试程序过程中发现,当按键触发外部中断时,会打断显示程序。哪位大侠能给小弟一些指导,不胜感激!(两个数码管)程序如下:
#include
#define uchar unsigned char
sbit p10=P1^0;
sbit p11=P1^1;
sbit p32=P3^2;
sbit p33=P3^3;
uchar n=0,n1=0,n2=0;
uchar m[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay(uchar a)
{
uchar j;
while(a--!=0)
{
for(j=0;j<231;j++);
}
}
void display(uchar b0,uchar b1)
{
p11=0;
P0=m[b0];
delay(5);
p11=1;
p10=0;
P0=m[b1];
delay(5);
p10=1;
}
void Timer0()interrupt 1 using 0
{
TH0=0xb8;
TL0=0x00;
n++;
if(n==100)
{
n=0;
n1++;
if(n1==10)
{
n1=0;
n2++;
if(n2==6)
{
n2=0;
}
}
}
}
uchar i;
void interrupt0()interrupt 0 using 1
{
if(p32==0)
delay(5);
if(p32==0)
{
TR0=0;
EX1=1;
i++;
}
}
void interrupt1()interrupt 2 using 2
{
if(p33==0)
delay(5);
if(p33==0)
{
if(i==1)
{n1++;}
if(i==2)
{n2++;}
if(i==3)
{i=0;
TR0=1;}
}
}
main()
{
TMOD=0x01;
TH0=0xb8;
TL0=0x00;
ET0=1;
EX0=1;
EA=1;
TR0=1;
P1=0xff;
i=0;
while(1)
{
display(n1,n2);
}
}
|
|