//Displaying Temperature sensor (ATD chan1) of Axiom Peripheral (TWR-DEV-PERIPH) board on LEDs of PORTT for HCS12G128 Tower Board //Modified and tested by Mazidi from Program 13-1C of HCS12 book by Mazidi & Causey //Notice the on-chip ADC of HCS12G is slightly different from the HCS12DT256/512 covered in the textbook //See Chapters 12/13 (ADC10B12CV2) in the MC9S12GRMV1.pdf ref. Manual //In TWR-S12G128 the Bus Freq=6.25 MHz. //On the Axiom TWR-DEV-PERIPH board, the ATD channel 1 (AN1) is connected to MCP9700 Temperature sensor //This program displays the room temperature in Celsius (in binary) //The MPC9700 Temperature sensor is U1 on TWR-DEV-PERIPH board //and it is located on the right side of the letter A of keypad //The Voltage for Vref on TWR-HCS12G128 module is connected to Vdd(5V). That means the step size is 20 mV //Therefore the temp value you get is twice of what should be since MPC9700 gives us 10mV per degree Celsius. //Touch the TempSensor or blow hot air (with your mouth) on it to see the LEDs change //On the Axiom TWR-DEV-PERIPH board make sure you have jumpers: JP1 set on the left, JP2 is set, and JP3,JP4, and JP5 on the right. //In Codewarrior, make sure you are in Open Source BDM //In Codewarrior F7(make), F5(Debug) and F5 again to start running #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); void main(void) { unsigned char MyTemp; DDRT = 0xF0; // PORTT as output ATDCTL1 = 0; // 8-bit resolution ATDCTL3 = 0x88; // right justified, one sample per sequence ATDCTL4 = 0x02; // prescaler = 2; ATD clock = 6.25MHz / (2 * (2 + 1)) == 1.04MHz // should be between 0.25MHz and 8 MHz per specs. for(;;) { ATDCTL5 = 1; // start a single conversion on channel 1 while(!(ATDSTAT0 & 0x80)); //while(ATDSTAT0_SCF==0x80); //you can also use this instead MyTemp = ATDDR0L; //Notice the conversion result is in low bye of ATDDR0 register (ATDDR0L) MyTemp = MyTemp<<4; //shift it left 4 times since you are displaying upper LED4-LED1 PTT = ~MyTemp; // dump it on LEDs (invert the value because LEDs are low active) //you can also connect 4 more LEDs to PT3-PT0 on a breadboard and see all 8 bits. MSDelay(50); //optional } } void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i