My application is using two interrupts at the same time: serial interrupt and external interrupt (INT0). I seems like they are bugging one another, and sometimes it causes the program to hang. Could some experts in this forum take a look at my code below. Thanks in advance.
void main() IT0 = 1; // Configure interrupt 0 EX0 = 1; //enable INT0 serial_init(); EA = 1; //enable global interrupt while(1) //endless loop --waiting { } /////Setup serial port////////// void serial_init (void) { SCON = 0x50; mode 1: 8-bit UART, TMOD |= 0x20; // timer 1 mode 2: TH1 = 0xf3; // 2400 baud TR1 = 1; // timer1 run ES = 1; // enable serial int PS = 0; //serial int to low-priority } ////////// serial service routine ///// void serial (void) interrupt 4 using 2 { if (RI) { array[index] = SBUF; //Get char RI = 0; //clear flag index++; } if (TI) { TI = 0; SBUF = out; // Transmit char } //////INTO interrupt service routine//////// unsigned char ex0_isr_counter = 0; void ex0_isr (void) interrupt 0 { perform_task1(); //call a function }
My application is using two interrupts at the same time: serial interrupt and external interrupt (INT0) Not really. It has both interrupts enabled, and they may even occur at the same time, but you have only one CPU, so only one interrupt can be in "using" state at any one time. Could some experts in this forum take a look at my code below. Sure we can take a look --- but that doesn't help anybody anything, because that code is much to incomplete to be diagnosed meaningfully. I'll second Erik's remark, though: an interrupt handler that does nothing but call another function is quite certainly a bad idea. The only open question is how bad, and in what way.