MIT-Curricular/ES/Lab/Lab10/ADC.c
2025-10-16 12:00:37 +05:30

22 lines
657 B
C

#include <LPC17xx.h>
unsigned long result, y; // global variable for ADC result
int main(){
LPC_PINCON -> PINSEL3 = 3 << 28; // P1.30 function 3
LPC_SC -> PCONP = 1 << 12; // power control
// ADCR
LPC_ADC -> ADCR = 1 << 4 | 1 << 16 | 1 << 21 | 1 << 24; // ADC4, burst mode, ADC enable, start now
LPC_ADC -> ADINTEN = (1 << 4); // Interrupt (4th channel to be enabled)
NVIC_EnableIRQ(ADC_IRQn); // Nested Vector Interrupt Controller
while(1){} // infinite delay
}
void ADC_IRQHandler(void)
{
result = (LPC_ADC -> ADGDR & (0xFFF << 4) >> 4 ); // Read 12-bit ADC result
y = (LPC_ADC -> ADDR4 & (0xFFF << 4) >> 4); // Done bit reset
}