uaveiro-leci/2ano/2semestre/ac2/aula07/part2-1.c

33 lines
755 B
C
Raw Permalink Normal View History

#include <detpic32.h>
int main() {
TRISBbits.TRISB4 = 1;
AD1PCFGbits.PCFG4 = 0;
AD1CON1bits.SSRC = 7;
AD1CON1bits.CLRASAM = 1;
AD1CON3bits.SAMC = 16;
AD1CON2bits.SMPI = 0;
AD1CHSbits.CH0SA = 4;
AD1CON1bits.ON = 1;
IPC6bits.AD1IP = 2; // configure priority of A/D interrupts
IEC1bits.AD1IE = 1; // enable A/D interrupts
IFS1bits.AD1IF = 0; // clear A/D interrupt flag
TRISD &= 0xF7FF; // Configure RD11 as output
EnableInterrupts();
AD1CON1bits.ASAM = 1;
while (1);
}
void _int_(27) isr_adc(void) {
volatile int adc_value;
LATDbits.LATD11 = 0;
adc_value = ADC1BUF0;
IFS1bits.AD1IF = 0;
AD1CON1bits.ASAM = 1;
LATDbits.LATD11 = 1;
}