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.

LCD interfacing with 8051 serial inteface

Status
Not open for further replies.

aliraza786

Full Member level 4
Joined
Nov 10, 2009
Messages
210
Helped
14
Reputation
28
Reaction score
14
Trophy points
1,298
Location
Lahore, Pakistan, Pakistan
Activity points
2,914
hello... i am interfacing LCD with 89c51 and and this uc1 recive data by serial connection... another uc2 send data to uc1 which display on LCD.... but the problem is that when i send data from uc2 to uc1 in this format like "" senddata('A') ''' it display on the lcd connected with uc1 but if i send some value like this,
unsigned char v;
v=5;
senddata(v);

it displays nothing and if i send like this " senddata('v') then it doesnt display 5 but display V......
this is the code of Sending data


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<reg51.h>
#include<stdlib.h>
#include<stdio.h>
unsigned char cd[3];
unsigned char a,b,c,e,f,g,sdata1;
void send(unsigned char d)
{ 
  SBUF=d;
  while(TI==0);
  TI=0;
}
void senddata(unsigned char sdata)
{
 if(sdata>=0 && sdata<=9)
 {
  send('0');
  send('0');
  send(sdata);
 }
 if(sdata>=10 && sdata<=99)
 {
   send(0);
   a=sdata/10 ;
   b=sdata%10 ;
   send(a);
   send(b);
 }
 if(sdata>=100 && sdata<=255)
 {
  c=sdata/100;
  send(c);
  e=sdata%100;
  f=e/10;
  send(f);
  g=e%10;
  send(g);
 }
}
inits()
{
 TMOD=0x20;
 TH1=0xFA;
 SCON=0x50;
 TR1=1;
}
void main()
{ inits();
 while(1)
 {
     sdata1=P2;
     senddata(sdata1);
 }
}
_______________________________________________________________________
Reciver UC1 code
 
while(1)
{
 for(n=0;n<3;n++)
  {
    while(RI==0);
    mydata=SBUF;
    lcddata(mydata);
    RI=0;
  }
  lcdcmd(200);
 for(m=0;m<3;m++)
   {
    while(RI==0);
    mydata=SBUF;
    lcddata(mydata);
    RI=0;
   }
   m=0; n=0; cpo(136);
 }


________________________________________________________
circuit diagram


---------- Post added at 10:13 ---------- Previous post was at 10:12 ----------

i request to the moderator to tell me how to write code properly
 

senddata('5');


try this, before that u are sending the integer value, while u have to send the ascii value..

example
v='5';
then
senddata(v);
this will work..

---------- Post added at 15:30 ---------- Previous post was at 15:28 ----------

I am taking a part of your code...
Code:
if(sdata>=10 && sdata<=99)
{
send(0);
a=sdata/10 ;
b=sdata%10 ;
send(a);
send(b);
}

change it as follow if you want to display it on lcd

Code:
if(sdata>=10 && sdata<=99)
{
send(0);
a=sdata/10 ;
b=sdata%10 ;
a = a | 0x30;       //oring with 0x30 to make i an acii value
b = b| 0x30; 
send(a);
send(b);
}


Hope this helps
 
thnku so much for ur suggestion... my problem is almost solved now... but when i put "0" at the port and read from that port and send the value at this port to uc which is connected to LCD through serial connection. there is unwanted value which i dnt know from where it comes...port is at zero and there will be zeros on both line (sensorL and sensor R both should show 000) but i dnt know upper line show 408 and lower line show right Data.... this is the image of the circuit and the code which i m using for sending...

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
void send(unsigned char d)
{ 
  SBUF=d;
  while(TI==0);
  TI=0;
}
void senddata(unsigned char sdata)
{
 if(sdata>=0 && sdata<=9)
 {
  send('0');
  send('0');
  sdata=sdata | 0x30;
  send(sdata);
 }
 if(sdata>=10 && sdata<=99)
 {
   send('0');
   a=sdata/10 ;
   b=sdata%10 ;
   a=a| 0x30;
   b=b| 0x30;
   send(a);
   send(b);
 }
 if(sdata>=100 && sdata<=255)
 {
  c=sdata/100;
  c=c|0x30;
  send(c);
  e=sdata%100;
  f=e/10;
  f=f|0x30;
  send(f);
  g=e%10;
  g=g|0x30;
  send(g);
 }
}


---------------------
circuit image
 
Last edited by a moderator:

Code:
void senddata(unsigned char sdata)
{
if(sdata>=0 && sdata<=9)
{
send('0');
send('0');
send(sdata);
}
if(sdata>=10 && sdata<=99)
{
send(0);
a=sdata/10 ;
b=sdata%10 ;
send(a);
send(b);
}
if(sdata>=100 && sdata<=255)
{
c=sdata/100;
send(c);
e=sdata%100;
f=e/10;
send(f);
g=e%10;
send(g);
}
}

I personally don't feel this is good logic..
Change this logic as follow:-
Code:
unsigned int  ones, hundreds, tens;
void senddata(unsigned char sdata)
{
ones = sdata % 10;
        sdata = adc_data / 10;
        tens = s_data % 10;
        hundreds = s_data / 10;
//then send it to serial port,
send(0x30 | hundreds);
send(0x30 | tens);
send(0x30 | ones);
}
This code will eliminate the your if else logic and provide and better insight.

Have a look at the code at this link..
https://sites.google.com/site/coole...0/tutorial-list/temperature-monitoring-system

It will help you..


Hope this helps
 
  • Like
Reactions: alexxx

    alexxx

    Points: 2
    Helpful Answer Positive Rating

thanks arun sharma i have little confusion in your logic .... what is the function of adc_data,s_data in your code..?

It's taken from ur first post in this thread..
Have a look at that
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top