at89c51单片机中断程序的调用
#include<reg51.h>#define uchar unsigned char
#define uint unsigned int
//#define _DEVICEFLAG_
sbit key0=P3^2;
sbit key1=P3^3;
sbit key2=P3^4;
sbit key3=P0^3;
sbit b1=P0^4;
sbit k1=P2^4;
sbit k2=P2^3;
sbit k3=P2^2;
sbit k4=P2^1;
sbit k5=P2^0;
void delay_ms (uint z)
{
uint x,y;
for (x=z;x>0;x--)
for (y=110;y>0;y--);
}
void init()
{
TMOD=0x01;
TH0=0xfc;
TL0=0x66;
ET0=1;
TR0=1;
EA=1;
TMOD|=0x01; //定时器T0,工作方式1
TH0=0xC3;
TL0=0xC7; //这两个寄存器存的是计数器的计数开始的值,这两个值累加至溢出后正好是50ms
ET0=1; //使T0中断可以溢出
EA=1; //开启总中断
TF0=0; //溢出位清零
TR0=1; //开启T0
}
uchar ControlFlag=0;
void timer0(void)interrupt 1
{
static uchar i,count=0;
TH0=0xfc;
TL0=0x66;
count++;
if(key0 == 0)
{
#ifndef _DEVICEFLAG_
for(i=0;i<2;i++)
{
delay_ms(100);
}
if(key0 == 0) //按键2
{
ControlFlag = 2;
}
else if(key0 == 1)
{
ControlFlag = 1;
}
#else
if(key0 == 1)
{
ControlFlag = 1;
}
#endif
}
}
//外部中断2服务程序 复位开关2
void timer1(void)interrupt 2
{
static uchar i,count=0;
TH0=0xfc;
TL0=0x66;
count++;
if(key1 == 1)
{
for(i=0;i<2;i++)
{
delay_ms(100);
}
if(key1 == 0)
{
ControlFlag = 6;
}
else if (key1 == 1)
{
ControlFlag = 5;
}
}
}
//外部中断3服务程序 复位开关1
void it_timer3(void)interrupt 3
{
static uchar i,count=0;
// TMOD&=0xF0;
// TH0=0x00;
// TL0=0x00;
// ET0=1;
// EA=1;
// TR0=1;
TH0=0xC3;
TL0=0xC7;
count++;
if(key2 == 1)
{
for(i=0;i<2;i++)
{
delay_ms(100);
}
if(key2 == 0)
{
ControlFlag = 4;
}
else if(key2 == 1)
{
ControlFlag = 3;
}
}
}
main()
{
k1=0;
k2=0;
k3=0;
k4=0;
k5=0;
key3=0;
init();
while(1)
{
#ifndef _DEVICEFLAG_
if((b1==1)||(key3 == 1))
{
k5 = 1;
}
else if ((b1 == 0)&&(key3 == 0))
{
k5 = 0;
}
#endif
/*************************************************************
*************************************************************/
#ifndef _DEVICEFLAG_
switch(ControlFlag)
{
case 1: //机器总开关长按
if(key3 == 0) //服务器+5V为0时
{
if(b1 == 0) //K1断开时
{
k1 = 1;
k4 = 1;
delay_ms(1000);
k4 = 0;
}
else if (b1== 1) //K1闭合时
{
k1 = 0;
}
}
else if(key3 ==1) //服务器+5V为1时
{
if(b1 == 0) //K1断开时
{
k4 =1;
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
k4 = 0;
}
else if(b1 ==1) //K1闭合时
{
k4 = 1;
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
k1= 0;
delay_ms(1000);
k4 = 0;
}
}
ControlFlag = 0;
break;
case 2: //机器总开关短按
if(key3 == 0) //服务器+5V为0时
{
if(b1 ==0) //K1为断开时
{
k1 = 1;
k4 = 1;
delay_ms(1000);
k4 = 0;
}
else if (b1 == 1) //K1为闭合时
{
k4 = 1;
delay_ms(1000);
k4 = 0;
}
}
else if(key3 ==1) //服务器+5V为1时
{
if(b1 == 0) //K1断开时
{
k1 = 1;
}
else if(b1 ==1) //K1闭合时
{
;
}
}
ControlFlag = 0;
break;
case 3: //复位开关1长按
if(b1 == 1) //K1闭合时
{
k2 = 1;
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
k2 = 0;
}
ControlFlag = 0;
break;
case 4: //复位开关1短按
if(b1 == 1) //K1闭合时
{
k1 = 0;
delay_ms(1000);
k1 = 1;
}
ControlFlag = 0;
break;
case 5: //复位开关2长按
if(key3== 1)
{
k3= 1;
delay_ms(1000);
k3 = 0;
}
ControlFlag = 0;
break;
case 6: //复位开关2短按
if(key3 == 1)
{
k3 = 1;
delay_ms(1000);
k3 = 0;
}
ControlFlag = 0;
break;
#endif
default:
break;
}
delay_ms(10);
}
}
为什么我的中断只有第一个被调用了,求教