Page 315 - Programming Microcontrollers in C
P. 315

300    Chapter 6  Large Microcontrollers

                   #include “hc16.h”
                   #include “gpt.h”
                   #include “sim.h”

                   #define PERIOD 0x1000
                   #define ON_TIME       0x0800
                   #define GPT_IARB  5
                   #define GPT_IRL       6
                   #define GPT_VBA       4

                   /* function prototypes */
                   @port void OC3_Isr( void); /* the PWM isr */
                   WORD pwm_period=PERIOD, pwm_count=ON_TIME;


                   main()
                   {
                       /* The initialization portion of the program */


                       SYNCR.X=ON; /* set the clock freq to 16.78 MHz */
                       SYPCR.SWE=OFF; /* disable the watchdog */
                       GPT_MCR.IARB=GPT_IARB;        /* pick an IARB for the Timers */
                       ICR.IRL=GPT_IRL;         /* interrupt level 6 */
                       ICR.VBA=GPT_VBA;         /* vectors start at 0x40 */
                       OCONM.OCONM3=ON;         /* sent OC1 out to pin */
                       CONM.OCONM5=ON;          /* couple OC1 to OC3 */
                       TMSKON.OC3I=ON;          /* enable the OC3 interrupt */
                       OCOND.OCOND5=ON;         /* turn on OC3 when OC1 occurs */
                       TCTLON.OL3=ON; /* toggle OC3 when OC3 occurs */
                       TOC1=TCNT+pwm_period;/* set OC1 to the period */
                       TOC3=TOC1+pwm_count; /* set OC3 time on */
                       cli();    /* enable the system interrupts */
                       /* the applications portion of the program */


                       FOREVER
                       {
                       }
                   }

                   /* The asynchronous service portion of the program */

                   @port void OC3_Isr( void) /* the PWM isr */
   310   311   312   313   314   315   316   317   318   319   320