|
|
View previous topic :: View next topic |
Author |
Message |
quichedood
Joined: 02 Feb 2004 Posts: 5
|
Show a value on lcd, got a "/" :( |
Posted: Mon Feb 02, 2004 3:09 pm |
|
|
hi everybody,
i'm new to ccs, and i try to realize my project.
i've done some functions who works but i'm locked on something who looks very easy :p
so here a part of my code :
Code: |
int temperature;
char mystring[21];
//send a char to lcd
void send_char(char str_eight){
output_high(LCD_RS);
trait_eight = align1(str_eight);
OUTPUT_A (trait_eight);
enable_lcd();
trait_eight = align2(str_eight);
OUTPUT_A (trait_eight);
enable_lcd();
}
//Send a value to lcd
void send_value(int value){
sprintf(mystring,"%u",value);
send_char(mystring);
}
temperature = 65;
send_value(temperature);
|
ok so here is the problem the function "send_char" works fine
example : send_char("test"); -> "test" is writtent on my lcd
BUT, now i would like to show the content of "temperature" (who's 65)
so i use the other function : "send_value" but that write a "/" on my lcd.
if someone could help me it would be great
(sorry for my english, but i think you can understand )
DooD |
|
|
Ttelmah Guest
|
Re: Show a value on lcd, got a "/" :( |
Posted: Mon Feb 02, 2004 4:38 pm |
|
|
quichedood wrote: | hi everybody,
i'm new to ccs, and i try to realize my project.
i've done some functions who works but i'm locked on something who looks very easy :p
so here a part of my code :
Code: |
int temperature;
char mystring[21];
//send a char to lcd
void send_char(char str_eight){
output_high(LCD_RS);
trait_eight = align1(str_eight);
OUTPUT_A (trait_eight);
enable_lcd();
trait_eight = align2(str_eight);
OUTPUT_A (trait_eight);
enable_lcd();
}
//Send a value to lcd
void send_value(int value){
sprintf(mystring,"%u",value);
send_char(mystring);
}
temperature = 65;
send_value(temperature);
|
ok so here is the problem the function "send_char" works fine
example : send_char("test"); -> "test" is writtent on my lcd
BUT, now i would like to show the content of "temperature" (who's 65)
so i use the other function : "send_value" but that write a "/" on my lcd.
if someone could help me it would be great
(sorry for my english, but i think you can understand )
DooD |
This is not a CCS problem, but a general 'C' one...
The function 'send_char', expects to receive a single character. It only works with the 'constant' string 'test', because CCS has a 'shortcut', that if a constant string is handed to a function expecting single characters, it will automatically call the function repeatedly to send the individual characters. When you call the function with 'mystring', the _address_ of the RAM string is handed to the function, which happens to display as a '/'...
You can work two different ways. The first is to write 'send_string' function, that takes the address, and steps through the characters one by one, till it sees the end of string ('/0') marker, so:
Code: |
void send_string(char *str) {
while (*str!='\0') send_char(*str++);
}
|
Then call this instead of send_char inside send_value.
or simply use printf, rather than sprintf (which supports sending the output to a function, rather than to a string), so:
Code: |
//Send a value to lcd
void send_value(int value){
printf(send_char,"%u",value);
}
|
You then don't need 'mystring' at all.
Best Wishes |
|
|
quichedood
Joined: 02 Feb 2004 Posts: 5
|
|
Posted: Tue Feb 03, 2004 2:53 pm |
|
|
thanks a lot for your reply ... but it doesn't work anyway :D
here is the code :
Code: | //Send a string to lcd
void send_string(char *str) {
while (*str!='\0') {
send_char(*str++);
}
}
//Send a value to lcd
void send_value(int value) {
printf([b]send_string[/b],"%u",value);
} |
the text in bold is a little correction of what you give me (good isn't it ?)
so if anyone have an idea... I will look at it tonight, i'll keep you informed if something works
EDIT : for value=65 it write "q q" on lcd if it can help someone
(not real "q" that's the letter who correspond to this char code : 11100111)
http://home.iae.nl/users/pouweha/lcd/lcd.shtml
EDIT2 ( ) : send_string function doen't work correctly (when using it without send_value function) |
|
|
quichedood
Joined: 02 Feb 2004 Posts: 5
|
|
Posted: Tue Feb 03, 2004 3:46 pm |
|
|
ok so here is my result :p
with that code :
Code: | //Envoi d'une chaine au lcd
void send_string(char *str) {
while (*str!='\0') {
send_char(*str++);
}
}
//Envoi une valeure au lcd
void send_value(int value) {
sprintf(mystring,"%u",value);
send_string(mystring);
} |
sending a value works great (thx !!!)
sending a string using send_char works
sending a string using send_string doesn't work
so why the last one doesn't work ? it should no ? |
|
|
quichedood
Joined: 02 Feb 2004 Posts: 5
|
|
Posted: Tue Feb 03, 2004 4:15 pm |
|
|
little screenshot
but sending a string using send_string doesn't work better |
|
|
Guest
|
|
Posted: Tue Feb 03, 2004 4:30 pm |
|
|
quichedood wrote: | ok so here is my result :p
with that code :
Code: | //Envoi d'une chaine au lcd
void send_string(char *str) {
while (*str!='\0') {
send_char(*str++);
}
}
//Envoi une valeure au lcd
void send_value(int value) {
sprintf(mystring,"%u",value);
send_string(mystring);
} |
sending a value works great (thx !!!)
sending a string using send_char works
sending a string using send_string doesn't work
so why the last one doesn't work ? it should no ? |
You are misunderstanding what I posted.
The second example I gave, was an _alternative_ to the first.
You can just use:
Code: |
//Send a value to lcd
void send_value(int value){
printf(send_char,"%u",value);
}
|
The printf function, will call the function given as the first variable, for each character in turn. The 'send_string' routine, was designed to take a string input, if you needed/wanted to do it this way. The printf example would work as posted. Your 'modification', is _wrong_, because the 'send_string' function, expects to receive the _address_ of a string, while the function used by printf, is expected to receive a single character. You are repeating the same mistake...
Best Wishes |
|
|
quichedood
Joined: 02 Feb 2004 Posts: 5
|
|
Posted: Wed Feb 04, 2004 2:50 pm |
|
|
oops sorry, i re-test like you said and all it's ok
so thx a lot once more for the solution and all your explications !
i'll maybe come back later on this forum, very usefull
see you later.
DooD |
|
|
|
|
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
|