Hi guys
I am using this chip pic18f24k20, and I need to use RA3 as input. But if RA3 is pull low, it reset/hang my chip. My code seem to work when RA3 is pull high only.
Unfortunately I can't use other pin as this is the only pin left.
According the errata of this chip, I need to do something with the comparator input (which RA3 shares), I have tried a few thing but can't fix it.
Here is the errata:
here is my code:
I am using this chip pic18f24k20, and I need to use RA3 as input. But if RA3 is pull low, it reset/hang my chip. My code seem to work when RA3 is pull high only.
Unfortunately I can't use other pin as this is the only pin left.
According the errata of this chip, I need to do something with the comparator input (which RA3 shares), I have tried a few thing but can't fix it.
Here is the errata:
here is my code:
Code:
ANSEL = 0x00; // disable digital input buffer
ANSELH = 0x00; // disable digital input buffer
HLVDCONbits.HLVDEN = 0; // disable high/low-voltage detection
SSPCON1bits.SSPEN = 0; // disable ssp
CM2CON0bits.C2ON = 0; // disable comparator 2
CM1CON0bits.C1ON = 0; // disable comparator 1
ADCON0bits.ADON = 0; // disable ADC
// these code deal with errata
// 22. Module: Comparators
TRISAbits.TRISA3 = 0; // output
LATAbits.LATA0 = 1; // high
__delay_ms(2);
TRISAbits.TRISA3 = 1; // input
PIE2bits.C1IE = 0; // diable cm1 interrupt
PIE2bits.C2IE = 0; // idable cm2 interrupt
PIR2bits.C1IF = 0; // clear cm1 interrupt flag
PIR2bits.C2IF = 0; // clear cm2 interrupt flag