#include "inttypes.h" #include "stdbool.h" #include "LPC17xx.h" #include "ADC_LPC175x_6x.h" #include "SCU_LPC175x_6x.h" #include "CLOCK_LPC175x_6x.h" int main ( void ) { static uint32_t measCnt = 0, errCnt = 0, temp, last_temp; PINSEL_CFG_Type pinCfg; LPC_SC->PCONP |= CLKPWR_PCONP_PCAD; pinCfg.Funcnum = 1; pinCfg.Pinnum = 25; pinCfg.Portnum = 0; PINSEL_ConfigPin(&pinCfg); LPC_GPIO2->FIODIR |= (1<<5); LPC_GPIO2->FIODIR |= (1<<6); LPC_ADC->ADCR = ADC_CR_PDN; LPC_ADC->ADINTEN = 0; LPC_ADC->ADCR |= (1UL<<2); /* Bits 7:0 Channel select */ LPC_ADC->ADCR |= (6<<8); /* Bits 15:8 ClkDiv */ LPC_ADC->ADCR |= ADC_CR_BURST; /* Start Burst */ __disable_irq(); while ( 1 ) { LPC_GPIO2->FIOSET = (1UL<<6UL); while ( (LPC_ADC->ADGDR & ADC_DR_DONE_FLAG) == 0) {}; LPC_GPIO2->FIOCLR = (1UL<<6UL); temp = ADC_DR_RESULT(LPC_ADC->ADGDR); if ( (temp > last_temp+160) || (temp < last_temp-160) ) { errCnt++; LPC_GPIO2->FIOSET = (1UL<<5UL); } else { measCnt++; LPC_GPIO2->FIOCLR = (1UL<<5UL); } last_temp = temp; } } |