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 CCS Technical Support

How to display char variable with flex lcd?

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



Joined: 28 Sep 2011
Posts: 12

View user's profile Send private message

How to display char variable with flex lcd?
PostPosted: Wed Sep 28, 2011 1:56 pm     Reply with quote

First of all, thank you very much for the creators / collaborators of this LCD driver! Just with 5 minutes editing I made my project WOW, from 0 to 100% functional! It works just perfectly!!! One question only: how to show the contents of a char variable (I'm using CCS)?

Check my sample below, part of my working code (everything works fine, but the writing of the var):
Code:

sensor = read_adc();   // reads ADC

set_pwm1_duty(sensor);    // set duty of PWM to servo

leitura_caracter = sensor;   // send a int16 to char variable

lcd_putc("\f >> Leitura:\n");  // writes 1st line
lcd_putc(leitura_caracter);     // writes contents of variable

delay_ms(800);

So.... Whats wrong?? The second line of the LCD is always (
_________________
Rubs
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Wed Sep 28, 2011 2:38 pm     Reply with quote

It depends what you want to display....
lcd_putc, displays the _character_. If (for instance), your variable did contain the value 65 (0x41, ob1000001, 65), then you would see the character 'A' displayed, since this is what this number represents.
However you presumably want the numeric value printed out. For this the number would have to be converted into a sequence of ASCII characters, not just the one. The standard tool for this is 'printf'.
So:
Code:

leitura_caracter=65;
lcd_putc(leitura_caracter); //Displays 'A'
printf(lcd_putc,"%ld ",leitura_caracter); //Displays '65'
printf(lcd_putc,"%lu ",leitura_caracter); //Displays '65', but handles 0-255
printf(lcd_putc,"%lx ",leitura_caracter); //displays '41' - hex value
printf(lcd_putc,"%3.1lw ",leitura_caracter); //displays '6.5'

There are others, but these are the commonest integer output formats. The difference between '%u', and '%d', is if the top bit of the value is set, with %d, the value is displayed as a -ve number.
The 'l' says to handle an int16/int32 value, rather than a int8 value.
The last format also important, allowing you to use an integer as a scaled decimal value.

Best Wishes
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