请教一下,为什么我的中断进入不了,利用中断查询扩展法
时间:10-02
整理:3721RD
点击:
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar Count=0;
uchar Sec=0;
uchar bfled;
uchar bfshuma;
sbit K3=P3^2; //紧急情况
sbit K2=P3^6; //B车道控制
sbit K1=P3^7; //A车道控制
void outside_int() //外部中断0,1的初始化
{
EX0 = 1;
IT0 = 1;
EX1 = 1;
IT1 = 1;
EA = 1;
}
void delay(uint del) //延时子程序10ms
{
uint i,j;
for(i=0; i<del; i++)
for(j=0; j<1827; j++)
;
}
void key1() //A道放行5秒
{
bfled=P0;
bfshuma=P2;
Sec=5;
while(Sec!=0)
{
P0=0xdb;
P2=table[Sec];
}
P0=bfled;
P2=bfshuma;
}
void key2() //B道放行5秒
{
bfled=P0;
bfshuma=P2;
Sec=5;
while(Sec!=0)
{
P0=0xbd;
P2=table[Sec];
}
P0=bfled;
P2=bfshuma;
}
void key3() //紧急情况,所有车道禁止通行,紧急车辆通行3秒
{
bfled=P0;
bfshuma=P2;
Sec=3;
while(Sec!=0)
{
P0=0xf6;
P2=table[Sec];
}
P0=bfled;
P2=bfshuma;
}
void key() //按键扫描
{
if(K1==0)
{
delay(1);
if(K1==0)
{
while(K1==0);
key1();
}
}
if(K2==0)
{
delay(1);
if(K2==0)
{
while(K2==0);
key2();
}
}
if(K3==0)
{
delay(1);
if(K3==0)
{
while(K3==0);
key3();
}
}
}
void Time0_Init(void)
{
TMOD = 0x01;
TH0 = 0x4c;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
}
void Time0_Int(void) interrupt 1 //50ms*20=1s
{
TH0 = 0x4c;
TL0 = 0x00;
Count++;
if(Count == 20)
{
Count = 0;
Sec--;
}
}
void display()
{
uchar i;
Sec=9;
while(Sec!=0)
{
P0=0xf3;
P1=table[Sec];
}
Sec=3;
while(Sec!=0)
{
P0=0xf5;
P1=table[Sec];
}
Sec=9;
while(Sec!=0)
{
P0=0xde;
P1=table[Sec];
}
Sec=3;
while(Sec!=0)
{
P0=0xee;
P1=table[Sec];
}
}
void main() //主函数
{
Time0_Init();
while(1)
{
key();
display();
}
}
#define uint unsigned int
#define uchar unsigned char
uchar code table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar Count=0;
uchar Sec=0;
uchar bfled;
uchar bfshuma;
sbit K3=P3^2; //紧急情况
sbit K2=P3^6; //B车道控制
sbit K1=P3^7; //A车道控制
void outside_int() //外部中断0,1的初始化
{
EX0 = 1;
IT0 = 1;
EX1 = 1;
IT1 = 1;
EA = 1;
}
void delay(uint del) //延时子程序10ms
{
uint i,j;
for(i=0; i<del; i++)
for(j=0; j<1827; j++)
;
}
void key1() //A道放行5秒
{
bfled=P0;
bfshuma=P2;
Sec=5;
while(Sec!=0)
{
P0=0xdb;
P2=table[Sec];
}
P0=bfled;
P2=bfshuma;
}
void key2() //B道放行5秒
{
bfled=P0;
bfshuma=P2;
Sec=5;
while(Sec!=0)
{
P0=0xbd;
P2=table[Sec];
}
P0=bfled;
P2=bfshuma;
}
void key3() //紧急情况,所有车道禁止通行,紧急车辆通行3秒
{
bfled=P0;
bfshuma=P2;
Sec=3;
while(Sec!=0)
{
P0=0xf6;
P2=table[Sec];
}
P0=bfled;
P2=bfshuma;
}
void key() //按键扫描
{
if(K1==0)
{
delay(1);
if(K1==0)
{
while(K1==0);
key1();
}
}
if(K2==0)
{
delay(1);
if(K2==0)
{
while(K2==0);
key2();
}
}
if(K3==0)
{
delay(1);
if(K3==0)
{
while(K3==0);
key3();
}
}
}
void Time0_Init(void)
{
TMOD = 0x01;
TH0 = 0x4c;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
}
void Time0_Int(void) interrupt 1 //50ms*20=1s
{
TH0 = 0x4c;
TL0 = 0x00;
Count++;
if(Count == 20)
{
Count = 0;
Sec--;
}
}
void display()
{
uchar i;
Sec=9;
while(Sec!=0)
{
P0=0xf3;
P1=table[Sec];
}
Sec=3;
while(Sec!=0)
{
P0=0xf5;
P1=table[Sec];
}
Sec=9;
while(Sec!=0)
{
P0=0xde;
P1=table[Sec];
}
Sec=3;
while(Sec!=0)
{
P0=0xee;
P1=table[Sec];
}
}
void main() //主函数
{
Time0_Init();
while(1)
{
key();
display();
}
}
你是做交通灯的吧,加我详谈qq1552985179