/*
 * File:   led_1.c
 * Author: corrado
 *
 * Created on October 23, 2016, 11:16 AM
 */


#include <xc.h>

void main(void)
{
    int button_1_state, button_2_state;
    long count = 0;
    TRISAbits.TRISA3 = 1;
    TRISAbits.TRISA2 = 1;
    TRISBbits.TRISB0 = 0;
    TRISBbits.TRISB1 = 0;
    TRISBbits.TRISB2 = 0;
    LATBbits.LATB0 = 1;
    LATBbits.LATB1 = 1;
    LATBbits.LATB2 = 1;
    button_1_state = PORTAbits.RA3;
    button_2_state = PORTAbits.RA2;
    for (;;) {  // loop forever
        if (button_1_state != PORTAbits.RA3) {
            // ok, the button has changed state!
            if (PORTAbits.RA3 == 0) {
                // OK!! We have got button press
                LATBbits.LATB0 = !LATBbits.LATB0; // toggle the led
            }
            button_1_state = PORTAbits.RA3;
        }

        if (button_2_state != PORTAbits.RA2) {
            // ok, the button has changed state!
            if (PORTAbits.RA2 == 0) {
                // OK!! We have got button press
                LATBbits.LATB1 = !LATBbits.LATB1; // toggle the led
            }
            button_2_state = PORTAbits.RA2;
        }

        ++count;
        if (count == 200000) {
            LATBbits.LATB2 = !LATBbits.LATB2; // toggle the led
            count = 0;
        }
    }
}
