//Displaying Overflow Timer on LEDs of PORTA for Project Board with HCS12 MCU Module and CodeWarrior //Modified by Mazidi from Example 9-28 in HCS12 textbook by Mazidi & Causey //In CodeWarrior,MAKE sure you are in TBDML Mode before downloading //Press F7 (to Make), then F5(Debug) to downLOAD,and F5 once more to start the program execution #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void main(void) { /* put your own code here */ unsigned char overflow = 0; DDRA = 0xFF; //PORTA as output since LEDs are connected to it DDRP = DDRP | 0b00010000; //on Project Board, the lower 4 bits of PA3-PA0 are connected to LEDs(LED1-LED4) permanently PTP = PTP & 0b11101111; //and must be enabled by clearing bit P4 of PORTP //on Project Board,we need to connect 4 wires from LED5-LED8 (J10) to pins PA4-PA7 via J6 connector (pins 25,27,29,31) TSCR1 = 0x80; //enable timer TSCR2 = 0x4; //Prescaler=16 (Try 0-7 values to see changes on LEDs) for(;;) { TFLG2 = 0x80; while (!(TFLG2 & TFLG2_TOF_MASK)); //wait for Timer Overflow overflow = overflow + 1; //keep adding the overflows PORTA = overflow; //and dump it PORTA to see } // Notice the LEDs of LED1-LED4 on Project Board are arranged in awkward manner. //LED1 should have been connected to the PA0 pin of CPU ,but instead it is connected to PA3. //that is the reason the counter looks awkward. }