View previous topic :: View next topic |
Author |
Message |
cm279
Joined: 21 Nov 2010 Posts: 6
|
Outputting variables to LCD |
Posted: Sun Nov 21, 2010 6:25 pm |
|
|
Hey folks, Just wondering if anyone would be able to help out..
I've written a simple code that outputs text to LCD fine, however I'm having problems working out how to display variables, in particular the value read by an ADC. My code is below:
Code: |
#include "16F690.h"
#device ADC=10
#fuses XT,NOPROTECT,NOWDT,INTRC,BROWNOUT
#use delay(clock=4000000, INTERNAL)
//#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)
#include "flex_lcd.c"
int16 adc1;
void main()
{
// Initialisation
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init(); // Initialise LCD
// Configure Ports
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN0 | VSS_VDD);
set_adc_channel(0);
// Main code
while(TRUE){
adc1 = read_adc();
delay_ms(1000);
lcd_putc("\fADC Value is:\n");
lcd_putc(adc1);
}
}
|
Basically the 10-bit adc is reading into adc1 variable (16-bit) and is right justified due to the "#device ADC=10 " I presume?
The LCD line 1 displays "ADC Value is:" as expected then I get a spurious character response from the line 2 which does change upon varying the analogue input. I'm assuming these characters represent ASCII symbols relating to the 10bit adc value..
How can I get it to display a decimal value 0-1023?
Im sure the solution will be simple? Just I've spent hours searching the forums for an example of this to no avail. Maybe I've not been looking hard enough I don't know.
Any help would be appreciated |
|
|
cm279
Joined: 21 Nov 2010 Posts: 6
|
|
Posted: Sun Nov 21, 2010 6:34 pm |
|
|
I tried
Code: | printf(lcd_putc,"%u",adc1); |
which is similair to what I've seen in other code for displaying variables however I get a compling error:
*** Error 114 "lcd_test.c" Line 42(22,26): Printf format type is invalid :: |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Nov 21, 2010 7:09 pm |
|
|
Quote: |
*** Error 114 "lcd_test.c" Line 42(22,26): Printf format type is invalid ::
|
The compiler error message told you:
- The Line where the error is
- The position in such line where the error is
- The exact description of the error detected
...it expect the same size in the variable declaration and in the printf format. C'mon try for yourself!
Regards |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sun Nov 21, 2010 7:25 pm |
|
|
Hi CM279,
As Humberto has told you, there is a mismatch between your printf data type specifier and your variable type. This is a fairly common problem unless you code in 'C' a fair amount. The compiler manual has a pretty good description of the printf function that includes the information you need to solve the problem!
John |
|
|
cm279
Joined: 21 Nov 2010 Posts: 6
|
|
Posted: Sun Nov 21, 2010 7:47 pm |
|
|
Ahh "%Lu" rather than "%u" compiles.
don't I feel stupid
Been a long day just built the whole circuit up and been programming and soldering for hours miss obvious things when tired I guess!
Thanks very much for the quick response. Super stuff |
|
|
|