Hello, im making a digital controlled switchmode power supply, and i want to display the voltage and current on a 16x2 lcd controlled by a pic16f886.
the problem is, that I have in one line displaying voltage, and below i have the current being displayed, but the current value is shown over the voltage value as well, Il show you in a picture
As you can see, voltage should display only "5" but instead, it adds the current value after. And its not a simulation bug, it does the same on phyisical
Here is the code:
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
float duty;
float v;
char volt [2];
char amp [6];
float a;
void main() {
TRISA = 1;
PORTA = 0;
TRISB = 0;
TRISC = 0;
PORTC = 0;
C1ON_bit = 0;
C2ON_bit = 0;
ANSEL = 0b00000011;
ANSELH = 0;
PWM1_init(2000);
Pwm1_start();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
duty = 255;
while(1){
a = adc_read(1)*7.35;
v = adc_read(0)*0.02945;
delay_ms(100);
floatToStr(v,volt);
floatToStr(a,amp);
lcd_out(1,1,"V:");
lcd_out(1,4,volt);
lcd_out(2,1,"mA:");
lcd_out(2,4,amp);
pwm1_set_duty(duty);
if(ra2_bit == 1){
delay_ms(150);
duty = duty +10.66;
}
if(ra3_bit == 1){
delay_ms(150);
duty = duty -10.66;
}
if(ra4_bit == 1){
delay_ms(150);
duty = duty-1;
}
if(ra5_bit == 1){
delay_ms(100);
duty = duty+1;
}
if(duty >= 255){
duty = 255;
}
if(duty <=0){
duty = 0;
}
}
}
I cant seem to tell whats wrong, hope you can help me
Thanks for your time