Page 319 - Programming Microcontrollers in C
P. 319

304    Chapter 6  Large Microcontrollers

                              These two macros accomplish the equivalent of the same instruc­
                          tions for the MC68HC16. The cli() instruction clears the bits of
                          the IP to zero, so that any interrupt will be acknowledged by the
                          processor. The sei() instruction set the IP bits so that only a
                          nonmaskable interrupt will be acknowledged. Additional macros can
                          be written that enable the programmer to set the interrupt level any­
                          where between 1 and 7 if needed.
                              Recall that with the MC68HC11 the two registers TFLG1 and TFLG2
                          were different from the usual registers in the part. To reset bits in these
                          registers, it is necessary to write ones to the designated bits rather than
                          zeros. On the MC68HC16, this anomaly has been corrected. On the
                          MC68HC16, to reset bits in the TFLG1 and TFLG2 registers the pro­
                          gram must write zeros to the appropriate bits. That change shows up in
                          two locations in the OC3_Isr routine. The much more logical

                   TFLG1.OC1F=OFF;
                   .
                   .
                   TFLG1.OC3F=OFF;

                          instructions are used here. Otherwise, the remainder of the interrupt ser­
                          vice routine shown in Listing 6-2 is the same as that found in Listing 5-5.
                              This portability is what you should expect when changing be­
                          tween the MC68HC11 and the MC68HC16 family of parts. Care has
                          been used in the design to assure that register names and bitfield
                          names are common between the families. Therefore, code written
                          for the MC68HC11 should move to the MC68HC16 with little change.
                          The need for change at all is caused by the fact that architectures of
                          the basic machines are different.

                          EXERCISES

                          1. Modify the program shown in Figure 6-2 to allow the PWM range
                            to vary from 1 to 0XFFF. Compile this program and test the code.
                          2. Write a macro that will permit the program to put an arbitrary value
                            between 0 and 7 into the IP field of the condition code register.
   314   315   316   317   318   319   320   321   322   323   324