#include "LPC17xx.h" //****** ADC variables and arrays ******// unsigned int adc_result[5];//adc_result array to store results from the different channels int main(void) { //A/D Converter is powered on LPC_SC->PCONP |= 1<<12; //set P0.23 as AD0.0 LPC_PINCON->PINSEL1 |= (0x1 << 14); //Set PINMODE of AD0.0 as no pull-up/down resistors LPC_PINCON->PINMODE1 |= (0x2 << 14); //select AD0.0, CLKDIV = 4+1 => 25MHz/5 = 5MHz < 13MHz, power on LPC_ADC->ADCR |= (1 << 0) | (4 << 8) | (1 << 21); //start conversion LPC_ADC->ADCR |= (1 << 24); //wait for conversion to finish by checking ADGDR.31 while((LPC_ADC->ADDR0 & (1<<31)) == 0); //return conversion result adc_result[0] = ((LPC_ADC->ADDR0 >> 4) & 0xFFF); // Enter an infinite loop, just incrementing a counter volatile static int i = 0 ; while(1) { i++ ; } return 0 ; } |
//A/D Converter is powered on LPC_SC->PCONP |= 1<<12; //set P0.23 as AD0.0 [COLOR=Red]LPC_PINCON->PINSEL1 &= ~(3<<14);[/COLOR] LPC_PINCON->PINSEL1 |= (1<<14); //Set PINMODE of AD0.0 as no pull-up/down resistors [COLOR=Red]LPC_PINCON->PINMODE1 &= ~(3<<14);[/COLOR] LPC_PINCON->PINMODE1 |= (2<<14); //select AD0.0, CLKDIV = 4+1 => 25MHz/5 = 5MHz < 13MHz, power on LPC_ADC->ADCR[COLOR=Red] = [/COLOR](1 << 0) | (4 << 8) | (1 << 21); //start conversion LPC_ADC->ADCR |= (1 << 24); //wait for conversion to finish by checking ADGDR.31 while((LPC_ADC->ADDR0 & (1<<31)) == 0); //return conversion result adc_result[0] = ((LPC_ADC->ADDR0 >> 4) & 0xFFF); |