Clk_Init(); /* Configure clocks to run at 20 Mhz */
GPIO_Init(); /* Configure button pins as inputs and LED pins as outputs */
ADC_Init(3,EIGTH_BIT); /* Configure ADC channel 3 in 8-bit resolution mode */
for(;;) {
counter++;
adc_value=ADC_Read(3); /* Read ADC value from channel 3 */
/* Display ADC value in LED0, LED1, LED2 and LED3*/
adc_value = adc_value >> 4;
GPIOA_PSOR |=adc_value <<16;
adc_value = (char)~adc_value ^ 0b11110000;
GPIOA_PCOR |= (adc_value) << 16;
}
return 0;
}
/***********************************************************************************************
*
* @brief ADC_Init - Initiates the Channel to read the value of the ADC channel
*
* @param Channel to init and resolution
* @return none
*
************************************************************************************************/
void ADC_Init(UINT8 channel, UINT8 mode)
{
SIM_SCGC |= SIM_SCGC_ADC_MASK;
ADC_SC1 = 0 ;
ADC_SC1|= ADC_SC1_ADCO_MASK; /* Continuous mode operation */
ADC_SC3 |= ADC_SC3_MODE(mode); /* 8,10,12 bit mode operation */
ADC_APCTL1 |= ADC_APCTL1_ADPC(1<<channel); /* Channel selection */
}
/***********************************************************************************************
*
* @brief ADC_Read - Read the selected ADC channel
* @param ch - channel to read
* @return result
*
************************************************************************************************/
UINT16 ADC_Read(UINT8 channel)
{
ADC_SC1 |= ADC_SC1_ADCH(channel); /* Select channel to read */
while(!(ADC_SC1 & ADC_SC1_COCO_MASK)); /* Wait conversion to complete */
return ADC_R; /* Return adc value */