/* * File: main.c * Author: sheep73 * * Created on 3/4/14, 2:30 PM */ #include #include #include /* * */ void configports() { PORTA=0x00; //set all pin in a to 0; PORTC=0x00; TRISC=0x00;// Set all to output TRISA=0b00000100; // Set pin A2 to input } void light() { int lightval=0; ADCON0=0b10001001;// Set up ADC registers ADCN0 and ADCON1 ADCON1=0b01000000; GO_DONE=1; while(GO_DONE);//Buffer for ADC lightval=((ADRESH<<8)+ADRESL); if(lightval>365) //set to 1.7VV ACD value 365 { PORTC=0b00010000;//port C on } else { PORTC=0b00000000;//Port C off } } void main() { configports(); while(1) { light();//Code to sens the voltage at the light sensonr } }