/*
 * File:   CSCI 255 Stoplight lab
 * Author: Your Name here
 */

#pragma JTAGEN=OFF
#pragma FWDTEN=OFF
#pragma FSOCEN=OFF

#include <xc.h>
#include <stdlib.h>

/*
 * Pins used in lab all on port B
 *   Pin  5 --  RB1  [PGEC1/AN3/C1INC/C2INA/RPB1/CTED12/PMD1/RB1]
 *   Pin  6 --  RB2  [AN4/C1INB/C2IND/RPB2/SDA2/CTED13/PMD2/RB2]
 *   Pin  7 --  RB3  [AN5/C1INA/C2INC/RTCC/RPB3/SCL2/PMWR/RB3]
 *   Pin 16 --  RB7  [TDI/RPB7/CTED3/PMD5/INT0/RB7]
 *   Pin 17 --  RB8  [TCK/RPB8/SCL1/CTED10/PMD4/RB8]
 */

/* All on port B */
#define GREENLED    3
#define YELLOWLED   2
#define REDLED      1

#define LEFTSWITCH  8
#define RIGHTSWITCH 7

void spin(int wastetime) {
    int i ;
    for (i=0; i<wastetime; ++i) ;
}

int main(void) {

    ANSELA = 0 ;           // Set all pins for digital
    ANSELB = 0 ;
    TRISA = 0 ;            // Set all pins for output except for SWITCHES
    TRISB = 0x0180 ;
    CNENA = 0 ;            // Disable change notification
    CNENB = 0 ;
    CNPUA = 0 ;            // Disable weak pullup except for SWITCHES
    CNPUB = 0x0180 ;
    CNPDA = 0 ;            // Disable weak pulldown
    CNPDB = 0 ;
    ODCA = 0 ;             // Disable open drain
    ODCB = 0 ;
    LATA = 0 ;             // Write 0 to output
    LATB = 0 ;

    while(1) {
        spin(100000) ;
        LATBINV = 0x000E ;
    }
    return (EXIT_SUCCESS);
}

