/* Generate two PWMs with OC1 controlling OC2 & OC3. */ #code 0xC0F0 #data 0xC000 #include #include <68hc11.h> /* to use special registers of the 68HC11 */ #include #define REG_BASE 0x1000 int temp; /* used by interrupt service routine since service routine cannot have local variables */ int period; unsigned int duty1; /* duty cycles */ unsigned int duty2; int one_percent_per; /* one percent period */ /***************************/ interrupt toc1(){ /* Schedule next compare for OC1, OC2, OC3 */ temp = peek(REG_BASE + TOC2); temp = temp + period; poke(REG_BASE + TOC2, temp); temp = peek(REG_BASE + TOC3); temp = temp + period; poke(REG_BASE + TOC3, temp); temp = peek(REG_BASE + TOC1); temp = temp + period; poke(REG_BASE + TOC1, temp); bit_set(REG_BASE + TCTL1, 0x80); /* clear OC1 flag */ } /************************************************** * Calculate offset to schedule first compare for OC2 & OC3 **************************************************/ cal_offset(duty) int duty;{ return (duty * one_percent_per); } /***************************/ initialize(){ int offset; bit_set(REG_BASE+TCTL1,0xA0); /* OC2 and OC3 for toggle */ pokeb(REG_BASE+TFLG1,0x80); /* clear OC1 flag */ pokeb(REG_BASE+TMSK1,0x80); /* enable OC1 int. */ pokeb(REG_BASE+OC1M, 0x60); /* OCM 6,5 = 1 */ pokeb(REG_BASE + OC1D, 0x60); /* drive OC2, OC3 high at OC1 successful compare */ period = (one_percent_per * 100); /* calculate period */ poke(REG_BASE+TOC1, period); /* schedule first OC1 compare */ offset = cal_offset(duty1); poke(REG_BASE+TOC2, offset); /* schedule first OC2 compare */ offset = cal_offset(duty2); poke(REG_BASE+TOC3, offset); /* schedule first OC3 compare */ } main(){ poke(0xE0,toc1); /* store addr of toc1 to pseudo int. vector + 1*/ one_percent_per = 170; duty1 = 50; duty2 = 50; initialize(); e_int(); while(1){ ; } }