Example 11 Analog-to-Digital Converter Lecture L5.1
miniDragon+ Serial cable Reset button Power plug2 pushbutton switches A/D Pot Run/Load switch 7-segment display I/O headers Keypad header LCD Header
A/D Ports MC9S12DP256
ATD0 Pins PADD0 – PADD7 (ch# 0 – 7) Pins 67,69,71,73, 75,77,79,81 ATD1 Pins PAD8 – PAD15 (ch# 0 – 7) Pins 68,70,72,74, 76,78,80,82
ATD0 Pins PADD0 – PADD7 (ch# 0 – 7) Pins 67,69,71,73, 75,77,79,81 ATD1 Pins PAD8 – PAD15 (ch# 0 – 7) Pins 68,70,72,74, 76,78,80,82 Pot
Method of Successive Approximation
// Example 11: A/D Converter -- Pot #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" int val; void main(void) { PLL_init();// set system clock frequency to 24 MHz ad0_enable(); // enable a/d converter 0 lcd_init(); // enable lcd while(1) { val = ad0conv(7); // read pot on channel 7 val = val >> 1;// shift 1 bit right (divide by 2) set_lcd_addr(0x40); // display on 2nd row of LCD write_int_lcd(val);// write value in field of 5 ms_delay(100);// delay 0.1 seconds } Example 11