We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hi,
my code is too long so i put snapshot of my code
#include<..........> . . . . . main() { ...... } void down(void)//down { ES=0; //disable serial ISR timer_flag=0; ph_sensor_error(); motor_direction=ANTI_CLOCK_WISE; while(ph_sensor_down==OFF && timer_flag==0) motor_power=ON; motor_power=OFF; timer_flag=0; ES=1; //enable serial ISR } void ph_sensor_error(void) { TR0 = 1; /* Start Timer 1 Running */ } /*** timer0 interrupt service routine ***/ void timer0_ISR (void) interrupt 1 { TR0 = 0; TF0 = 0; TH0 = 0x00; TL0 = 0x00; counter++; // Increment the overflow count if(counter>=10)//0.71s { TR0 = 0; TF0=0; counter=0; timer_flag=1; } else TR0 = 1; } /*** serial interrupt ***/ void serial_ISR (void) interrupt 4 { unsigned char moh=0; if (RI == 1) { RI = 0; moh=SBUF; if(SBUF==0x31) down(); }*/ }
my problem is when i entered in serial_ISR and the SBUF=0x31 it mean the condition true,when i call down() function i can not from it enter to timer0_ISR never. how can i solve this problem?
My problem solved. I set priority for timer0_ISR higher than serial_ISR so in this case serial_ISR can be interrupted with timer0_ISR. I did it with this code [CODE] IPL0 = 0x02; //make serial interrupt lower priority than timer0 to be can interrupt IPH0 = 0x00; //serial ISR with timer0 ISR [/CODE] i used at89c51ed2.
It may well be better to not call the function from the ISR.
Instead, just have the ISR set a flag and have the main loop test the flag - and call the function, if required.
Better still may be to not even have the ISR do the test: simply have the ISR buffer the received characters, and the main loop "parse" the buffer.
Keil provide examples of buffered, interrupt-driven serial IO...
Here's an example of parsing an input stream: www.visualgps.net/.../NMEAParser.html
It may well be better to not call the function from the ISR. Keep Isrs Short and Simple
forgetting to KISS has been the bane of many projects.
Erik
"forgetting to KISS has been the bane of many projects."
Ah - but it have also given consultants lots of money to buy christmas presents for :)
Including the undesigned