Displaying string in 8051

Thread Starter

OSOO

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

MrChips

Joined Oct 2, 2009
35,159
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");
 

Thread Starter

OSOO

Joined Feb 19, 2014
34
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 ?
 

Thread Starter

OSOO

Joined Feb 19, 2014
34
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 !
 

MrChips

Joined Oct 2, 2009
35,159
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)
 

shteii01

Joined Feb 19, 2010
4,644
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?
^ 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...
 

ErnieM

Joined Apr 24, 2011
8,415
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 ?
Strings in C by design all end in a zero, so you can loop simply by using:
Rich (BB code):
void display(char *name)
    {
    while(*name)
    {
        //output each character *name
        name++;        // increment the pointer 
    }
}
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.
 
Top