#include "board.h"
#include <cr_section_macros.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
static ADC_CLOCK_SETUP_T ADCSetup;
Status status;
int adc(char *param1){
uint8_t channel;
uint16_t dataADC = 0;
if(strcmp("2", param1) == 0){
channel = ADC_CH2;
}else if(strcmp("3", param1) == 0){
channel = ADC_CH3;
}else if(strcmp("7", param1) == 0){
channel = ADC_CH7;
}
Chip_ADC_EnableChannel(LPC_ADC, channel, ENABLE);
Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
/* Waiting for A/D conversion complete or timeout */
for (int i = 0; i < 500000; i++) {
if (Chip_ADC_ReadStatus(LPC_ADC, channel, ADC_DR_DONE_STAT) == SET) {
break;
}
}
status = Chip_ADC_ReadValue(LPC_ADC, channel, &dataADC);
Chip_ADC_EnableChannel(LPC_ADC, channel, DISABLE);
return (int)dataADC;
}
int main(void) {
SystemCoreClockUpdate();
Board_Init();
//Configuring ADC pins.
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_1, FUNC2); //ADC2
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_2, FUNC2); //ADC3
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_11, FUNC2); //ADC7
/* ADC Init */
Chip_ADC_Init(LPC_ADC, &ADCSetup);
int measurement2, measurement3, measurement7;
while(1){
measurement2 = adc("2"); //1023 at 3,3V, around 200 when not connected, 0 when connected to GND.
measurement3 = adc("3"); //1023 at 3,3V, around 200 when not connected, 0 when connected to GND.
measurement7 = adc("7"); //between 4 and 6 at 3,3V, 0 when not connected, 0 when connected to GND.
}//Debug breakpoint here to read the values.
return 0 ;
}
|