370 A. PROGRAMMING
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
There are two types of variables used within a program: global variables and local variables. A global
variable is available and accessible to all portions of the program. Whereas, a local variable is only
known and accessible within the function where it is declared.
When declaring a variable in C, the number of bits used to store the operator is also speciﬁed.
In Figure A.4, we provide a list of common C variable sizes. The size of other variables such as
pointers, shorts, longs, etc., are contained in the compiler documentation [ImageCraft].
4 - 8
Figure A.4: Typical C variable sizes.
When programming microcontrollers, it is important to know the number of bits used to
store the variable and also where the variable will be assigned. For example, assigning the contents
of an unsigned char variable, which is stored in 8-bits, to an 8-bit output port will have a predictable
result. However, assigning an unsigned int variable, which is stored in 16-bits, to an 8-bit output
port does not provide predictable results. It is wise to insure your assignment statements are balanced