#define task1Reset 4
#define task2Reset 7
volatile task1Counter;
volatile task2Counter;
volatile task1Flag;
volatile task2Flag;
void interrupt()
{
TMR0 = <whatever the correct reset value should be>
TMR0IF_bit = 0;
// See if we need to trigger task 1 into action
if( 0 == --task1Counter)
{
task1Flag = 1; // Tell the main loop that task 1 needs to run
task1Counter = task1Reset; // Reset the counter
}
// Similarly, see if we need to trigger task 2 into action
if( 0 == --task2Counter)
{
task2Flag = 1; // Tell the main loop that task 2 needs to run
task2Counter = task2Reset; // Reset the counter
}
}
main()
{
<set up the processor, oscillator etc>
task1Flag = 0;
task1Counter = task1Reset;
task2Flag = 0;
task2Counter = task2Reset;
<set up the timer with the base period>
while(1)
{
if( task1Flag)
{
task1Flag = 0;
<do whatever needs to happen for task 1>
}
if( task2Flag)
{
task2Flag = 0;
<do whatever needs to happen for task 2>
}
}
}