Add ES/Lab/Lab10/ADC.c

This commit is contained in:
aadit 2025-10-16 11:41:54 +05:30
parent dd2c41c0b9
commit 7b53dd846e

20
ES/Lab/Lab10/ADC.c Normal file
View file

@ -0,0 +1,20 @@
#include <LPC17xx.h>
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)
{
unsigned long Result;
Result = (LPC_ADC -> ADGDR & (0xFFF << 4)) >> 4 ; // Read 12-bit ADC result
}