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

Writing String and Character to an LCD

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








Writing String and Character to an LCD
PostPosted: Thu Oct 20, 2005 8:34 am     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 20, 2005 8:53 am     Reply with quote

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.");
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