sbit S1=P2^0;
这是什么意思,是按键在P2.0引脚上吗,就是你说的:
按一下按键启动外部中断的那个按键吗?
要是的话,这个按键要接在P3.2引脚上,那才是外部中断INT0的引脚。而且是不用定义的。
程序也有问题。
修改后的程序
#include
#define uchar unsigned char
#define uint unsigned int
//sbit S1=P2^0; //这行不用写
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8E};
uchar t;
void init()
{
EX0=1;
IT0=1; //这是IT0=1,是下降沿中断
EA=1;
}
//用不着延时子程序
/*
void delay(uint z)
{
uint t1,y;
for(t1=z;t1>0;t1--)
for(y=110;y>0;y--);
}
*/
void main()
{
init();
P1=0xff; //这行与数码管显示无关
t=0; //在这写初值
while(1)
{
P0=tab[t];
}
}
void int0() interrupt 0 //外部中断INT0,这个中断号是0
{
t++; //这么写比较好
if(t>15)t=0; //一位数码管,最大只能显示到F
}
仿真图如下