Hi All,
I only ever post problems, so I thought I'd post my solution to having loads of software timers and ending up with an interrupt routine source code that generally looks confusing to decode.
#define LCD_REFRESH 250 #define ONE_SECOND 12500 /* define a structure for a timer */ struct timerdef { unsigned int time; unsigned int period; } timer[] = { {LCD_REFRESH, LCD_REFRESH}, {ONE_SECOND , ONE_SECOND} }; /* define a pointer to a function */ typedef void (*pFunction)(void); /* define prototypes for timer functions */ void tsr_lcdrefresh( void ); void tsr_onesecond( void ); /* initalise an array of timer functions */ pFunction timer_functions[] = { tsr_lcdrefresh, tsr_onesecond }; /* Timer Service routine for lcdrefresh */ void tsr_lcdrefresh( void ) { /* do something here */ } /* End Timer Service Routine */ /* Timer Service routine for onesecond */ void tsr_onesecond(void) { /* do something here */ } /* End Timer Service Routine */ void software_timers(void) { /* use a local variable for looping */ unsigned char i; /* run the software timers */ for( i=0; i
I an implimentation of this code in a sligthly different form to scan switches too, and then have an array of pointers to functions to service key presses.
This seems to make my life easier when I want to add another software timer.
Does anyone else impliment software timers in this way, or maybe slightly differently/better?
Best Regards,
Brian Sidebotham.