#include <xc.h>



void setup(void)
{
CTMUCONH = 0x00; //make sure CTMU is disabled
CTMUCONL = 0x90;
CTMUICON = 0b00000010; //0.55uA, Nominal - No Adjustment


/**************************************************************************/
//Setup AD converter;
/**************************************************************************/
OSCCONbits.IRCF = 0b111;    //8Mhz
OSCTUNEbits.PLLEN = 1;  //ppl on 48mhz

LATA=0;
LATB=0;
LATC=0;


ANCON0 = 0b11000000;
ANCON1 = 0b10011110;

TRISC=0b00010100; //set channel 2 as an input
TRISA=0b000111111; //set channel 2 as an input
TRISB=0b00001111;
LATCbits.LC6=1;
ADCON1bits.ADFM=1; // Result format 1= Right justified
ADCON1bits.ADCAL=0; // Normal A/D conversion operation
ADCON1bits.ACQT=1; // Acquisition time 7 = 20TAD 2 = 4TAD 1=2TAD
ADCON1bits.ADCS=1; // Clock conversion bits 6= FOSC/64 2=FOSC/32
ANCON1bits.VBGEN=1; // Turn on the Bandgap
// ADCON0
ADCON0bits.VCFG0 =0; // Vref+ = AVdd
ADCON0bits.VCFG1 =0; // Vref- = AVss
ADCON0bits.ADON=1; // Turn on ADC
//timmer0
INTCONbits.GIE=0;//1
INTCONbits.TMR0IE=0;//1
INTCONbits.TMR0IF=0;
RCONbits.IPEN=0;    //high priority on
T0CONbits.TMR0ON=1;
T0CONbits.T08BIT=0;
T0CONbits.T0CS=0;
T0CONbits.PSA=0;
T0CONbits.T0PS=0b110;

// setp SPI
SSP1CON1 = 0b00110010;
unsigned int k;
for(k=0;k<65000;k++);
SSP1BUF = 0b00000000;

} 