Functions

ADC single step mode example
[Projects]


This example samples P00 using ADC single step mode and outputs the 8 bit sample value on P1.

Functions

void main ()

Function Documentation

void main ( void   )

Definition at line 30 of file main.c.

{
  // Set P1 as output
  P1DIR = 0;

  // Configure ADC
  hal_adc_set_input_channel(HAL_ADC_INP_AIN0);
  hal_adc_set_reference(HAL_ADC_REF_VDD);
  hal_adc_set_input_mode(HAL_ADC_SINGLE);
  hal_adc_set_conversion_mode(HAL_ADC_SINGLE_STEP);
  hal_adc_set_resolution(HAL_ADC_RES_8BIT);
  hal_adc_set_data_just(HAL_ADC_JUST_RIGHT);

  while(true)
  {
    hal_adc_start();                                // Start the ADC
    while( hal_adc_busy() )                         // Wait for the ADC to finish a conversion
    {
        }
    P1 = hal_adc_read_LSB();                        // Write the ADC result to P1
  }
}