C18 C button example ?

Discussion in 'Embedded Systems and Microcontrollers' started by coden4fun, Feb 14, 2009.

  1. coden4fun

    Thread Starter New Member

    Feb 4, 2009
    Hi, I'm looking for a C18 button example for the PICDEM 2+ board?

    There is example 5 in C18 Getting Started pdf but there is a bug, for if you copy and paste example 5 and setup the pins correctly you only get the buzzer sound, and you can't press any of the 3 buttons to stop the buzzing noise like it says it should do upon building the project successfully.

    Here is the example 5 code

    #include <p18f4520.h> /* for the special function register declarations
    #include <portb.h> /* for the RB0/INT0 interrupt */

    #pragma config OSC = HS
    #pragma config WDT = OFF
    #pragma config LVP = OFF
    #pragma config DEBUG = ON

    void toggle_light (void);

    #pragma code HIGH_INTERRUPT_VECTOR = 0x8
    void high_ISR(void)
    goto toggle_light
    #pragma code

    #pragma interrupt toggle_light
    void toggle_light (void)

    void EnableHighInterrupts (void)
    RCONbits.IPEN = 1; /* enable interrupt priority levels */
    INTCONbits.GIEH = 1; /* enable all high priority interrupts */

    void main(void){
    OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */
    FALLING_EDGE_INT); /* trigger interrupt upon S3 button
    depression */
    CCP1CON = 0x0F;