/* Generate a square wave at the PA6 output pin using OC2 Can change the variable half_cyc_delay in main as desired */ #code 0xC000 #data 0xD000 #include #include <68hc11.h> #include #define REG_BASE 0x1000 int half_cyc_delay; int temp; /* used by interrupt service routine since service routine cannot have local variable */ /*************************************** * Service routine: schedule next toggle for OC2 ****************************************/ interrupt toc2(){ temp = peek(REG_BASE+TOC2); /* get delay time for 1/2 cycle*/ temp = temp + half_cyc_delay; /* add to last compare value */ poke(REG_BASE + TOC2,temp); /* schedule next edge */ bit_set(REG_BASE + TFLG1, 0x40); } /***************************/ initialize(){ pokeb(REG_BASE+TCTL1,0x40); /* OM2:OL2 = 0:1 -> OC2 toggle */ pokeb(REG_BASE+TFLG1,0x40); /* clear OC2 flag */ pokeb(REG_BASE+TMSK1,0x40); /* enable OC2 */ } /***************************/ main(){ half_cyc_delay = 10000; poke(0xDD,toc2); /* store toc2 address into pseudo interrupt vector+1 */ initialize(); e_int(); while(1) ; }