[SOLVED] problem in serial port using 89c2051

Status
Not open for further replies.

m2star

Junior Member level 1
Joined
May 1, 2010
Messages
18
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Location
Rawalpindi, Pakistan, Pakistan
Activity points
1,390
i am working on a project, in which i have to receive data serially form PC
and show it on LCD, for this purpose i have to use micro-controller 89c2051
BUT i am facing an annoying problem with serial port,
its is not properly receiving the data which i am sending from PC
i use the following code for bouncing back the received data
but its not not working can anyone help??????????
"

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
INITHW();
uchar RByte;
while(1)
    {
        RECByte();
        SNDByte(RByte);
       }
void INITHW()
{
    TMOD=0x20;  //Timer 1, 8-bit auto-reload
    TH1=0xFA;   //4800 baud rate
    //TL1=0xFA;
    SCON=0x50;  //8-bit , 1 stop bit, REN enabled
    TR1=1;      //start timer 1
}
void RECByte()
{
    while(!RI);
    RByte=SBUF;
    RI=0;
}
void SNDByte(uchar SByte)
{
    SBUF=SByte;
    while(!TI);
    TI=0;   
}


"
 
Last edited by a moderator:

try this
Code:
#include <reg51.h>
main()
{
char c;
// set timer1 in auto reload 8 bit timer mode 2
TMOD=0x20;
// load timer 1 to generate baud rate of 4800 bps
TH1 = 0xFA;
// set serial communication in mode 1
SCON=0x40;
// start timer 1
TR1 = 1;
while(1)
{
// enable reception
REN = 1;
//wait until data is received
while((SCON & 0X02) == 0);
// same as while(RI==0);
// reset receive flag
RI=0;
// read a byte from RXD
c = SBUF;
// disable reception
REN = 0;
 
Reactions: m2star

    m2star

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…