View previous topic :: View next topic |
Author |
Message |
project2010
Joined: 14 Mar 2010 Posts: 21
|
LCD display keep flashing |
Posted: Sun Apr 25, 2010 7:19 am |
|
|
Code: | #include <18F4620.H>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=2000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <LCD20x4.c>
//============================
void main()
{
int16 adc_value;
float volts;
lcd_init();
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);
while(1)
{
adc_value = read_adc();
volts = (float)(adc_value * 500)/1023.0;
lcd_gotoxy(2,1);
printf(lcd_putc, "\f%3.2fv", volts);
delay_ms(500);
}
} |
printf(lcd_putc, "\f%3.2fC", volts);
if i replaced it by printf(lcd_putc, "%3.2fC", volts);
it will not keep flashing ,
but if the volt under 10 such as 9.56 it will display 9.56vv
it loop the \f.....
how can i solve it ? thank you
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Apr 25, 2010 10:25 am |
|
|
The problem is that your input voltage is higher than the Vref.
Using:
setup_adc_ports(AN0); // The +5v is used as a Vref.
I gues that you are using a Vin/2 voltage divider.
When the input voltage is higher than 10.0V, let says 10.6V you get:
(10.6V*500)/1023= 5.18V
You need to recalculate the voltage divisor in the input AN0 in order that Vin
by no way should be higher that +5V.
Humberto
Last edited by Humberto on Sun Apr 25, 2010 10:34 am; edited 2 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
project2010
Joined: 14 Mar 2010 Posts: 21
|
|
Posted: Sun Apr 25, 2010 10:44 am |
|
|
Humberto wrote: | The problem is that your input voltage is higher than the Vref.
Using:
setup_adc_ports(AN0); // The +5v is used as a Vref.
I gues that you are using a Vin/2 voltage divider.
When the input voltage is higher than 10.0V, let says 10.6V you get:
(10.6V*500)/1023= 5.18V
You need to recalculate the voltage divisor in the input AN0 in order that Vin
by no way should be higher that +5V.
Humberto |
oh...i just made and example....i have not focus on the voltage...
you're right, the v max must be=<5V
Anyway thank you for your reply. |
|
|
project2010
Joined: 14 Mar 2010 Posts: 21
|
|
Posted: Sun Apr 25, 2010 10:45 am |
|
|
thank you PCM programmer:grin: , problem fixed.
This is the only way to fix it? add a if() |
|
|
project2010
Joined: 14 Mar 2010 Posts: 21
|
|
Posted: Sun Apr 25, 2010 11:14 am |
|
|
i try it that's good.
i also found if i use %3.0f it can auto provide a space before the no.
_88 <like this |
|
|
|