***coding for charging circuit
#include <16F877a.h>
//use pic16f877a
#device adc=10 //use
10bit adc detect bat voltage
#use delay(clock=20000000) //clock speed=20mhz
#fuses hs,noprotect,nowdt
//default setting
#define use_portb_lcd TRUE //use portb for lcd
#include <lcd.c>
//call lcd.c library
//enable port a, b, c, d, e
#byte PORTA=5
#byte PORTB=6
#byte PORTC=7
#byte PORTD=8
#byte PORTE=9
long int adc1;
long int adc2;
int mycount=40;
float mybat, mywind;
void main()
{
//initialize system
set_tris_a(0b11111111);
set_tris_b(0b00000000);
set_tris_c(0b00000000);
set_tris_d(0b00000000);
set_tris_e(0b00000000);
setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
output_low(pin_d2); //stop
charging
output_high(pin_d5); //on green led
output_high(pin_d4); //on red led
delay_ms(1000);
output_low(pin_d5);
//off green led
output_low(pin_d4);
//off red led
lcd_init();
lcd_putc("\f");
do
{
if(mycount==40)
{
mycount=0;
//cutoff
charging
output_low(pin_d2);
delay_ms(200);
//read solar
volt
set_adc_channel(0);
delay_ms(10);
adc1=read_adc();
mywind=adc1/65.41;
delay_ms(10);
//read battery volt
set_adc_channel(1);
delay_ms(10);
adc2=read_adc();
mybat=adc2/65.41;
delay_ms(10);
//display
output
printf(lcd_putc,"\fB:%.2f W:%.2f ",mybat, mywind);
if(mybat<12) //if battery <
12V
{
output_low(pin_d5); //off green led
output_high(pin_d4); //on red led
output_high(pin_d2); //charge
battery
printf(lcd_putc,"\nBat Charging
");
}
else //if battery >= 12V
{
output_high(pin_d5); //on green led
output_low(pin_d4); //off red led
output_low(pin_d2); //stop charge
battery
printf(lcd_putc,"\nBat
Not Charging");
}
}
else
{
mycount=mycount+1; //increase
counter
}
delay_ms(250);
}while(1);
}