PICKIT2 Demo board (PIC16F690) Interupt on Change

Discussion in 'Embedded Systems and Microcontrollers' started by fatoms, Mar 22, 2010.

  1. fatoms

    Thread Starter New Member

    Oct 25, 2009
    4
    0
    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
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Be awere of the fact then using the demo board with Pickit 2 the MCLR or RA3 input is controlled from the Pickit. So the button will not work. You may use RA0 (the pot) or control the RA3 from MPLAB toolbar->programmer-> Release from Reset (Hold in Reset)
     
  3. fatoms

    Thread Starter New Member

    Oct 25, 2009
    4
    0
    t06afre,

    Thanks for the hint. I did a Release from Reset and it is now working as expected.

    Dom
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The PIckit low pin count demo board is somewhat clumsy on this point. I very quickly got frustrated by this board so I soldered up my own demo board tailored to my preferences, and used a chip wich supported debugging via Pickit 2. I recommend the same to you. Either bread board or solder.
     
Loading...