hi, i've been trying to enable interrupt on change for GPIO pins 0 and 1 except it doesn't seem to be working...
Could someone take a look at my code and tell me where i'm going wrong, thank you.
pins are held high and get pulled down to trigger interrupt, well that was the aim anyway
Could someone take a look at my code and tell me where i'm going wrong, thank you.
Code:
#include <pic.h>
#include <htc.h>
void init(void)
{
TRISIO=0b00000011; //set GPIO<1:0> as inputs
GPIO=0b11111111; //set GPIO high
IOC=0b00000011; //enable ICO GP0 and GP1
INTCON = 0b10001000; //enable interrupt on change and global interrupts
}
volatile unsigned char zero; //initilise global var flag zero
volatile unsigned char one; //initilise global var flag one
#define SET 1
#define UNSET 0
#define _XTAL_FREQ 8000000
main()
{
init(); //initilise registers
zero=UNSET; //unset flag
one=UNSET; //unset flag
ei(); //enable interrupts
while(1) //wait for a flag to be set by interrupt
{
if(zero == SET)
{
GP4=0; //set GP4 low
zero=UNSET; //unset flag
}
if(one == SET)
{
GP4 = 1; //set GP4 high
one=UNSET; //unset flag
}
}
}
void interrupt my_isr(void)
{
di(); //disable interrupts
if(GP0 == 0) //set correct flag
zero=SET;
if(GP1 == 0)
one=SET;
__delay_us(90);
ei(); //enable interrupts
}
pins are held high and get pulled down to trigger interrupt, well that was the aim anyway
Last edited: