Page 326 - Programming Microcontrollers in C
P. 326
Cosmic MC68HC16 Compiler 311
#define MAX_MIN MAX_SEC
#define MAX_HOURS 12
#define MIN_HOURS 1
/* function like macros */
#define get_hi(x) ((x)/10+’0')
#define get_lo(x) ((x)%10+’0')
/* function prototypes */
@port void OC3_Isr(void);
@port void PIT_Isr(void);
void output_time(void);
void putch(int);
void send_out(WORD);
/* External variables */
WORD pwm_period=PERIOD, pwm_count=ON_TIME,new_input=0;
WORD hrs,mts,sec,been_here=0;
char new_character;
main()
{
/* The initialization portion of the program */
/* initialize the SIM registers */
SYNCR.X=ON; /* set the system freq to 16.88 mHz */
SYPCR.SWE=OFF; /* disable the watchdog */
SIM_MCR.IARB=SIM_IARB; /* IARBs for each module is
different */
PICR.PIRQL=PIC_PIRQL; /* put all timers at level 6 */
PICR.PIV=PIC_PIV; /* vector is 0x38, address is 0x70 */
PITR.PTP=ON; /* 512 prescaler */
PITR.PITM=PIT_PITM; /* divide by 16*4, 1 tic per
second */
/* initialize the GPT */
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 */
OC1M.OC1M3=ON; /* sent OC1 out to pin */
OC1M.OC1M5=ON; /* couple OC1 to OC3 */
TMSK1.OC3I=ON; /* enable the OC3 interrupt */
OC1D.OC1D5=ON; /* turn on OC3 when OC1 occurs */
TCTL1.OL3=ON; /* toggle OC3 when OC3 occurs */
TOC1=TCNT+pwm_period; /* set OC1 to the period */
TOC3=TOC1+pwm_count;/* set OC3 time on */