This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to receive character to P89V51RD using serial communication?

Hi everyone,
In my code receive session is not working.. what changes should i made to receive a character from my keyboard?

// Program to test serial communication of controller with PC using hyper terminal
#include<reg51.h>

void ini()     // Initialize Timer 1 for serial communication
{
TMOD=0x20;  //Timer1, mode 2, baud rate 9600 bps
TH1=0XFD;
SCON=0x50;
TR1=1;
}

void recieve()  //Function to receive serial data
{
unsigned char value;
while(RI==0);
value=SBUF;
P1=value;
RI=0;
}

void transmit()  // Funtion to transmit serial data
{
P2=P1-32;
SBUF=P2;
while(TI==0);
TI=0;
SBUF=P1;
while(TI==0);
TI=0;
}

void main()
{
while(1)
{
  ini();
  recieve();
  transmit();
}
}


Thank in advance

Parents
  • puts() isn't really a big problem - somewhere in memory there is likely to be a zero.
    puts() isn't much different from printf() - also assuming that the string is zero-terminated.
    Just as strlen() and a huge number of other functions.

    gets() on the other hand is lethal unless it is one of the non-standard implementations that takes a buffer size.

Reply
  • puts() isn't really a big problem - somewhere in memory there is likely to be a zero.
    puts() isn't much different from printf() - also assuming that the string is zero-terminated.
    Just as strlen() and a huge number of other functions.

    gets() on the other hand is lethal unless it is one of the non-standard implementations that takes a buffer size.

Children
No data