Hi, I want to implement following job in C code with Keil C51. (1) jump to a place (function entry) after an interrupt occurs. I know how to implement it in assemble, but I don't know how to implement it in C ? Following is the implementation in assemble, JUMP_HERE: CLR A ... ... Int1: MOV DPTR,#JUMP_HERE PUSH DPL PUSH DPH RETI Does following C code works ? void main() { while(1) { JUMP_HERE: func1(); ... } } void Int0_ISR (void) interrupt 0 using 1 { // C code here .... #pragma asm MOV DPTR,#JUMP_HERE PUSH DPL PUSH DPH #pragma endasm } I know you can only use the goto statement within same function in C. Any idea ? Thanks. Daniel
>1. The ISR recognises the interrupt, and sets >some flag; >2. Code in the "main loop" recognises the >flag, and takes the appropriate action. Hello, A (Andy ?),If my memory is correct. Yes, my code currently works this way. However, to achieve this, there are two requirements: (1) ISR must be short enough, if the egularly interrupt, such as timer interrupt interval is about 10ms, my oppion is ISR should not last over 2ms(20%), 8 ms (80%)leave to main loop. (2) The task(function) is not time critical, but unfortunately, this task is very time critical, you have to serve it within 3-5 ms, my main loop is pseudo-multitasking, some task(function) may be longer than 10ms or even more, if you use strcpy() it is even longer, So when the right function is called, the 3-5 ms is already elapsed. Then, there is another way, use ISR to process this task, however, this task may last one second (worst case), for ISR it is too long, this is why I try to use jump between functions, I am not sure whether this can be achieveable by mixing C and assembler, if not, the only choice is ISR, the cost is it may take about one second, that is trade-off! thanks
"I am not sure whether this can be achieveable by mixing C and assembler" Your basic problem is that labels in the 'C' programming language cannot have global scope; ie, they are never accessible from outside the function in which they are declared. This is defined by the language; nothing specifically to do with Keil - see a 'C' textbook. Therefore, you will have to implement both the ISR and the "target" of the jump in assembler. You might possibly be able to use setjmp and longjmp, but I think these are implemented as functions - so that'd be no good here. :-( http://www.keil.com/support/man/docs/c51/c51_lib_misc.htm Again, this is fundamentally contrary to the principles of 'C' so, if your really must do it, you need to do it in assembler.
SCRAP THE TASK SWITCHER my mathod: Put the time critical "main" portion in an unused ISR Set all "real" ISRs to high priority When the time critical "main" portion is to run set the bit that trigger the "unused" ISR. Erik