/* Measure period of pulse at IC1. Error: +/- 100ms (0.1sec). minimum period = 0.1sec.*/ #code 0xC000 #data 0xD000 #include #include <68hc11.h> /* to use special register of 68HC11 */ #include /* These are included to use fputs */ #include #include #include #include #define REG_BASE 0x1000 FILE stdout; /* to use fputs */ int done; /* flag: 0-not done,1-pulse measured*/ int first; /* s/w mode flag: 0 -> waiting, 1 -> first edge*/ int factor, count; interrupt tme_ic1() { if (first == 0) { first = first+1; /* 1st edge detected, not done */ } else { done = 1; /* 2nd edge detected, done */ first = 0; } bit_set(REG_BASE+TFLG1,0x04); /* clear int. flag */ } init() { done = 0; first = 0; count = 0; pokeb(REG_BASE+TCTL2,0x10); /*EDG1B:EDG1A = 0:1, IC1 rising edges*/ bit_set(REG_BASE+TFLG1,0x04); /* clear IC1 flag, if any */ bit_set(REG_BASE+TMSK1,0x04); /* enable IC1 interrupt */ bit_set(REG_BASE+TFLG2,0x40); /* clear RTI flag, if any */ bit_set(REG_BASE+TMSK2,0x40); /* enable RTI interrupt */ bit_set(REG_BASE+PACTL,0x03); /* set rate to 32.77ms */ e_int(); } /******************************************************** * This service routine gets called every 32.77ms. count is * incremented each time until = 3 (100ms has passed). "factor" * is incremented every 100ms since the first edge is detected. * The period is (factor * 100ms). */ interrupt rti(){ if(count == 3){ /* 100ms has passed */ count = 0; if(done ==1){ d_int(); /* disable interrupt */ stdout = fopen(EVB_out); printdec(factor * 100); /* print the period out to screen */ fputs(" ms\n", stdout); done = 0; /* reset done flag for next measurement */ factor = 0; /* reset for next measurement */ e_int(); /* enable interrupt */ } else if(first == 1) factor = factor + 1; else ; } else count = count + 1; /*keep track of when 100ms has passed*/ bit_set(REG_BASE+TFLG2,0x40); /*clear int. flag */ } main(){ poke(0xE9,tme_ic1); /* make tme_ic1 an int. service routine*/ poke(0xEC,rti); /* make rti() an int. service routine */ init(); while(1){ ; } }