How does this function work for displaying string in lcd?

Status
Not open for further replies.

94d33m

Junior Member level 2
Joined
Oct 30, 2016
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
155
Code:
lcd_string("welcome"); 

void lcd_string(unsigned char *p)
{
     while(*p!=0)
    {
           lcd_char(*p++);
     }
}

void lcd_char(unsigned char cha)
{
       lcd_data_port=cha;
       rs=1;
       rw=0;
       en=1;
      delay(10);
      en=0;
}

How does the function lcd_string work?
 

lcd_char() puts a single character code on the LCD data lines then operates the control lines to write it to the LCD module. If the delay(10); is 10mS it can be considerably shortened!

lcd_string() takes the string and keeps callling lcd_char, passing it one character from the string at a time until it finds a NUL (zero) character. Strings in 'C' are stored with a NUL at their end so it uses it as a marker to say 'no more' after all the characters have been displayed.

Brian.
 
Reactions: 94d33m

    94d33m

    Points: 2
    Helpful Answer Positive Rating
and does lcd_char(*p++) mean it sends the value to the function first then increases its value ??
 

Yes, by C syntax rules. That's why we call it a postfix increment operator.
 
Reactions: 94d33m

    94d33m

    Points: 2
    Helpful Answer Positive Rating
does lcd_char(*p++) mean it sends the value to the function first then increases its value ??

To be more clear, it sends the character (dereferenced by the pointer 'p') and then increments the pointer 'p' (post-incrementing), after this 'p' points to the next character.
 
Reactions: 94d33m

    94d33m

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…