请单片机达人帮忙看下以下程序,硬件仿真时经常性发生死机,望指点迷津,还有在执行键值中断扫描后返回主函数时(如在执行当键值=0XF7这条指令后执行的循环点亮LED子程序时),我想让它在执行中断程序后不再返回该子程序,不知如何实现?
#include <reg52.h> #include <absacc.h> #define uint unsigned int #define uchar unsigned char
sbit l0=P0^0; sbit l1=P0^1; sbit l2=P0^2; sbit l3=P0^3; sbit an=P3^7; sbit beer=P3^2;
uchar jianzhi; uchar huayang[]={0xfe,0xfd,0xfb,0xf7,0xef}; //定义点亮LED花样 uint a,b=0; uint j; uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //定义数值显示码
//////////延时程序(由i值确认延时长度)/////////////////// void delay(uint i) { /*void mDelay(unsigned int DelayTime) { unsigned int j=0; for(;DelayTime>0;DelayTime--) { for(j=0;j<125;j++) {;} }} */
for(;i>0;i--) { for(j=0;j<125;j++){;} } }
//BEER响声处理程序 void beer0(void) { beer=0; delay(5); beer=1; delay(5); beer=0; delay(5); beer=1; delay(5); beer=0; delay(5); beer=1; }
///////////////主函数///////////////////////////// void main(void)
{ an=0; EA=1; IT0=1; ET0=1; TMOD=0x01;//方式1,计时10ms TH0=-4000/256; TL0=-4000%256; TR0=1;
/*键值处理程序*/ while(1) { if(jianzhi==0xfe){ b++; if(b==10) { b=0; } an=1; P1=0xfe; P0=table; P0=~P0;
while(jianzhi==0xfe) { ; } } //P0=0xfe;
/* if(P2_2==0) { delay(20); //延时防抖 if(P2_2==0) //继续判P2.0 { second++; //秒加一位 if(second==60) { second=0; } dispbuf[3]=second%10; //显示第七位为秒个位数 dispbuf[2]=second/10;//第六位为秒十位数 while(P2_2==0) { ; } } }*/
else if(jianzhi==0xfd) { P1=0xff; an=0; P0=0xfd; } else if(jianzhi==0xfb) { P1=0xff; an=0; P0=0xfb; } else if(jianzhi==0xf7) //当键值等于0XF7时 { P1=0xff; an=0; do { for(a=0;a<5;a++) { //if(jianzhi!=0xf7)break; delay(500); //延时半秒 P0=huayang[a]; //花样处理值送P0 } }while(jianzhi==0xf7); //循环执行 } }
/* switch(jianzhi) { case(0xfe):{P0=0xfe;}break; case(0xfd):{P0=0xfd;}break; case(0xfb):{P0=0xfb;}break; case(0xf7):{ for(a=0;a<5;a++) { delay(500); P0=huayang[a]; } }break; default:break; }
*/
}
/////定时中断扫描键盘程序 //// void timer0(void) interrupt 1 using 1 {
if(P2==0xff)return; delay(10); if(P2!=0xff) { delay(10); if(P2==0xfe) { delay(10); beer0(); jianzhi=P2; delay(10); while(P2==0xfe) { ; } } else if(P2==0xfd) { delay(10); beer0(); jianzhi=P2; delay(10); while(P2==0xfd) { ; } } else if(P2==0xfb) { delay(10); beer0(); jianzhi=P2; delay(10); while(P2==0xfb) { ; }
} else if(P2==0xf7) { delay(10); beer0(); jianzhi=P2; delay(10); while(P2==0xf7) { ; } } }return;
}
|