serial data transmission in 8051

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
hii,

I have been trying in vain to transmit and receive a string in 8051.
First character gets displayed on the lcd, but the rest do not.  I
shorted RXD and TXD pins.  The code in c is as follows:

void main()
{
unsigned char char_to_write[] = "hello, this is the data";
RECEIVED = 0;
init_timer();
init_lcd();
initialize_serial();
pass_cmd(0x80);
display_routine(char_to_write);
while(1);
}

void display_routine(unsigned char *this_is)
{
while(*this_is)
    {
    SBUF = *this_is++;
    TI = 1;
    while(!RECEIVED);
    RECEIVED = 0;
    }
}

void init_timer() \for 4800 baud rate
{
TICK = 0;
EA = 1;
ET0 = 1;
TMOD = 1;
TH0 = 0XFC;
TL0 = 0X18;
}

void initialize_serial()
{
SCON = 0X50;
TMOD = 0X20;
TH1 = 0XF3;
TR1 = 1;
EA = 1;
ES = 1;
}


void serialint() interrupt 4
{
if(TI)
    TI = 0;
if(RI)
    {
    pass_data((unsigned char)SBUF); // displays SBUF value on lcd.
    RI = 0;
    RECEIVED = 1;
    }
}

I dont find any problem with lcd display function or timer function.
Any help will be appreciated. Thanx,
digitalBug


Re: serial data transmission in 8051

Quoted text here. Click to load it

I think you lcd rutine is to slow, so the string on the serial port is
transmitted before you have written 1 char in your lcd...

recieve the whole string before you write it to the lcd... or at least move
it out from the IRQ rutine and have a recieve buffer... then you can start
to write out before...

Kasper



Re: serial data transmission in 8051

Quoted text here. Click to load it

Yes, have your serial ISR move the data into a buffer, and nothing else.
Then have your background (app/main/idle) loop polling the buffer for
new data and write to the LCD from there.

Regards,
Mark

Re: serial data transmission in 8051
Hii folk,

It works... Thank you repzak and mark for your generous help.
Sharaf


Site Timeline