有參考範例程式並修改成如下,但是連中斷都進不了
int main(void)
{
// ADC INITIALIZATION
// Configure the I/O pins to be used as analog inputs.
TRISAbits.TRISA0 = 1;
ANSELAbits.ANSELA0 = 1;
TRISBbits.TRISB2 = 1;
ANSELBbits.ANSELB2 = 1;
// Configure the common ADC clock.
ADCON3Hbits.CLKSEL = 2; // clock from FRC oscillator
ADCON3Hbits.CLKDIV = 0; // no clock divider (1:1)
// Configure the cores’ ADC clock.
ADCORE0Hbits.ADCS = 0; // clock divider (1:2)
ADCORE1Hbits.ADCS = 0; // clock divider (1:2)
// Configure the ADC reference sources.
ADCON3Lbits.REFSEL = 0; // AVdd as voltage reference
// Configure the integer of fractional output format.
ADCON1Hbits.FORM = 0; // integer format
// Select single-ended input configuration and unsigned output format.
ADMOD0Lbits.SIGN0 = 0; // AN0/RA0
ADMOD0Lbits.DIFF0 = 0; // AN0/RA0
ADMOD0Lbits.SIGN1 = 0; // AN1/RA1
ADMOD0Lbits.DIFF1 = 0; // AN1/RA1
// Enable and calibrate the module.
EnableAndCalibrate(); // See Example 5-1
// Configure and enable ADC interrupts.
ADIELbits.IE0 = 1; // enable interrupt for AN0
ADIELbits.IE1 = 1; // enable interrupt for AN1
_ADCAN0IF = 0; // clear interrupt flag for AN0
_ADCAN0IE = 1; // enable interrupt for AN0
_ADCAN1IF = 0; // clear interrupt flag for AN1
_ADCAN1IE = 1; // enable interrupt for AN1
// Set same trigger source for all inputs to sample signals simultaneously.
ADTRIG0Lbits.TRGSRC0 = 13; // timer 2 for AN0
ADTRIG0Lbits.TRGSRC1 = 13; // timer 2 for AN1
// TIMER 2 INITIALIZATION (TIMER IS USED AS A TRIGGER SOURCE FOR ALL CHANNELS).
T1CONbits.TCS = 0; // clock from peripheral clock
T1CONbits.TCKPS = 0; // 1:1 prescale
PR1 = 0x8000; // rollover every 0x8000 clocks
T1CONbits.TON = 1; // start timer to generate ADC triggers
while(1);
return 1;
}
// ADC AN0 ISR
void __attribute__((interrupt, no_auto_psv)) _ADCAN0Interrupt(void)
{
dataAN0 = ADCBUF0; // read conversion result
_ADCAN0IF = 0; // clear interrupt flag
}
// ADC AN1 ISR
void __attribute__((interrupt, no_auto_psv)) _ADCAN1Interrupt(void)
{
dataAN1 = ADCBUF1; // read conversion result
_ADCAN1IF = 0; // clear interrupt flag
}
void EnableAndCalibrate()
{
// Set initialization time to maximum
ADCON5Hbits.WARMTIME = 15;
// Turn on ADC module
ADCON1Lbits.ADON = 1;
// Turn on analog power for dedicated core 0
ADCON5Lbits.C0PWR = 1;
// Wait when the core 0 is ready for operation
while(ADCON5Lbits.C0RDY == 0);
// Turn on digital power to enable triggers to the core 0
ADCON3Hbits.C0EN = 1;
// Turn on analog power for dedicated core 1
ADCON5Lbits.C1PWR = 1;
// Wait when the core 1 is ready for operation
while(ADCON5Lbits.C1RDY == 0);
// Turn on digital power to enable triggers to the core 1
ADCON3Hbits.C1EN = 1;
// Turn on analog power for shared core
ADCON5Lbits.SHRPWR = 1;
// Wait when the shared core is ready for operation
while(ADCON5Lbits.SHRRDY == 0);
// Turn on digital power to enable triggers to the shared core
ADCON3Hbits.SHREN = 1;
}
請問是哪個環節有問題,謝謝