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.

send data or char 4m hyperterminal to lcd using 89c51

Status
Not open for further replies.
Post your code and I will fix it.
#include <REGX51.H>
sbit rs= P3^5;
sbit rw= P2^1;
sbit en= P3^4;
////////////////////////////////////Delay////////////////////////////////////
void mdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
/// / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / L C D COMMAND////////////////////////////////////
void lcdcmd(unsigned char value)
{
P1=value;
rs=0;
rw=0;
en=1;
mdelay(1);
en=0;
}
void lcd_data(unsigned char value)
{

P1=value;
rs=1;
rw=0;
en=1;
mdelay(1);
en=0;
}
/////////////////////////////////STRING LCD////////////////////////////////
void string_lcd(unsigned char *ptr)
{
unsigned int h,j=0;
while(*ptr)
{
h++;
if(h<15)
{
lcd_data(*ptr++);
}
if(h>=15 && h<=31)
{

lcdcmd(0xC0+j);
lcd_data(*ptr++);
j++;

}
if(h>31 && h<47)
{
mdelay(300);
lcdcmd(0x01);
lcdcmd(0x80);
lcdcmd(0x06);
lcd_data(*ptr++);
}
if(h>=47)
{
lcdcmd(0xC0+j);
lcd_data(*ptr++);
j++;
}
//mdelay(250);
//lcdcmd(0x18);
}
// *(ptr++);
}

//INITIALIZATION///////////////////////////////
void uart_init()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
/// / / / / / / / / / / / / / / / / / / / / / / / / / / / / L C D INITIALIZATION//////////////////////////////
void lcd_init()
{
lcdcmd(0x38);
//mdelay(250);
lcdcmd(0x0F);
//mdelay(250);
lcdcmd(0x01);
//mdelay(250);
lcdcmd(0x06);

} //mdelay(250);

void main()
{

unsigned char str2[100],*ptr;
unsigned int i;
ptr=str2;
uart_init();
lcd_init();

while(SBUF!=0x0D) //Checking if the enter is pressed or not
{
while(RI==0);
RI=0;
str2=SBUF;
i++;
}
str2='\0';
string_lcd(ptr);
// To display on LCD
for(i=0;i<6;i++)
{
lcd_data(str2);
}
while(1);
}

i cant understand now.i was trying with my all logics.and by that code i still get 32 char. on lcd but from 33 char only one char get on lcd then starting overwrite on that one code.
 

Try this code

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
void string_lcd(unsigned char *ptr)
{
    unsigned int h,j = 0, k = 0;
    while(*ptr)
    {
        h++;
        if(h<15)
        {
            lcdcmd(0x80 + k);
            lcd_data(*ptr++);
            k++;
            
        }
        else if(h>=15 && h<=31)
        {
 
            lcdcmd(0xC0 + j);
            lcd_data(*ptr++);
            j++;
            
        }
        else if(h>31 && h<47)
        {
            h = 0;
            j = 0;
            k = 0;
            mdelay(300);
            lcdcmd(0x01);
            lcdcmd(0x80);
            lcdcmd(0x06);
            lcd_data(*ptr++);
        }
 
        //if(h>=47)
        //{
            //lcdcmd(0xC0+j);
            //lcd_data(*ptr++);
            //j++;
        //}
        //mdelay(250);
        //lcdcmd(0x18);
        //}
        //  *(ptr++);
        //}
    }
}



What are you printing one character at a time using lcd_data() function in the below code?


Code C - [expand]
1
2
3
4
for(i=0;i<6;i++)
{
       lcd_data(str2[i]);
}



Instead of lcd_data() function to print str2[] can't you use string_lcd(str2); so that string_lcd() functions takes care of printing the data on the two lines of LCD?

If the first code doesn't work then try this code.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
void string_lcd(unsigned char *ptr)
{
    unsigned int h,j = 0, k = 0;
    while(*ptr)
    {
        h++;
        if((h > 31) && (h < 47))
        {
            h = 0;
            j = 0;
            k = 0;
            mdelay(300);
            lcdcmd(0x01);
            lcdcmd(0x80);
            lcdcmd(0x06);
            //lcd_data(*ptr++);
        }       
        else if((h >= 15) && (h <= 31))
        {
 
            lcdcmd(0xC0 + j);
            lcd_data(*ptr++);
            j++;
            
        }
        else if(h < 15)
        {
            lcdcmd(0x80 + k);
            lcd_data(*ptr++);
            k++;
            
        }
        
        
 
        //if(h>=47)
        //{
            //lcdcmd(0xC0+j);
            //lcd_data(*ptr++);
            //j++;
        //}
        //mdelay(250);
        //lcdcmd(0x18);
        //}
        //  *(ptr++);
        //}
    }
}

 
Try this code

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
void string_lcd(unsigned char *ptr)
{
    unsigned int h,j = 0, k = 0;
    while(*ptr)
    {
        h++;
        if(h<15)
        {
            lcdcmd(0x80 + k);
            lcd_data(*ptr++);
            k++;
            
        }
        else if(h>=15 && h<=31)
        {
 
            lcdcmd(0xC0 + j);
            lcd_data(*ptr++);
            j++;
            
        }
        else if(h>31 && h<47)
        {
            h = 0;
            j = 0;
            k = 0;
            mdelay(300);
            lcdcmd(0x01);
            lcdcmd(0x80);
            lcdcmd(0x06);
            lcd_data(*ptr++);
        }
 
        //if(h>=47)
        //{
            //lcdcmd(0xC0+j);
            //lcd_data(*ptr++);
            //j++;
        //}
        //mdelay(250);
        //lcdcmd(0x18);
        //}
        //  *(ptr++);
        //}
    }
}



What are you printing one character at a time using lcd_data() function in the below code?


Code C - [expand]
1
2
3
4
for(i=0;i<6;i++)
{
       lcd_data(str2[i]);
}



Instead of lcd_data() function to print str2[] can't you use string_lcd(str2); so that string_lcd() functions takes care of printing the data on the two lines of LCD?

If the first code doesn't work then try this code.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
void string_lcd(unsigned char *ptr)
{
    unsigned int h,j = 0, k = 0;
    while(*ptr)
    {
        h++;
        if((h > 31) && (h < 47))
        {
            h = 0;
            j = 0;
            k = 0;
            mdelay(300);
            lcdcmd(0x01);
            lcdcmd(0x80);
            lcdcmd(0x06);
            //lcd_data(*ptr++);
        }       
        else if((h >= 15) && (h <= 31))
        {
 
            lcdcmd(0xC0 + j);
            lcd_data(*ptr++);
            j++;
            
        }
        else if(h < 15)
        {
            lcdcmd(0x80 + k);
            lcd_data(*ptr++);
            k++;
            
        }
        
        
 
        //if(h>=47)
        //{
            //lcdcmd(0xC0+j);
            //lcd_data(*ptr++);
            //j++;
        //}
        //mdelay(250);
        //lcdcmd(0x18);
        //}
        //  *(ptr++);
        //}
    }
}

thanks jay
yes i got output on lcd more then 32 char.but here some little new problem is creating suppose i writing "ronak patel ahemdabad123456789101112131415161718192021222324252627282930" then i can see all data in lcd. but when i writhing that same data in two line then only one line can displayed. suppose i writing above same data "ronak patel ahemdabad123456789101112131415[here i pressed ENTER key for new line]
161718192021222324252627282930"
then i can see only this "ronak patel ahemdabad123456789101112131415 data on lcd upto 15 last number
 

What LCD are you using? 2X16? You sent data from usart to lcd? You pressed enter after ...131415 and then typed 161718.... ??
yes i m using 16x2 lcd .i was try send data after pressed Enter .but here in our case when i was pressed enter and then lcd will sow data only .after that if i want send another data then lcd will not accept that input data. and when i m pressing reset button of LCD then only that lcd will show another data
 

Your hex file is not loading in Proteus so I can't check your simulation. I told you not to print str using lcd_data(). After the serial data is read the data is stored in str2[] and converted to string. So, use string_lcd(str2); to print data.
 
Your hex file is not loading in Proteus so I can't check your simulation. I told you not to print str using lcd_data(). After the serial data is read the data is stored in str2[] and converted to string. So, use string_lcd(str2); to print data.

wait i again createView attachment rs232 to lcd.zip a file check it once i think this is working .

- - - Updated - - -

Your hex file is not loading in Proteus so I can't check your simulation. I told you not to print str using lcd_data(). After the serial data is read the data is stored in str2[] and converted to string. So, use string_lcd(str2); to print data.

still not getting output plz help me i m trying updated code buy still not working

- - - Updated - - -

Your hex file is not loading in Proteus so I can't check your simulation. I told you not to print str using lcd_data(). After the serial data is read the data is stored in str2[] and converted to string. So, use string_lcd(str2); to print data.

/ To display on LCD
for(i=0;i<6;i++)
{
string_lcd(str2);
//lcd_data(str2);
}
while(1);
}
i m trying with this code but not working
 

Your code doesn't work. Send a working file which displays some string on lcd then I will help you. See image. All the pins of your MCU is high in Proteus simulation. I am not able to simulate your project. Just create a new project and write code to display some string like "EDABoard" on LCD and post all the project files and working Proteus file.

See this prints text on lcd as you need. lcd2.rar

See lcd2 v2.rar Find out why space is printed in lcd at the end of string and also find out why 1 or 2 character is not printed if lcd goes form line 2 to line 1.
 

Attachments

  • lcd2.rar
    58.6 KB · Views: 49
  • lcd2 v2.rar
    59.5 KB · Views: 49
Last edited:
Your code doesn't work. Send a working file which displays some string on lcd then I will help you. See image. All the pins of your MCU is high in Proteus simulation. I am not able to simulate your project. Just create a new project and write code to display some string like "EDABoard" on LCD and post all the project files and working Proteus file.

See this prints text on lcd as you need. lcd2.rar


See lcd2 v2.rar Find out why space is printed in lcd at the end of string and also find out why 1 or 2 character is not printed if lcd goes form line 2 to line 1.

hy jay
thanks for helping your v2 file i show and i loaded that hex file in 89c51
now i can able to see next data automatically but here .text file is not supported that was supported in old program ?
how that can be able to see any text file sending from pc that may see in 16x2 lcd
 

What is .text file? Which program supported it?

What do you mean by that?

in our old program ,when i was sent .text file via hyper terminal or real term software at that time lcd was show that .text file data.but rightnow in new programm that is not done .getting me what i want to ask you?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top