//Displaying ATD0 channel 1 (POT) on 8 LEDs of PORTA for Freescale Project Board with HCS12 MCU module //Modified from Program 13-1 of HCS12 textbook by Mazidi & Causey //In HCS12 MCU Module, XTAL=4MHz, Bus Freq. =2MHz. Then divivde it by 2 to get 1MHz for conversion freq. //ATD0 channel 1 (AN01) is connected to POT. The POT (RV1) is located on the bottom corner left side of the Student Project Board. //Change the POT to see the changes on LEDs of PORTA //The lower 4 bits of PA3-PA0 are connected to LEDs(LED1-LED4 on J10) permanently //and must be enabled by clearing bit P4 of PORTP. //MAKE SURE both jumpers for LED and POT are set. LED and POT jumpers are part of group of jumpers called UFEA right next to the Buzzer //To have 8 LEDs, we must also connect 4 wires from LED5-LED8 (J10) to pins PA7-PA4 via J6 connector //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 MSDelay(unsigned int); void main(void) { /* put your own code here */ 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) DDRP = DDRP | 0b00001000; //We need to make P3 bit of PORTP as output for the POT PTP = PTP | 0b000001000; //The POT is connected to AN01 (ADC0 chan 1) and must be enabled by setting high bit P3 of PORTP ATD0CTL2 = 0x80; //Turn on ADC,..No Interrupt MSDelay(1); //optional ATD0CTL3 = 0x08; //one conversion, no FIFO ATD0CTL4 = 0xE0; //8-bit resolu, 16-clock for 2nd phase, //prescaler of 0 for Conversion Freq=1MHz for(;;) { ATD0CTL5 = 0x81; //Channel 1 (right justified, unsigned,single-conver,one chan only) while(!(ATD0STAT0 & 0x80)); PORTA = ATD0DR0L; //dump it on LEDs //MSDelay(2); /optional } } void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i