Saturday, 17 May 2014

# problem by stig brad

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

# problem by stig brad
What's wrong with this, it doesn't work 
#include <16f877.h>
#use delay (clock=4000000)
#include "lcd.c"
unsigned int D, Vmax, Vmin, Imin, Vfloat;
void main()
{

setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!

float Lecture, Vbat, read, Ibat;
int1 charge;
charge=0;
Imin=0.8;
Vmax=14.28;
Vfloat=13.4;
Vmin=11;
lcd_init();
lcd_putc("Lecture & envoie\n a lcd");
delay_ms(1000);
lcd_putc("\f");
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_DIV_2);
//setup_adc(ADC_CLOCK_internal);
//setup_adc_ports(ALL_ANALOG);
while(TRUE) {
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_by_16, 100, 1);
set_adc_channel(0);
delay_us(50);
Lecture=read_adc();
Vbat=((Lecture*5)/1023.0)+9.4;
set_adc_channel(3);
delay_us(50);
read=read_adc();
Ibat=((read*4.2)/1023.0);
lcd_gotoxy(1,1);
printf(lcd_putc,"V,I Batterie:\n %fV %fA ", Vbat, Ibat);
delay_us(50);
while(Vbat < 10.5) {output_high(pin_b1); // if Vbat < 10.5V turn on the red Led
lcd_gotoxy(1,4);
printf(lcd_putc,"Discharged batt"); // & display (Discharged battery)
delay_ms(500);
}
if(Ibat > 0.1) {lcd_putc("\f");
lcd_init();
printf(lcd_putc," Battery charger");}
else if (Vbat < Vmin) { charge=1;
D=170;
set_pwm1_duty(D);
delay_ms(6000);
lcd_putc("\f");
lcd_init();
printf(lcd_putc,"Bulk");
break; }
else if (Vbat < Vmax) { if (charge==1) {
for(D=63;D<85;D++)
{set_pwm1_duty(D);
delay_ms(1000);} }
else { lcd_putc("\f");
lcd_init();
printf(lcd_putc,"Floating");
if (Vbat > Vfloat)
{
for(D=85;D>63;D--)
{set_pwm1_duty(D);
delay_ms(1000);} }
else {
for(D=63;D<85;D++)
{set_pwm1_duty(D);
delay_ms(1000);} } } }
else {
for(D=98;D>85;D--)
{set_pwm1_duty(D);
delay_ms(1000);}
if (Ibat > Imin && charge==1)
{ lcd_putc("\f");
lcd_init();
printf(lcd_putc,"Absorption");
Delay_ms(1000); }
else { lcd_putc("\f");
lcd_init();
printf(lcd_putc,"Floating");
if (Vbat > Vfloat)
{
for(D=85;D>63;D--)
{set_pwm1_duty(D);
delay_ms(1000);} }
else {
for(D=63;D<85;D++)
{set_pwm1_duty(D);
delay_ms(1000);}} } }
}
}

0 comments: