中断分为外部中断、定时器中断、和串口中断,在TCON中控制中断的各个位,EA为总的中断开关,打开响应的开关以后就能够使得对应的中断开启,在写中断的时候,还要注意中断的标号,每个串口对应不同的中断。
程序部分:
/*程序实现的内容是:按键按一下数字跳动一下,到十截止。*/
#include<reg51.h>
unsigned char s[] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
sbit P32 = P3^2;
int num = 0;
void display()
{
P2= s[num];
}
void initzhongduan()
{
IT0= 1;
EX0= 1;
EA= 1;
P32= 1;
}
void main()
{
initzhongduan();
while(1)
{
display();
}
}
void zhongduan() interrupt 0
{
num++;
if(num==10)
{
num= 0;
}
}