Page 419 - Programming Microcontrollers in C
P. 419
404 Chapter 8 MCORE, A RISC Machine
computer does not have to sit in a wait loop until the delay time is
over to implement the delay.
The two delay functions, those shown in Listings 8-1 and 8-3,
are examples of code that are very close to the microcontroller. The
application program shown in Listing 8-4 is the type of program that
could almost be viewed as divorced from the microcontroller. In 8-4
the two operations
Enable_Fast_Interrupts();
vector(handler,FAST_AUTOVECTOR);
are clearly processor dependent, but these processor dependent
functions are written as functions, or function-like macros. Therefore,
if it is necessary to move to another processor, it is necessary only to
adjust the contents of these functions to make the program usable.
The two delay functions, on the other hand, are a mass collection of
processor-specific commands that would have no meaning if the
processor were to be changed. It is a good idea when writing code
for embedded microcontrollers to collect together all of the processor
specific code into functions by themselves and allow the general code
to be as free from processor specifics as possible. We will see this
idea in the following section where several general functions interface
with several processor-specific functions.
Serial Input/Output
Serial input/output is an important capability of almost all
microcontrollers that allows the programmer or user to communicate
with the processor. Most of these functions are rather simple to
implement. Some of the functions are quite processor-specific and
others are more generally applicable to many microcontrollers. As
mentioned above, it is important that you split these functions apart
so that as much of the code that you generate as possible is portable.
Let us look at the functions contained in serial1.c.
/***********************************************************
These routines implement a serial port on the MMC2001.
The UART1 is used and the default is set to 9600 b/s, 8 bit,
no parity, and 1 stop bit. The baud rate is passed as an
integer to the inituart() function. There are several i/o
functions included. These are: