Page 101 - Programming Microcontrollers in C
P. 101
86 Chapter 2 Advanced C Topics
PORTA |=0X80;
if(PORTA & 0x6==0)
do something;
You can perform any operations with PORTA that you would want
with any normal variable in the language. While PORTA has been
generated by a macro expansion it also can be used as a variable.
Thus, the title pseudo-variable. Unless there is a specific reason,
though, I will call these macros “variables.”
The above pseudo-variable is of the type char, and its address is
0x1000. This capability is very useful in programming microcontrollers.
When programming microcontrollers, there are two reasons why
it is necessary to be able to manipulate direct addresses in memory.
Most high-level languages will not allow the programmer direct ac
cess to specific memory locations. As seen above, C does allow the
programmer to bend these rules enough to be able to store data into
a specific memory address. Another feature that is highly desirable
is to be able to place the address of a function at a specific address.
This capability is necessary when implementing an interrupt service
routine. When an interrupt occurs, the computer will stop its current
operation, save at least the values contained in the status register and
the program counter, and begin execution at an address contained in
a vector location. Each interrupt will have a vector address, and each
interrupt will require its own interrupt service routine. Program ini
tialization when interrupts are involved will require that the program
place the addresses of any interrupt service routines into the specific
vector addresses for each interrupt.
A continuation of the above approach can be used in this case. There
is a direct address in memory that is to receive the interrupt service
routine address. Let’s think for a moment about what this address is. The
address is going to contain the address of a function. The address itself is
a pointer to a memory location. The contents of this location are a pointer
that points to a function that is the interrupt service routine. All interrupt
service routines are of the type void. Therefore, the vector address is a
pointer to a pointer to a type void. To be able to place the value of the
pointer to a type void into this location, we must assert one additional
level of indirection to access the content of the specific memory loca
tion. Therefore, the following line of code