On Wed, 24 Oct 2007 16:28:16 -0700, James Newton wrote: > I'm working on probably the largest program I've ever done in C. There > are 5 separate ".C" files and double that in ".H" files. Some of the C > files are being done by other people. I have main.c and .h, and another > programmer is doing flash.c and .h. My main, of course, includes flash.h > as well as main.h and his flash.c also includes both of those as well. > > We need to access some "global" variables between us. E.g. a pair of > count down timer variables and a status flag byte. I have to decrement > the timers in the interrupt routine that I wrote and he sets those and > waits for them to empty at points in his code. We each set and reset > flags in the status byte and branch based on their settings. > > Where and how do we define those variables? I would write several timer access functions and keep the timer variable private in the timer module. Global variables at the timer interrupt level are a nasty bug waiting to happen. Sometimes they can't be avoided but usually they can. The rule would be only the timer ISR and the timer access functions can change or access the timer variable(s). Add some functions like TimerSet(), TimerExpired(), TimerRead(), etc. to the timer software module that are public and allow other software modules access to timer status through one method and place. There is very low overhead for doing this and the functions are very simple but they are also safe in that you know the timer variable(s) are only accessed/changed in ONE place in the code. In general, globals are a bad thing... ;-) Matt Pobursky Maximum Performance Systems -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist