PROGRAMMING PIC MICROCONTROLLERS IN C:PERSISTENT VARIABLES AND ABSOLUTE ADDRESS VARIABLES

PERSISTENT VARIABLES

Normally, the initial values of variables are cleared to zero when the program starts up (i.e. whenever reset is applied to the microcontroller). The persistent qualifier prevents a variable from being cleared at start-up. In the following example, the variable max is declared persistent and as a result its value is not cleared after a reset:

persistent int max

ABSOLUTE ADDRESS VARIABLES

It is possible to declare a variable such that it holds the address of an absolute location in the microcontroller memory. This is done by typing the character ‘@’ after the name of the variable. For example,

unsigned char Portbit @ 0×06

In this code, the variable Portbit is assigned the absolute hexadecimal address 0 × 06. It is important to realize that the compiler does not create a location for the variable Portbit, it simply assigns the variable to the specified absolute address.

The bit data type and absolute address variables can be used together to access individual bits of a register. For example, the PORTA register is at absolute address 5. We can declare a variable called PA1 to access bit 1 of PORTA as follows:

unsigned char PORTA @ 0×05; bit PA1 @ (unsigned)&PORTA*8+1;

Leave a comment

Your email address will not be published. Required fields are marked *