Displaying string in 8051

Discussion in 'Embedded Systems and Microcontrollers' started by OSOO, May 4, 2014.

  1. OSOO

    Thread Starter Member

    Feb 19, 2014
    34
    0
    Please I want to know how to display a string on LCD using C language in 8051 microcontrollers
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    Displaying a string using C is the same for all microcontrollers, including the 8051.

    You can create your own function that is called with a statement that looks something like:

    LCD_Text("Hello World");
     
  3. OSOO

    Thread Starter Member

    Feb 19, 2014
    34
    0
    MrChips I tried to write string functions but they don't work when executing the code
    also I have copied functions from some websites but they all don't work with me I don't know why.

    this is an example of what I have used :

    void display(char *name)

    {
    int len,i;

    len=strlen(name);
    for(i=0;i<len;i++)
    {


    Also I have a question why we use pointers ,what is the purpose of pointer here ?
     
  4. OSOO

    Thread Starter Member

    Feb 19, 2014
    34
    0
    this is another function:

    this is the function prototype ----> void Send_A_String(char);

    This is the function:

    void Send_A_String(char *StringOfCharacters)
    {
    while(*StringOfCharacters > 0)
    {
    dat(*StringOfCharacters++);
    }
    }



    but unfortunately nothing works !
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    LCD_Text( )

    display( )

    Send_A_String( )

    are all examples of a function that you can create yourself to output a string.

    Before you can output a string you have to be able to output a single character.

    So your next task is to write a function such as

    putc(char ch)
     
    OSOO likes this.
  6. Arm_n_Legs

    Active Member

    Mar 7, 2007
    183
    10
    What kind of LCD are you using? Is it based on the HD44780 chip with a paralle 8-bit data, a Enable pin, and a RS pin?
     
    OSOO likes this.
  7. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,388
    497
    ^ This.

    In my project I used lcd that talked to uC using i2c. 8051 does not normally use i2c to talk to lcd. In my class on uC we used 8-bit and 4-bit setup for 8051 to talk to lcd. So we ask you to provide the hardware details, if you want help that is...
     
    OSOO likes this.
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Strings in C by design all end in a zero, so you can loop simply by using:
    Code ( (Unknown Language)):
    1. void display(char *name)
    2.     {
    3.     while(*name)
    4.     {
    5.         //output each character *name
    6.         name++;        // increment the pointer
    7.     }
    8. }
    9.  
    You pass the pointer to the string instead of the string itself as this is far more efficient: you just pass 1 element (the pointer) instead of an indeterminate and possibly large number of characters.
     
    OSOO likes this.
  9. OSOO

    Thread Starter Member

    Feb 19, 2014
    34
    0
    Thank you all, now everything is all right
     
Loading...