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.
In my program, I have a periodic timer interrupt written in C. What I need to achieve is to have the interrupt service routine jump to another function after the interrupt service routine is executed. However, the catch is that the address of the function (which the program is suppose to jump) is stored as a variable (which is not fixed each time the interrupt occurs). Im looking for advice on how can this possibly be done. Thank you.
Yes you are right. The program would not return to 'main'. Instead it will jump from function to function. The purpose of doing this is to create an application which can run different tasks (functions) in a round robin fashion. These tasks can execute forever until they are pre-empted by another task when the timer interrupt sets in. What I describe may sound a bit pointless but it is actually part of an overall effort to build a context switching routine for a very basic real-time OS in 8051.
The purpose of doing this is to create an application which can run different tasks (functions) in a round robin fashion. These tasks can execute forever until they are pre-empted by another task when the timer interrupt sets in. To make a preemptive multi-tasker on an 8051, I don't think you'll get by with writing everything in C. You'll have to code at least some of the core pieces in assembly. You'll have to manipulate the stack on each context switch triggered by the timer interrupt. I would strongly suggest to re-evaluate that plan. Preemptive multitasking is hard to do on an 8051, and harder still if you want to stick with C as the implementation language. Cooperative multitasking may very well be a better choice.