Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How does this function work for displaying string in lcd?

Status
Not open for further replies.

94d33m

Junior Member level 2
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.
 
  • Like
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.
 
  • Like
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.
 
  • Like
Reactions: 94d33m

    94d33m

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

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top