Page 235 - Programming Microcontrollers in C
P. 235
220 Chapter 5 Programming Large 8-Bit Systems
There are several small routines associated with the processing
of interrupts that are not in the C library. These routines are written
as functions to make it easier to access these important operations.
The cli() and sei() functions allow the program to clear or set
the interrupt bit in the condition code register (CCR). The programmer
can with these two functions and the interrupt masks in the I/O
memory map control all interrupt operations of the part.
The compiler must be notified that a function is to be an interrupt
service routine. An interrupt service routine can have no arguments,
and it must return nothing. Therefore, the function prototype of an
interrupt service routine might look like
void isr_clock( void );
However, the compiler would still have no way of knowing that this
function is an interrupt service routine. The reason that the compiler
must know an isr is that the MC68HC11 family stacks the complete
machine status when an interrupt is accepted by the device. This
status must be restored when the program control is returned to the
interrupted program. The machine status is restored when an rti
instruction is executed. Therefore, any return from an interrupt must
be the assembly instruction rti rather than the instruction rts
usually used to return from a function. An interrupt service routine is
identified to the compiler by the sequence @port ahead of the
definition of the function in the function prototype. The function
prototype of an interrupt service routine should be
@port void isr_clock( void );
This flag will cause all returns from the function to be rti instructions.
There is no guarantee that there will be macro definitions for
useful numbers and functions. A series of enumerations that define
TRUE, FALSE, ON, OFF, START, STOP, etc., are included to pro
vide mnemonics for these often-used values. The pointer constant
NULL is also defined by a macro here. These constants are often
defined in other header files, so the protection against including these
constants more than one time is also included. Also useful is the
macro FOREVER which is included.