We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am a beginner to C language... I have alreaady initialized the LCD in my code...How do i display a message("HELLO" eg.) to LCD? I want to use it in function void but i do not know where to start...I want to make it simple if possible...There are samples that i found but the samples are complicated...
I try to write it in this way...I am trying to display the letter 'c' to my 8x2 LCD but a line of square dots keep on displaying on the LCD,without displaying a letter.
void lcdwrite(char *letter) { while(*letter) { lcddata(*letter); letter++; } } void main() { Init_Device(); lcdinit(); lcd_clear(); lcdwrite('c'); }
http://www.keil.com/forum/docs/thread10256.asp
Your definition of lcdwrite has:
void lcdwrite(char *letter)
but your call to it is
lcdwrite('c');
Spot the mismatch?
The lcdwrite function expects not a character but a pointer to a character or rather a pointer to a number of characters in wich the last character has the value 0x00. This is called a nullterminated string. So it would be better to make the function call look like this:
lcdwrite("Hello world")
Was there no warning message by the compiler?
It seems I am way too slow in posting...
mate,
Our teech told us about this two weeks ago. Look at your revision notes on page 3 where he even gave us an example!
"Look at your revision notes on page 3"
That's the trouble with having all your documentation separate from the source code!
Learn the habit now of always fully-commenting your code (with specific references to external documents where necessary)
For example: All functions should have a descriptive header; All variable definitions should clearly state their purpose, usage, range of values, units of measure, etc
eg
// Write a null-terminated string to the LCD void lcdwrite ( char *letter // Input: pointer to the string to write ) { while(*letter) { lcddata(*letter); letter++; } }
Think also that "letter" was not a good choice of name for the parameter, was it?
Ya that "letter" was not a good choice of name for parameter... But i still don't get any message displayed on my LCD...Not even a cursor..All i get are row of square dots...
Mr Alias,
go back and look at teech's notes. The code DOES work. I know, im using it here!
" i still don't get any message displayed on my LCD"
If you haven't corrected the call to the function, then it still won't work, will it?
Post your corrected code!
I am not sure what you want to do, or how lcddata() works changing 'c' to "c" may help. It appears that you want to call lcddata() until you get a null ('\0') Other wise you are getting the data from Code address 99d then writing until you find a zero in memory
void lcdwrite(char *letter) { while(*letter) { lcddata(*letter); letter++; } } void main() { Init_Device(); lcdinit(); lcd_clear(); lcdwrite("c"); // This maybe right }
I change name and code to this:
void lcdwrite(char diget) { while(diget) { lcddata(diget); diget++; } }
now i get a different characters on screen.
what else can i try?
How do you suppose that will work?
Think about what the 'while' will do...
"what else can i try?"
Look back throughh this thread, and think about what "null-terminated string" means - look it up in your textbook, class notes, etc...
Now who's using my new nick or trying to be me?? I didn't wrote that...I am Fitri Nickolasky aka Fiddy Geeky...
Guys,just wanna check with you guys whether Did i configure the ports correctly??I connected the following pins of my LCD to 8051: RS to PORT 2.5, RW to PORT 2.6 ,E to PORT 2.7 and my data pins to PORT 3.0-3.7...
void Port_Init() { PRT3CF = 0xFF; P2MODE = 0x1F; }
Fiddeley,
WTF is the PRT3CF register?
youre usin an 8052 not an 8051. neither has the PRT3CF or P2MODE register.
youre project is now late mate!
saddos wont answer yer q if yer dont give correct details!