大佬帮我看一下 我这个外部中断的程序要怎么写 抢答按键连接的外部中断
时间:10-02
整理:3721RD
点击:
void main()
{
uchar ret;
WaitTime=EEPROM_Read(0x2000); // 读时间
if((WaitTime==0)||(WaitTime>99))
{
WaitTime=30;
}
AnswerTime=EEPROM_Read(0x2001);
if((AnswerTime==0)||(AnswerTime>99))
{
AnswerTime=15;
}
TimerInit(); 定时器初始化 打开了TR0
Buff[0]=Array[0]; 数码管刷新
Buff[1]=Array[0];
Buff[2]=Array[0];
Buff[3]=Array[0];
while(1)
{
SetTime(); 设置时间
ret=KeyScanf(); 判断提前抢答
if(ret!=0)
{
Buff[0]=Array[ret];
Buff[1]=Array[16];
Buff[2]=Array[12];
Buff[3]=Array[12];
bp=0;
while(1);
}
EX0 = 1;
IT0 = 1;
if(kStart==0) 开始抢答
{
break;
}
}
DelayMs(10);
while(!kStart);
DelayMs(10);
Init_INT0();
Buff[0]=Array[17]; 抢答倒计时
Buff[1]=Array[17];
Buff[2]=Array[WaitTime/10];
Buff[3]=Array[WaitTime%10];
TR1 = 1;
while(1)
{
if(Count>=20)
{
WaitTime--;
Buff[2]=Array[WaitTime/10];
Buff[3]=Array[WaitTime%10];
Count=0;
if(WaitTime<6)
{
bp=0;
DelayMs(100);
bp=1;
}
}
if(WaitTime==0)
{
TR1=0;
bp=0;
Buff[0]=Array[16];
Buff[1]=Array[16];
Buff[2]=Array[16];
Buff[3]=Array[16];
while(1);
}
ret=KeyScanf();
if(ret!=0)
{
break;
}
}
Buff[0]=Array[ret]; 答题时间
Buff[1]=Array[16];
Buff[2]=Array[AnswerTime/10];
Buff[3]=Array[AnswerTime%10];
Count=0;
while(1)
{
if(Count>=20)
{
AnswerTime--;
Buff[2]=Array[AnswerTime/10];
Buff[3]=Array[AnswerTime%10];
Count=0;
if(AnswerTime<6)
{
bp=0;
DelayMs(100);
bp=1;
}
}
if(AnswerTime==0)
{
TR1=0;
bp=0;
Buff[0]=Array[16];
Buff[1]=Array[16];
Buff[2]=Array[16];
Buff[3]=Array[16];
while(1);
}
}
}
void Timer0(void) interrupt 1
{
TH0 = 248;
TL0 = 48;
P0=0x00;
w1=1;
w2=1;
w3=1;
w4=1;
if(ShowID==1)
{
w1=0;
P0=Buff[0];
}
if(ShowID==2)
{
w2=0;
P0=Buff[1];
}
if(ShowID==3)
{
w3=0;
P0=Buff[2];
}
if(ShowID==4)
{
w4=0;
P0=Buff[3];
}
ShowID++;
if(ShowID==5)
ShowID=1;
}
void Timer1(void) interrupt 3
{
TH1 = 60;
TL1 = 176;
Count++;
}
void INT0_ISR(void) interrupt 0
{
EX0 = 0;
}
{
uchar ret;
WaitTime=EEPROM_Read(0x2000); // 读时间
if((WaitTime==0)||(WaitTime>99))
{
WaitTime=30;
}
AnswerTime=EEPROM_Read(0x2001);
if((AnswerTime==0)||(AnswerTime>99))
{
AnswerTime=15;
}
TimerInit(); 定时器初始化 打开了TR0
Buff[0]=Array[0]; 数码管刷新
Buff[1]=Array[0];
Buff[2]=Array[0];
Buff[3]=Array[0];
while(1)
{
SetTime(); 设置时间
ret=KeyScanf(); 判断提前抢答
if(ret!=0)
{
Buff[0]=Array[ret];
Buff[1]=Array[16];
Buff[2]=Array[12];
Buff[3]=Array[12];
bp=0;
while(1);
}
EX0 = 1;
IT0 = 1;
if(kStart==0) 开始抢答
{
break;
}
}
DelayMs(10);
while(!kStart);
DelayMs(10);
Init_INT0();
Buff[0]=Array[17]; 抢答倒计时
Buff[1]=Array[17];
Buff[2]=Array[WaitTime/10];
Buff[3]=Array[WaitTime%10];
TR1 = 1;
while(1)
{
if(Count>=20)
{
WaitTime--;
Buff[2]=Array[WaitTime/10];
Buff[3]=Array[WaitTime%10];
Count=0;
if(WaitTime<6)
{
bp=0;
DelayMs(100);
bp=1;
}
}
if(WaitTime==0)
{
TR1=0;
bp=0;
Buff[0]=Array[16];
Buff[1]=Array[16];
Buff[2]=Array[16];
Buff[3]=Array[16];
while(1);
}
ret=KeyScanf();
if(ret!=0)
{
break;
}
}
Buff[0]=Array[ret]; 答题时间
Buff[1]=Array[16];
Buff[2]=Array[AnswerTime/10];
Buff[3]=Array[AnswerTime%10];
Count=0;
while(1)
{
if(Count>=20)
{
AnswerTime--;
Buff[2]=Array[AnswerTime/10];
Buff[3]=Array[AnswerTime%10];
Count=0;
if(AnswerTime<6)
{
bp=0;
DelayMs(100);
bp=1;
}
}
if(AnswerTime==0)
{
TR1=0;
bp=0;
Buff[0]=Array[16];
Buff[1]=Array[16];
Buff[2]=Array[16];
Buff[3]=Array[16];
while(1);
}
}
}
void Timer0(void) interrupt 1
{
TH0 = 248;
TL0 = 48;
P0=0x00;
w1=1;
w2=1;
w3=1;
w4=1;
if(ShowID==1)
{
w1=0;
P0=Buff[0];
}
if(ShowID==2)
{
w2=0;
P0=Buff[1];
}
if(ShowID==3)
{
w3=0;
P0=Buff[2];
}
if(ShowID==4)
{
w4=0;
P0=Buff[3];
}
ShowID++;
if(ShowID==5)
ShowID=1;
}
void Timer1(void) interrupt 3
{
TH1 = 60;
TL1 = 176;
Count++;
}
void INT0_ISR(void) interrupt 0
{
EX0 = 0;
}
中断里就写按键按下后要做的事情,你的这个问题太笼统了,要做的事情不同,程序的编写也各有不同