//Displaying ATD channel 0 (POT) on LEDs of PORTT and Tera Terminal (or Hyper Terminal) via SCI0 for HCS12G128 Tower Board //Modified and tested by Mazidi from Examples in Chaps 10 and 13 of HCS12 book by Mazidi & Causey //On TWR-S12G128 Serial COM0 (SCI0) is IDC 2x5 male header located next to brown POT. //The TWR-S12G128 board comes with a DB9-to-IDC-2x5 femal cable for connecting it to the COM port of x86 PC //When connecting female IDC 2x5 to Tower,make sure pin 1 on IDC Tower board is lined up with the red stripe of the IDC-2x5 cable //If the IDC-2x5 cable is connected right, then RED stripe will be on side of USB power cable //If your x86 PC does not have Serial COM port (with DB-9 connector)then you need USB to Serial Converter //The best one we have seen is (TRENDnet USB to RS-232 Serial Converter TU-S9) from Amazon //http://www.amazon.com/TRENDnet-RS-232-Serial-Converter-TU-S9/dp/B0007T27H8/ref=pd_bxgy_e_img_y //With Contribution from Shu-Jen Chen //Notice the on-chip ADC of HCS12G128 is slightly different from the HCS12DT256/512 covered in the textbook //See Chapter 12/13 (ADC10B12CV2) in the MC9S12GRMV1.pdf ref. Manual //In TWR-S12G128 the Bus Freq=6.25 MHz. //ATD channel 0 (AN0) is connected to RV1 brown Pot Trimer //Change the POT to see the changes on LEDs of PORTT //Also bring up the Tera Terminal and see ADC values of 00-0xFF are displayed as ASCII chars //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 SerTx0(unsigned char); void MSDelay(unsigned int); void main(void) { unsigned char x; PER0AD = 0x80; // enable PU on PAD15 to enable COM for the HCS12G128 chip // Notiice this is different from HCS12DP256/512 SCI0BDH=0x00; SCI0BDL=41; //12.5 MHz/2=6.25MHz, 6.25MHz/16=390,625 Hz and 390,625/9600=41 SCI0CR1=0x00; SCI0CR2=0x0C; 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 = 0; // start a single conversion on channel 0 while(!(ATDSTAT0 & 0x80)); x = ATDDR0L; // read conversion result PTT = ~x; // dump it on LEDs (invert the value because LEDs are low active) SerTx0(x); // send it to SCI0 SerTx0(' '); //MSDelay(1); //optional } } void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i