Page 325 - Programming Microcontrollers in C
P. 325

310    Chapter 6  Large Microcontrollers

                              This program is a minimum SCI system. The SCI portion of
                          this chip has comprehensive capabilities that are not exploited in the
                          program above. These capabilities and error-checking devices are all
                          available on the chip, and their access anduse is explained in detail in
                          the QSM Reference Manual. Access of the various capabilities is
                          exactly the same as was shown above in this program.

            Periodic Interrupt

                              To make the problem a little more interesting, let’s add another
                          load to the machine by making use of the periodic interrupt capabil­
                          ity provided in the SIM to create an interrupt. With this interrupt, we
                          will build a time-of-day clock similar to that developed in Chapter 4.
                          In this case you will see that the applications code developed for the
                          MC68HC05 will work fine for the MC68HC16. Of course, the ini­
                          tialization code and the interrupt service routine will be completely
                          different for the MC68HC16. This additional code will be put right
                          into the program listed in Listing 6-3. It is asserted that there will be
                          no adverse interactions between the various sections of the code.
                   #include “hc16z1.h”
                   #include “gpt.h”
                   #include “sim.h”
                   #include “qsm.h”
                   #include “defines.h”


                   #define PERIOD 0x1000
                   #define ON_TIME       0x0800
                   #define SIM_IARB  4
                   #define PIC_PIRQL 6
                   #define PIC_PIV       0X38
                   #define PIT_PITM  16
                   #define GPT_IARB        10
                   #define GPT_IRL       6
                   #define GPT_VBA       5
                   /* set the baud rate=fclock/32*baud_rate */
                   #define BAUD_SET        (32768*512)/(32*38400)
                   #define TIME_COUNT           1000
                   #define MAX_MIN       59
                   #define MAX_HOURS 12
                   #define MIN_HOURS 1
                   #define NO_WAIT       0
                   #define OC2_OFFSET           5
                   #define MAX_SEC       59
   320   321   322   323   324   325   326   327   328   329   330