ADC code for MC9S08QG8, please help

Discussion created by M K on Feb 14, 2010
Latest reply on Feb 16, 2010 by bigmac

Hi there. I have a demo board for MC9S08QG8, its not an official one. Anyway it has a potentiometer connected to channel 0 PTA0.

All Im trying to do is output the adc value to 8 lights connected to port B. Can you please correct my code? Im using interrupts to read the data after the conversion is completed:






#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

void adcISR(void);

volatile unsigned char result;


void main(void) {

  EnableInterrupts; /* enable interrupts */




  ADCSC1=0x40; //interrupst enable, one conversion, input channel 0

  ADCSC2=0x00; //software trigger, no comparison


  APCTL1=0x01;  //pin AD0 I/O disabled

  ADCCFG=0x90;   //low power, bus clock, long sample, 8bit mode



  PTBDD=0xFF;    //Set port b as output


  PTBPE=0x00;    //pull-up resistors







  interrupt 19 void adcISR(void) {


  PTBD=ADCRL; // read the ADC result and put it onto port B













Thank you in advance.