i want to display on lcd screen but can't able working 8051 controller.plz anyone chek my code

Thread Starter

khangul

Joined Jan 31, 2015
12
Already covered by MrChips and myself.
I did what you suggest but it show different garbage value on lcd screen. code is below and I also attached picture of display.

Code:
#include<stdio.h>

#include<reg51.h>

//sfr ldata=0xB0;
sbit en =P3^2;
sbit rw =P3^1;
sbit rs =P3^0;
int i,j;
int k;


void delay();
void  lcdcmd (unsigned char );//lcd initialization command function prototype
void lcddata(unsigned char ); //lcd data funtion prototype
void lcdstring(unsigned char *);

 char comm[]={0x01,0x02,0x06,0x0e,0x38};//lcd initialization
//char dat[]={"hafi1z"};// string to show on lcd 
void main(void)

{

 rs = 0;
    rw=0;
    en = 0;

    for(i=0;i<5;i++)
    {
    P2 = comm[i];
    en = 1;
    delay();
    en = 0;
}



delay();
lcddata("welcome"); //data function called





}


void lcddata(unsigned char a)// data funtion
{
rs=0;
rw=0;
en=0;

//ldata=value;
//for(k=0;k<8;k++)
// {

P2= a;//[k];
rs=1;
en=1;
delay();
en=0;
//}
}
void lcdstring( unsigned char *value)// string function
{
while(*value)
lcddata(*value++);
}


void delay() //delay function
{
for (j=0;j<300;j++)
for (k=0;k<=50;k++);

}
 

Attachments

Thread Starter

khangul

Joined Jan 31, 2015
12
Code:
from this code I only get the first character on LCD screen
#include<stdio.h>

#include<reg51.h>

sfr ldata=0xB0;
sbit en =P3^2;
sbit rw =P3^1;
sbit rs =P3^0;
int i;
int j;
unsigned char k;

void delay();

void  lcdcmd (unsigned char a[]);//lcd initialization command function prototype
void dataa(unsigned char b[]); //lcd data funtion prototype

 char comm[]={0x01,0x02,0x06,0x0e,0x38};
 char dat[]={"hafi1z"};
void main()

{

   
while (1)
{


lcdcmd(comm);
delay();
//dataa(dat); //data function called
rs=0;
rw=0;
en=0;

 for(k=0;k<6;k++)
 {rs=1;

 P2= dat[k];
 en=1;
 delay();
 en=0;
return;
 }


}


}
void lcdcmd(unsigned char a[])
{
P2=0x80;
rs=0;
rw=0;
en=0;
for(i=0;i<5;i++)
    {   
    P2 = a[i];
    en = 1;
    delay();
    en = 0;

      }
   }
/*void dataa(unsigned char b[])// data funtion
{
rs=0;
rw=0;
en=0;

 for(k=0;k<6;k++)
 {rs=1;

 P2= b[k];
 en=1;
 delay();
 en=0;
return;
 }

  }*/





void delay() //delay function
{
 for (j=0;j<300;j++)
    for (k=0;k<=50;k++);

    }
 

Thread Starter

khangul

Joined Jan 31, 2015
12
I want to thank you all for your beautiful comments. At-last i succeed what i want to do.
I did it with do while loop not with the pointer whom you people suggest me, but i will try to do it with this way also.
Now please can anyone tell me how to do it for single time . I don't want to clear LCD screen again and again.
Please find attach of y circuit diagram.
 

Attachments

takao21203

Joined Apr 28, 2012
3,702
I want to thank you all for your beautiful comments. At-last i succeed what i want to do.
I did it with do while loop not with the pointer whom you people suggest me, but i will try to do it with this way also.
Now please can anyone tell me how to do it for single time . I don't want to clear LCD screen again and again.
Please find attach of y circuit diagram.
Check the datasheet for SET RAM ADDRESS command (or something like that).
 

spinnaker

Joined Oct 29, 2009
7,835
I want to thank you all for your beautiful comments. At-last i succeed what i want to do.
I did it with do while loop not with the pointer whom you people suggest me, but i will try to do it with this way also.
Now please can anyone tell me how to do it for single time . I don't want to clear LCD screen again and again.
Please find attach of y circuit diagram.

Your schematic is not of much use now. You have the electronics working.

What matters is the code. Not sure what you mean by "do it a single time". Is the message displaying over and over? If so what displays the message is inside a loop just move it outside the loop.
 
Top