![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Guest
|
Writing String and Character to an LCD |
Posted: Thu Oct 20, 2005 8:34 am |
|
|
How come when I use the following functions, lcd_putch and lcd_write, with strings it works? I understand why it works with just one character but how does it work when I send a string?
When I send
lcd_putch('c');
the lcd displays c
When I send
lcd_putch("string");
the lcd displays string.
Why does this work??? Shouldn't I have to write each letter of the string separately?
for instance...
lcd_putch('s');
lcd_putch('t');
lcd_putch('r');
lcd_putch('i');
lcd_putch('n');
lcd_putch('g');
then the LCD displays string
Here are the two functions I'm using...
Code: |
void lcd_write(unsigned char c) {
//high order bit first
output_high(LCD_EN); //set enable high
output_bit(LCD_D7,c & 0x80); //put each bit on separate line
output_bit(LCD_D6,c & 0x40);
output_bit(LCD_D5,c & 0x20);
output_bit(LCD_D4,c & 0x10);
output_low(LCD_EN); //set enable low
//now low order bit
output_high(LCD_EN); //set enable high
output_bit(LCD_D7,c & 0x08); //put each bit on separate line
output_bit(LCD_D6,c & 0x04);
output_bit(LCD_D5,c & 0x02);
output_bit(LCD_D4,c & 0x01);
output_low(LCD_EN); //set enable low
delay_us(40);
}
void lcd_putch(unsigned char c) {
output_high(LCD_RS);
lcd_write(c);
}
|
Everything works, I just want to understand why it works.
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 20, 2005 8:53 am |
|
|
Read this on page 89 (in Acrobat reader) of the CCS manual:
Quote: |
A (non-standard) feature has been added to the compiler to help get
around the problems created by the fact that pointers cannot be created
to constant strings.
A function that has one CHAR parameter will accept a constant string
where it is called. The compiler will generate a loop that will call the
function once for each character in the string.
Example:
void lcd_putc(char c ) {
...
}
lcd_putc ("Hi There."); |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|