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.

[51] Problem in serial communication

Status
Not open for further replies.

TheKnightRider

Newbie level 2
Joined
Jan 27, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,313
Hello,



I am a beginner with 8051 family. I am trying to implement serial communication using 89S52 with PC. The string (rather a singel chracter at this stage) will be transmitted through Hyperterminal and after reception the received text (what ever it be) has to be displayed on LCD. The problem is when I am debugging the code in keil, it's showing proper output i.e. the values at the lcd port are proper ASCII values of particular chracter being entered. But when it comes to hardware, the LCD is showing chracters that seems like those sent by aliens. I am progisp for burning the code, and a kit from HPS electronics. The code i am usin g is as follows:



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
#include <REGX52.H>
sbit rs= P2^0;
sbit rw= P2^1;
sbit en= P2^2;
void msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(unsigned char value)
{
P1=value;
msdelay(5);
rs=0;
msdelay(5);
rw=0;
msdelay(5);
en=1;
msdelay(5);
en=0;
}
void lcd_data(unsigned char value)
{
P1=value;
msdelay(5);
rs=1;
msdelay(5);
rw=0;
msdelay(5);
en=1;
msdelay(5);
en=0;
}
void uart_init()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
void lcd_init()
{
lcdcmd(0x38);
msdelay(10);
lcdcmd(0x0E);
msdelay(10);
lcdcmd(0x01);
msdelay(10);
lcdcmd(0x06);
msdelay(10);
lcdcmd(0x80);
msdelay(10);
} 
void main()
{
unsigned char str;
unsigned int i;
uart_init();
msdelay(250);
lcd_init();
msdelay(250);
while(1)
{
while(RI==0);
RI=0;
str=SBUF;
msdelay(250);
lcd_data(str);
msdelay(250);
}
}



The reason behind introducing so many delays is I thought their may be some latency. Please help.
 
Last edited by a moderator:

I did. And after that tried to run the most basic code to serially transmit the character 'A' continuously. To my surprise what i got is a heart and one more character. On keil simulation, it is perfectly transmitting 'A'. I have checked the serial to USB converter that I am using by shorting its 2 & 3 pin. It transmits each and every character nicely. As far as the burner is concerned, my other simple code such as blinking LED and so on are working fine. I displayed hello world (basic one, just to check LCD) and worked out well. So I am quite puzzled now where the problem is. Changed my MAX232 as well thinking it to be the culprit.

By the way, one more question, a strange thing I noticed with another program if getting an ECHO, once a character was received, the SCON value became 0x55 in place of 0x51 (as the RI sets, 0101 0001). Even after clearing RI, the value becomes 0x54. That calls for RB8 bit to set thus making all further communication meaning less and it doesn't understand 8 bit data anymore. though the problem can be solved by giving SCON 0x50 again and again, but that's certainly not the solution.

please help.
And yes of course, thanks for your reply.

PS:- It receives 'c', 'd' and 'g' nicely8-O
 

:) May be its sent by the Aliens itself, check the baud rate once again.......

- - - Updated - - -

The delays inside the while shd be removed...
 

are you used 8-bit data lines?
and delay's are more than requirement.
Code:
#include <REGX52.H>
sbit rs= P2^0;
sbit rw= P2^1;
sbit en= P2^2;
void msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<120;j++);
}
void lcdcmd(unsigned char value)
{
rs=0;
rw=0;
P1=value;
en=1;
msdelay(5);
en=0;
}
void lcd_data(unsigned char value)
{
rs=1;
rw=0;
P1=value;
en=1;
msdelay(5);
en=0;
}
void uart_init()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
void lcd_init()
{
lcdcmd(0x38);
msdelay(10);
lcdcmd(0x0E);
msdelay(10);
lcdcmd(0x01);
msdelay(10);
lcdcmd(0x06);
msdelay(10);
lcdcmd(0x80);
msdelay(10);
} 
void main()
{
unsigned char str;
unsigned int i;
uart_init();
lcd_init();
while(1)
{
while(RI==0);
RI=0;
str=SBUF;
msdelay(250);
lcd_data(str);
msdelay(250);
}
}

try this one i am also not tested just arrange your code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top