I am a fairly proficient user with Microchip products, however this is the first time using an 8 pin device. It is killing me! Is there some tricks to getting the GPIO so that I can do testing to see which GPIO pin changed state? Below is the offending code:
void interrupt() {
if (TMR0IF_bit) {
Cnt++; // increment counter
if (Cnt >= CNT_TO_1_SEC) { // 1 second has gone by
Elapsed_Time++;
Cnt = NULL;
}
TMR0IF_bit = NULL; // clear TMR0IF
TMR0 = INIT_VALUE;
}
if (GPIF_bit) { // A GPIO pin changed
rc = GPIO;
switch (rc) {
case (rc & 0b00100000): // GPIO 5 changed
GPIO = 0b00000001; // turn on red led at GPIO 0
break;
case (rc & 0b00010000) : // GPIO 4 changed
GPIO = 0b00000010; // turn on green led at GPIO 1
break;
}
}
GPIF_bit = NULL; // clear GPIF
}
}
My configuration settings:
OPTION_REG = 0x84; //pullup disabled. prescaler to TMR0 1:32 prescaler
GPIO = 0x00; // init GPIO
OSCCON = 0x71; // internal osc at 8 mhz
ANSEL = 0x00; // set pins to digital
TRISIO = 0x38; //0,1,2 out;3,4.5 in
TMR0 = 96; // Timer0 initial value
INTCON = 0xA8; // Enable Global, TMRO and IOC interrupts
IOC = 0x30; // ChargerDetected and MagnetDetected
CMCON0 = 0x07; //comparator off digital I/O
Problem:
If I change GPIO.4 an interrupt occurs, however the red led lights which seems to indicate that GPIO.5 changed. GPIO.5 behaves correctly.
Can anyone see what I am doing wrong?
Thanks
Juan M. Nuncio