sbit LED at RC3_bit;
sbit SOLAR_PRESENT at RA4_bit;
sbit Base_ON at RA5_bit;
unsigned int Battery_Value;
int temp1, temp2;
void main() {
//Configuring Microcontroller
CMCON = 0X07 ; // Disbale comparatorss digital
ANSEL = 0x10; // Configure AN4 pin as analog for battery
TRISC3_bit = 0; // PORTC3 (7th Pin) as output
TRISC0_bit = 1; // PORTC0 (10th Pin) as input
TRISA4_bit = 1; // PORTA4 (3rd Pin) as input
TRISA5_bit = 0; // PORTA5 (2nd Pin) as output
//Configuration complete
Delay_ms(200);
//Initializing ADC
ADC_Init();
while(1)
{
//Reading Battery Voltage from 10th pin Port C0
Battery_Value = ADC_Read(4);
LED = 1;
temp1 = 0;
temp2 = 0;
while((SOLAR_PRESENT==0) && (Battery_Value<440))
{
if(!temp1) {
Base_ON = 1;
temp1 = 1;
}
LED = 1;
Delay_ms(500);
LED = 0;
Delay_ms(500);
Battery_Value = ADC_Read(4);
}
while((SOLAR_PRESENT==0) && (Battery_Value>=440))
{
if(!temp2) {
temp2 = 1;
}
Base_ON = 1;
LED = 1;
Delay_ms(2000);
Base_ON = 0;
LED = 0;
Delay_ms(2000);
Battery_Value = ADC_Read(4);
}
if (SOLAR_PRESENT==1)
{
Base_ON = 0;
}
} //while loop end