Page 186 - Programming Microcontrollers in C
P. 186

Timers    171

                          underscore. These names are also listed in all upper-case letters. These
                          entries are the names of the various interrupt service routines. Since
                          C is case sensitive, the names of the functions to be used as interrupt
                          service routines must have the same form.
                              The three #pragma entries identified as has notifies the com­
                          piler that the microcontroller has the  STOP,  WAIT, and MUL
                          instructions. The next pair of entries defines the memory map for
                          this microcontroller. Finally, the next six entries are #defines that
                          identify the bits in the TCSR. Therefore, mnemonic representations
                          of all registers and bits can be used in the C program.
                              Several header files for the M68HC05 family are found on the
                          CD-ROM. The conventions in these files are to use bit names and
                          register names that are identical to those used in the technical data
                          books that describe the devices. Therefore, the programmer can safely
                          use register names and bit names found in the books without having to
                          look up the values in the header files. These files include commands to
                          prevent listing of these files in the compiler listing output files.
                              Listed below is a simple program that shows the use of the 15-bit
                          timer in the M68HC05J1. This program is not aimed at doing more
                          than showing the use of the timer operation. The system will create
                          an inaccurate clock in which the time in hours, minutes, and seconds
                          will be recorded in memory, but no provision to display these values
                          or even set the values will be considered at this time.
                              Most clocking operations should be interrupt driven. If a periodic
                          interrupt can be generated, the operation of the clock will be transpar­
                          ent to any other operations being conducted in the microcontroller.
                   #include “hc05j1.h”
                   enum {FALSE,TRUE);
                   enum {OFF,ON};


                   #define FOREVER while(TRUE)
                   #define MAX_SECONDS 59
                   #define MAX_MINUTES MAX_SECONDS
                   #define MAX_HOURS 12
                   #define MAX_COUNT 121

                   /* define the global variables */
                   int hrs,mts,sec;
   181   182   183   184   185   186   187   188   189   190   191