---------- > From: Stevenson, Brad > To: PICLIST@MITVMA.MIT.EDU > Subject: HiTech C questions > Date: Thursday, March 12, 1998 7:21 AM > > > Hello all, Hey now! > > I started using the Hi-Tech C compiler a couple of weeks ago. In general > it seems like a very good product, but I have a couple of questions and > I'm hoping someone else with more experience can give me a hand. > I've been using it for a couple of weeks too. It seems very good, but there are a few bugs I've found that I'm trying to resolve with Hi-Tech. > 1) In some of the examples in the manual, global variables are declared > as static. This appears redundant. Is there a reason? > Static is a C keyword that can be used in at least these two ways: a) When declaring global variables and functions within a file module. This denotes that the global variables and functions defined within this module are only used within this module and cannot be accessed externally without a global wrapper function. ie. char GetLastCount(void) /*Can be accessed externally*/ { return lastcount; /*Last count is static within this module*/ } b) For variables defined static within a function. These variables are only available within the function. However, the variable retains it's settings and is available the next time the function is called. You can see how this can be useful. > 2) In the FAQ example of an ISR function. The function itself is defined > as static. What is a static function? > See above. > 3) In the code I am working on, I have declared a global variable of > type 'bit'. This bit is declared in the main C source file. This bit is > set in an ISR function (which is defined in another C source file, > which is part of my project). The bit is checked in the main() part of > the program. By using an emulator I can verify that the ISR is being > executed, but the bit is not being set, so the main() program does not > respond accordingly. If I change the declaration from bit to char, the > code works properly. Any ideas? > I either use the bits defined. ie. RA0 = 1; //sets porta bit0 to 1 TRISB = 0; //sets tristate register b to output or use these #define SetBit(var,bit) ((var) |= (1 << (bit))) #define ClrBit(var,bit) ((var) &= ~(1 << (bit))) #define TstBit(var,bit) ((var) & (1 <<(bit))) > Brad Stevenson, CET > The DPL Group - Telecom Techniques > 506-635-1055 or 1-800-561-8880 > http://www.dpl.ca