DEMO9SO8QG8 -- TESTING WITH SINGLE ADC channel

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DEMO9SO8QG8 -- TESTING WITH SINGLE ADC channel

1,191 Views
HAN
Contributor I
our problem,
 
using demo9s08qg8 board ,control led1, led2  when ever read from adc value its compare  X  value accorading led1 on,led2 off
i write sample program
 
 
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC9S08QG8.h> /* include peripheral declarations */
 
 

#define LED1 PTBD_PTBD6
#define LED1_DDR PTBDD_PTBDD6
#define LED1_MASK PTBD_PTBD6_MASK
#define LED2 PTBD_PTBD7
#define LED2_DDR PTBDD_PTBDD7
#define LED2_MASK PTBD_PTBD7_MASK
#define ON 1
#define OFF 0

void ADC_Init(void)
  {

// set up adc
  ADCSC1=0x63; // all channels selected disables the ADC
    
 
  ADCSC2=0x00;   // select software trigger
    
  ADCCFG=0x90;      // bus clock
                   
 
 
  APCTL1=0x08;
   
           //APCTL1 = 0x00;  // Disable all pins as ADC     }inputs
  }
 
  
 
  void main(void)
  
{
 ADC_Init();   // Microcontroller initialization
   
   for (;:smileywink: {
         
        __RESET_WATCHDOG(); // Kicks the dog         
         
          while(ADCSC1_COCO==1);
         
            
        {
        
         if (ADCRL > 0x00) // ATD Output => 0xBF
         {
           PTBDD_PTBDD6=1;
         }
         else
         
          {
            PTBDD_PTBDD7=1;
         }
          
     }// End While
       
 }// Loop forever
   
}//end main(void)
 
interrupt 19 void  ADC_ISR (void)
{
 
  ADCRL=ADCSC1_ADCH;
 
  ADCSC1_AIEN=0;
}
 pls check this coding correct or not
 
Labels (1)
0 Kudos
2 Replies

294 Views
HAN
Contributor I

k. thank you.. i need better understanding  C code Using  DEMO9SQG8...  any reference for solve the problem.

0 Kudos

294 Views
Ake
Contributor II
Hi,
I looked thru your code, without understanding what it did, but one thing caught my attention.
In the interrupt routine you wrote:
 
 
  ADCRL=ADCSC1_ADCH;
but the ADCRH:L registers are where the results appear. So you are not allowed to do any writing into them.
 
Regards,
Ake
0 Kudos