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


#include <xc.h>

void main(void)
{
  int button_1_state;
  
  // ... set-up ports by TRIS registers
  TRISAbits.TRISA3 = 1;
  TRISBbits.TRISB0 = 0;
  LATBbits.LATB0 = 1;
  int button_1_state = PORTAbits.RA3;
  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;
    }
  }
}
