Page 230 - Programming Microcontrollers in C
P. 230
Header File 215
the bits are given the names bit0,bit1, . . . bit7. Therefore,
when dealing with specific bits within a type Register, the
programmer should use bitx, where x is the number of the bit being
referenced.
In the second portion of the file that follows, all of the I/O
registers are declared.
The external variable Register_Set is given a value 0x1000.
This value is the initial location of the I/O register map in the system.
In the MC68HC11, bit manipulation assembly instructions have a one-
byte address that can be an offset from an index register. With the
indexed version of the instruction, any single byte or bit in the entire
memory map can be accessed or tested with a single instruction.
However, the address operation must be indexed. If you use a single
address with offsets to each of the registers as is done in the header
file, the compiler will automatically place the value of Register_Set
into an index register and use the offsets specified to allow indexed
access to the data in the registers from anywhere in the program.
The value of Register_Set is not fixed by the microcontroller.
It can be changed within the first 64 clock cycles following reset. To
make this change, the programmer must assign the correct value to
the INIT register in the I/O memory space. This value should be
changed in the initialization routine for the program, which is usually
written in assembly language. After the INIT register is changed, a
new proper value assigned to Register_Set will allow the desired
access to all registers and bits in the I/O memory map.
The definition of Register shows that any instance of this
variable type is a collection of eight bits. Any location that is defined
as a type Register is truly a collection of bits and each bit must be
processed individually. For example, PORTA is declared to be of the
type Register. Therefore, an expression like
PORTA = 0x3f;
will result in an illegal assignment error because PORTA is of the
type Register, not char.
It is possible to make assignments to ports defined in the above
manner as either a byte-wide field or as bit fields. Return to the initial
declaration of a register in the header file:
typedef struct