Datasheet

Table Of Contents
PIC18F87J72 FAMILY
DS39979A-page 292 Preliminary 2010 Microchip Technology Inc.
EXAMPLE 22-5: READING DATA FROM AFE DURING INTERRUPT
/////////////////////////////////////////////////////////////////////////////////////////////
// STEP 7: Reading AFE results in Interrupt Routine.
// ADC is configured in 16-bit result mode, thus 16-bit result of each Channel can be read.
// In this example DR is connected to INT0; after each convesion, DR issues interrupt to INT0.
// INT0 is configured as high priority interrupt
////////////////////////////////////////////////////////////////////////////////////////////
#pragma interrupt High_isr_routine
void High_isr_routine(void)
{
char D_S_ADC_data1=0,D_S_ADC_data2=0,D_S_ADC_data3=0,D_S_ADC_data4=0,Dummy_Read=0;
if((INTCONbits.INT0IF)&&(INTCONbits.INT0IE))
{
// Disable all Chip selects of other devices connected to SPI
LATDbits.LATD7=0; //Chip select enable for Delta Sigma ADC
SSP1BUF = 0x01; //Address and Read command for Channel0 result MSB register
while(!SSPSTATbits.BF);
Dummy_Read=SSPBUF; //Dummy read to clear Buffer Full Status bit
SSPBUF =0x00;
while(!SSPSTATbits.BF);
D_S_ADC_data1=SSPBUF; //Data from Channel0 MSB
SSPBUF = 0x00;
while(!SSPSTATbits.BF);
D_S_ADC_data2=SSPBUF; //Data from Channel0 LSB, Address automatically incremented
SSPBUF = 0x00;
while(!SSPSTATbits.BF);
D_S_ADC_data3=SSPBUF; //Data from Channel1 MSB, Address automatically incremented
SSPBUF = 0x00;
while(!SSPSTATbits.BF);
D_S_ADC_data4=SSPBUF; //Data from Channel1 LSB, Address automatically incremented
LATDbits.LATD7=1; //Disable chip select after read/write of registers
INTCONbits.INT0IF=0; //Clear INT0IF for next interrupt
}
}
#pragma code High_isr=0x08
void High_ISR(void)
{
_asm goto High_isr_routine _endasm
}