Hello Guys,
I'm trying to teach myself to program PICs. I'm already familiar with C, so I'm using HI-TECH C compiler (The lite version that came with MPLAB).
I'm using a PIC12F629. IOport 0 to 2 has LEDs, and port 3 is pulled high with a button to ground. If I just do simple pooling in the main, it seems to read the button press just fine so my hardware is ok.
So now I'm trying to get an interrupt when I press that button. However it doesn't seem to work. Here's the source code so far:
Here's a link to the PIC12F629 Datasheet
Thanks, any help is greatly appreciated.
I'm trying to teach myself to program PICs. I'm already familiar with C, so I'm using HI-TECH C compiler (The lite version that came with MPLAB).
I'm using a PIC12F629. IOport 0 to 2 has LEDs, and port 3 is pulled high with a button to ground. If I just do simple pooling in the main, it seems to read the button press just fine so my hardware is ok.
So now I'm trying to get an interrupt when I press that button. However it doesn't seem to work. Here's the source code so far:
Rich (BB code):
#include <pic.h>
#define P1 0x01;
#define P2 0x02;
#define P3 0x04;
void Delay(unsigned short long time);
void Settings();
main()
{
Settings();
GPIO=0;
while(1){
GPIO = P1;
Delay(10000);
GPIO = P2;
Delay(10000);
GPIO = P3;
Delay(10000);
}
}
interrupt isr()
{
GPIO = 0x07; //Turn all three LEDs on
Delay(30000);
GPIF = 0; //Clear the port interrupt bit
}
void Delay(unsigned short long time){
unsigned short long c;
for(c=0; c<time; c++);
}
void Settings(){
TRISIO = 0x08; // declare port as output, and GPIO3 as input
INTCON = 0b10001000; //Enable: Global, Port Change interrupt. Disable: Peripheral, TMR0 Overflow, GP2/INT External interrupt.
IOCB = 0b00001000; // Enable interupt on change for port 3.
}
Thanks, any help is greatly appreciated.