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 transmit the data from one controller to another controller

im using 8051 microntroller send the data one contoller to another controller frame formet  but my data is missing and not working 

*one controller is transmiting/receiving and another controller is receiving /transmiting

This is my code:

#include<reg51.h>

#define len 6
#define identical 0xA5
#define START 0x55
#define checksum (A,B,C,D)(A+B+C+D+)
#define END 0xA2
unsigned char RX_data;
//unsigned char receivedChar=0;
//unsigned char var;
unsigned char TX_data[len];
//void serial_isr() interrupt 4
//{
// if(RI == 1)
// {
// receivedChar = SBUF; // Copy the received char
// SBUF = receivedChar; // echo the character back
// RI = 0; // Clear the Receive interrupt flag
// }
// else if(TI == 1)
// {
// TI = 0; // Clear the Transmit interrupt flag
// }
//}
void Transmit_data(char tx_data)
{
SBUF = tx_data;
/* Load char in SBUF register */
while (TI==0); /* Wait until stop bit transmit */
TI = 0; /* Clear TI flag */
}
unsigned char Rx_char()
{
unsigned char Rx_Data;
while(RI == 1);
Rx_Data = SBUF;
SBUF=Rx_Data;
RI = 0;
return(Rx_Data);
}

void main()
{
P0=0xff;

SCON = 0x50; // Asynchronous mode, 8-bit data and 1-stop bit
TMOD = 0x20; // Timer1 in Mode2.
TH1 = 0xFD; // Load timer value for 9600 baudrate
TR1 = 1; // Turn ON the timer for Baud rate generation
ES = 1; // Enable Serial INterrupt
EA = 1; // Enable Global Interrupt bit

// receivedChar=P0;

TX_data[0]=identical;
TX_data[1]=START;
TX_data[2]=P0;
TX_data[3]=END;

while(1)
{
// LEDs = receivedChar;
Transmit_data(TX_data[0]);
Transmit_data(TX_data[1]);
Transmit_data(TX_data[2]);
Transmit_data(TX_data[3]);


}

}

#include<reg51.h>
#define LEDs P1
#define len 6
unsigned char TX_data[len];
unsigned char receivedChar=0;
//unsigned char RX_data[5];

int i=0,j=0;
unsigned char get;

//void serial_isr() interrupt 4
//{
// if(RI == 1)
// {
// receivedChar = SBUF; // Copy the received char
// SBUF = receivedChar; // echo the character back
// RI = 0; // Clear the Receive interrupt flag
// }
// else if(TI == 1)
// {
// TI = 0; // Clear the Transmit interrupt flag
// }
//}
///void Transmit_data(char tx_data)
// {
// SBUF = tx_data; /* Load char in SBUF register */
// while (TI==0); /* Wait until stop bit transmit */
// TI = 0; /* Clear TI flag */
// }


un signed char Rx_char()
{
unsigned char Rx_Data;
while(RI == 0);
Rx_Data = SBUF;
SBUF=Rx_Data;
RI = 0;
return (Rx_Data);
}

//void Transmit_data(char tx_data)
//{
// SBUF = tx_data;
// /* Load char in SBUF register */
// while (TI==0); /* Wait until stop bit transmit */
// TI = 0; /* Clear TI flag */
//}

void main()
{
// P1=0x00;

P0=0xff;
SCON = 0x50; // Asynchronous mode, 8-bit data and 1-stop bit
TMOD = 0x20; // Timer1 in Mode2.
TH1 = 0xFD; // Load timer value for 9600 baudrate
TR1 = 1; // Turn ON the timer for Baud rate generation
ES = 1; // Enable Serial INterrupt
EA = 1; // Enable Global Interrupt bit
// P0=0xff;
// receivedChar=P0;


// unsigned char get;
// get=Rx_char();

while(1)
{
// get=Rx_char();
// TX_data[2]=get;
// LEDs=TX_data[2];

unsigned char get;
//
get=Rx_char();
// TX_data[i]=get;
//

//
if(i>=4)

i=0;
TX_data[i++]=get;


if(i==3)


LEDs=TX_data[2];
//
//
//
// Transmit_data(receivedChar);
}
}