Interrupts on 12F683

(instructions, reset, WDT, specifications...) PIC10F2xx, PIC12F5xx, PIC16F5x

Interrupts on 12F683

Postby jmnuncio » Thu Oct 16, 2014 4:42 pm

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
jmnuncio
 
Posts: 1
Joined: Thu Oct 16, 2014 4:11 pm
PIC experience: Experienced Hobbyist

Re: Interrupts on 12F683

Postby jtemples » Thu Oct 16, 2014 11:33 pm

Which compiler is letting you do "case (rc & 0b00010000):"? That's not standard C, and I wouldn't expect it to work.
jtemples
Verified identity
 
Posts: 160
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: Interrupts on 12F683

Postby Olin Lathrop » Fri Oct 17, 2014 3:15 pm

jmnuncio wrote:I am a fairly proficient user with Microchip products,

You should be able to see for yourself that your code is formatted to oblivion. No thanks.
User avatar
Olin Lathrop
Verified identity
 
Posts: 48
Joined: Fri May 30, 2014 3:38 pm
Location: Littleton, MA USA
PIC experience: Professional 5+ years with MCHP products

Re: Interrupts on 12F683

Postby ric » Sat Oct 18, 2014 6:56 am

Here's the same code with "code" tags around it:
Code: Select all
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
My new leslie-special website (for fans of The Great Race) :)
User avatar
ric
Verified identity
 
Posts: 391
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Interrupts on 12F683

Postby ric » Sat Oct 18, 2014 7:01 am

... and I agree with jtemples. Your case statements are nonsense.
Try changing:
Code: Select all
      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;

to
Code: Select all
        if (rc & 0b00100000)            // GPIO 5 changed
            GPIO = 0b00000001;          // turn on red led at GPIO 0
         
        if (rc & 0b00010000)            // GPIO 4 changed
            GPIO = 0b00000010;          // turn on green led at GPIO 1
My new leslie-special website (for fans of The Great Race) :)
User avatar
ric
Verified identity
 
Posts: 391
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to 12-Bit Core

Who is online

Users browsing this forum: No registered users and 1 guest

cron