CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Outputting variables to LCD

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cm279



Joined: 21 Nov 2010
Posts: 6

View user's profile Send private message

Outputting variables to LCD
PostPosted: Sun Nov 21, 2010 6:25 pm     Reply with quote

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 Smile
cm279



Joined: 21 Nov 2010
Posts: 6

View user's profile Send private message

PostPosted: Sun Nov 21, 2010 6:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 21, 2010 7:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 21, 2010 7:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 21, 2010 7:47 pm     Reply with quote

Ahh "%Lu" rather than "%u" compiles.
don't I feel stupid Very Happy

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group