/*
* mbariPic.c
*
* Copyright 2010, MBARI
* Author: EJM
* Date: 15DEC2010
*
* 	This code is a set of small library functions to accompany a 
* 	PIC Microcontroller board running the Microchip PIC24FJ64GA002
*
*/

#include "mbariPic.h"

void initBoard() {
	
	// Configure LED's as outputs
	TRISBbits.TRISB8 = 0;
	TRISBbits.TRISB9 = 0;

	// Map Switches as inputs;
	TRISBbits.TRISB6 = 1;
	TRISBbits.TRISB7 = 1;
}

void ledOn(int n) {
	if (n == 1) {
	    LATBbits.LATB8 = 0;
	} else if (n ==2) {
		LATBbits.LATB9 = 0;
	}
}


void ledOff(int n) {
	if (n == 1) {
	    LATBbits.LATB8 = 1;
	} else if (n==2)  {
		LATBbits.LATB9 = 1;
	}
}

int getSwitch(int swid) {
	int ret = 0;
	int inp = 0;

	if (swid == 1) {
		inp = PORTBbits.RB6;
	} else if (swid == 2) {
		inp = PORTBbits.RB7;
	}

	//invert ret
	if (inp == 1) {ret = 0;}
	if (inp == 0) {ret = 1;}

	return ret;
}






