And by "static" I meant, of course, "extern"! XP Static made the Timer1 in flash.c become a different variable (same name, different memory location) than the Timer1 in main.c. Extern in all my code, regular definition in flash.c and now the timers are working. If it were up to me, I would take Matt's suggestion to keep the variables private and access them through functions only. That is actually what I had first proposed when this came up the other day. But the other programmer involved costs a lot of money and doesn't want to do it that way, so... Dave's "GLOBAL" define is a really nice solution. For my project, I assume it would be set up as: flash.h -- GLOBAL volatile BYTE Timer1, Timer2; // 10mS decrement timer flash.c -- #define GLOBAL #include main.h ... #undef GLOBAL #define GLOBAL extern #include flash.h main.c -- #define GLOBAL extern #include main.h ... #undef GLOBAL #define GLOBAL #include flash.h Main.h has to be included first in all the .c files, so the extern part is in different places from the main and flash .c files. As to the "rule" that .h files only reference and never define, I understand the desire to keep things separate, but that also then requires that we have the types of the variables entered the same way in both the .h and .c files. If it turns out we need a 16 bit timer, with the macros or Dave's GLOBAL define, we only have to change the one flash.h file from "BYTE Timer1, Timer2;" to "WORD Timer1, Timer2;" and the compiler will change the generated code to compensate automatically. Thanks for all the great education on this point... Someone with the time to do it should put together a web page... -- James Newton -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of James Newton Sent: Wednesday, October 24, 2007 16:28 To: 'Microcontroller discussion list - Public.' Subject: [EE] Global variables in projects with many C files. Ok, I figured this out on my own, after writing the post I tried the other guys "static" keyword in my main.h file and that worked. I'm going to post it anyway 'cause I like looking stupid... Err... No, I'm going to post it because some day some other poor soul may have the same confusion. Had I posted it, some kind soul would have replied "RTFM: static keyword, main.h" Here is the original post. The is undoubtedly a stupid question, but I've managed to confuse myself enough that I need some help.. 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? The chip we are using is an MSP430F1611 and the compiler is IAR. My understanding is that they should be declared in main.h so that the declaration is seen in both places, but when I do that, it compiles ok, but the linker complains that " Error[e27]: Entry "Timer1" in module main ( D:\user\james\code\JAMES-WIP\msp430\logger\Debug\Obj\main.r43 ) redefined in module flash ( D:\user\ james\code\JAMES-WIP\msp430\logger\Debug\Obj\flash.r43 ) " This is the section of main.h: volatile BYTE Stat = STAT_NO; // status volatile BYTE Timer1, Timer2; // 10mS decrement timer I think there must be come compiler setting that I'm missing that would make it understand that those "two" variables are one and the same. The guy writing FLASH.H seems to think they should only be defined in his code, but says that using the "static" keyword will somehow make the values available in main. When we do that, the compiler complains that " Error[Pe020]: identifier "Timer1" is undefined D:\user\james\code\JAMES-WIP\msp430\logger\main.c 77" and so on for the other variables. -- Some clueless guy -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist