Good evening all,
I am attempting to get SW1 on the low pin count demo board that came with my PICKIT2 programmer to trigger an interupt on change and toggle the four led on PortC 0-3. The LED's toggle as the board powers up but then nothing happen when I press the switch. I am using the HITEC C compiled that comes with MPLAD.
C code is:
#include <pic.h>
//PIC16F690 Configuration
__CONFIG (INTIO & WDTDIS & PWRTDIS & MCLRDIS & BORDIS & UNPROTECT & IESODIS & FCMDIS );
//Internal clock, Watchdog off, MCLR internal, Low Voltage Program off,
// Code Unprotected, Clock Switch Disabled
#define DS1 RC0 // Label for LED connection
#define Btn 0b00001000
unsigned char prev_portA = 0;
unsigned char prev_portC = 0;
void
main(void)
{
/* setup stuff */
ANSEL = 0; // Intialize A/D ports off
ANSELH = 0; // Intialize A/D ports off
CM1CON0 = 0; // Initialize Comparator 1 off
CM2CON0 = 0; // Initialize Coparator 2 off
TRISC = 0x00; // RC0 Set to output to drive LED
TRISA3 = 1; // Set RA3 pin to input
IOCA3 = 1; // Enable RA3 IOC
RABIE = 1; // Enable PortA/B IOC
GIE = 1; // Global interrupt enable
PORTC = 0x0C; //turn on DS2 & DS3
while (1==1) // Loop here forever waiting for RA3 interrupts
{
}
}
void interrupt
isr(void) // This is the interrupt service routine
{
if(RABIF) // test if PORTA/B interrupt occurred
{
// if (prev_portA ^ PORTA > 0)
// {
prev_portC = PORTC;
prev_portC = prev_portC ^ 0x0F;
PORTC = prev_portC;
// }
prev_portA = PORTA;
RABIF = 0; // clear the interrupt
}
}
Any ideas on what I should be looking at would be appreciated.
Dom
I am attempting to get SW1 on the low pin count demo board that came with my PICKIT2 programmer to trigger an interupt on change and toggle the four led on PortC 0-3. The LED's toggle as the board powers up but then nothing happen when I press the switch. I am using the HITEC C compiled that comes with MPLAD.
C code is:
#include <pic.h>
//PIC16F690 Configuration
__CONFIG (INTIO & WDTDIS & PWRTDIS & MCLRDIS & BORDIS & UNPROTECT & IESODIS & FCMDIS );
//Internal clock, Watchdog off, MCLR internal, Low Voltage Program off,
// Code Unprotected, Clock Switch Disabled
#define DS1 RC0 // Label for LED connection
#define Btn 0b00001000
unsigned char prev_portA = 0;
unsigned char prev_portC = 0;
void
main(void)
{
/* setup stuff */
ANSEL = 0; // Intialize A/D ports off
ANSELH = 0; // Intialize A/D ports off
CM1CON0 = 0; // Initialize Comparator 1 off
CM2CON0 = 0; // Initialize Coparator 2 off
TRISC = 0x00; // RC0 Set to output to drive LED
TRISA3 = 1; // Set RA3 pin to input
IOCA3 = 1; // Enable RA3 IOC
RABIE = 1; // Enable PortA/B IOC
GIE = 1; // Global interrupt enable
PORTC = 0x0C; //turn on DS2 & DS3
while (1==1) // Loop here forever waiting for RA3 interrupts
{
}
}
void interrupt
isr(void) // This is the interrupt service routine
{
if(RABIF) // test if PORTA/B interrupt occurred
{
// if (prev_portA ^ PORTA > 0)
// {
prev_portC = PORTC;
prev_portC = prev_portC ^ 0x0F;
PORTC = prev_portC;
// }
prev_portA = PORTA;
RABIF = 0; // clear the interrupt
}
}
Any ideas on what I should be looking at would be appreciated.
Dom