//Displaying Overflow Timer on LEDs of PORTT in C Language for HCS12G128 Tower Board with Codewarrior //On TWR-S12G128 Tower module, 4 green LEDs are connected to PT7-PT4 //They are active LOW. Make sure the jumers for all 4 LEDs (LED1-LED4) are set //Modified from Example 9-28 in HCS12 book by Mazidi & Causey //Use F7 to Make, F5 (Debug) to download, and F5 (Start) to run the program //In CodeWarrior,make sure you are in Open Source BDM when downloading and running. #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void main(void) { /* put your own code here */ unsigned char overflow = 0; DDRT = 0xF0; //PORTT as output TSCR1 = 0x80; //enable timer TSCR2 = 0x01; //Prescaler=2 (Try 0-7 values to see changes on LEDs) for(;;) { TFLG2 = 0x80; while (!(TFLG2 & TFLG2_TOF_MASK)); //wait for Timer Overflow //while ((TFLG2 &0x80)==0); //instead of the above line you can use this one overflow = overflow + 1; //keep adding the overflows PTT = ~overflow; // dump it on LEDs (invert the value because LEDs are low active) } //Notice it is showing only the upper 4 bits of PT7-PT4. //You can connect the lower pins of PT3-PT0 to LEDs on a breadboard and see all 8-bits }