void SetupPIC(void)
{
//Setup ports
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
PORTA = 0;
PORTB = 0;
PORTC = 0;
//Disable all analog inputs
ANSEL = 0x00;
ANSELH = 0x00;
//Setup USART
TRISBbits.TRISB5 = 1;
TRISBbits.TRISB7 = 1;
//SetupUART();
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
129);
PIE1bits.RCIE = 1; //Enable USART receive interrupt
PIR1bits.RCIF = 0; //Clear USART receive interrupt flag
//Setup FRAM
init_FRAM();
//Setup ADC
init_ADC();
TRISCbits.TRISC6 = 0;
//Setup Timers
//Timer0
T0CON = 0b00000111; //Timer stopped;16-bit timer;
//Internal instruction cycle clock;
//Timer0 prescaler assigned;
//1:256 prescale value
INTCONbits.TMR0IE = 1; //Enable Timer0 interrupts
INTCONbits.TMR0IF = 0; //Clear Timer- interrupt flag
//Setup external interrupts INT0 and INT1
INTCONbits.INT0IF = 0; //Clear the interrupt flag
INTCONbits.INT0IE = 1; //Enable external interrupt INT0
INTCON2bits.INTEDG0 = 0;//Interrupt on the falling edge
PORTCbits.RC0 = 1; //Pull HIGH to create falling edge
//on contact
INTCON3bits.INT1IE = 1; //Enable external interrupt INT1
INTCON2bits.INTEDG1 = 0;//Interrupt on the falling edge
INTCON3bits.INT1IF = 0; //Clear the interrupt flag
PORTCbits.RC1 = 1;
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
}