/* filename ******** IC.C ************** Interrupt Input Capture program for the MC68HC11 EVB This example accompanies the book "Embedded Microcomputer Systems: Real Time Interfacing", Brooks-Cole, copyright (c) 2000, Jonathan W. Valvano 5/4/99 Interface between the TExaS simulator running a MC68HC11 EVB with ICC11 freeware compiler TExaS Copyright 1999 by Jonathan W. Valvano for more information about ICC11 see http://www.imagecraft.com You may use this file without restrictions PA2-PA0 are inputs from 3 switches Increments global variable count on both rising and falling edges on PA2/IC1 falling edge (switch openning) on PA1/IC2 rising edge (switch closing) on PA0/IC3 */ #include "HC11.h" #define IC1 0x04 #define IC2 0x02 #define IC3 0x01 unsigned char count[4]; /* interrupt on PA0/IC3 touch, rising edge */ void TIC3handler(void){ TFLG1=IC3; /* acknowledge interrupt */ count[0]++; /* count number of times PA0 touched */ asm(" rti"); } /* interrupt on fall or release of PA1/IC2 */ void TIC2handler(void){ TFLG1=IC2; /* acknowledge interrupt */ count[1]++; /* count number of times PA1 released */ asm(" rti"); } /* interrupt on touch and release of PA2/IC1 */ void TIC1handler(void){ TFLG1=IC1; /* acknowledge interrupt */ count[2]++; /* count number of times PA2 fall and rise */ asm(" rti"); } unsigned char dummy; /* interrupt on STRA touch, rising edge */ void STRAhandler(void){ dummy=PIOC; /* acknowledge interrupt */ dummy=PORTCL; /* clear STAF */ count[3]++; /* count number of times PA2 fall and rise */ asm(" rti"); } /***warning**** highest level interrupt program should be so simple it doesn't push things on the stack this inconvenience is only for the freeware compiler PS if you need to make it more complex, call a function and perform the complex operations in the function. e.g., see the SCIhandler in the file SCI11a.c */ void main(void){ PIOC=0x42; /* STAI=1, EGA=1 rising edge */ DDRC=0x00; /* PC7-PC0 inputs */ TMSK1=IC1+IC2+IC3; /* arm all IC */ count[3]=count[2]=count[1]=count[0]=0; /* 11,10,01 both on PA2/IC1 falling on PA1/IC2, rising on PA0/IC3 */ TCTL2=0x39; TFLG1=IC1+IC2+IC3; /* initially clear all flags */ asm(" cli"); /* enable interrupts */ while(1){} } void resetVectors(void){ /* not really a function, but this must be last */ asm(" org $FFEA"); asm(" FDB _TIC3handler"); asm(" FDB _TIC2handler"); asm(" FDB _TIC1handler"); asm(" org $FFF2"); asm(" FDB _STRAhandler"); asm(" org $FFFE"); asm(" FDB __start"); asm(" org $FC00"); /* puts rts in a harmless place */ /* string constants also placed here */ /* the value FC00 means you can have up to 1000 characters of strings */ }