Briez
Member level 5
hello,
I am implementing serial half duplex communication between two 8051 micro-controllers. My circuit is like this......
> I have wrote a "C" Program for master as well as Slave.
For master:>
For Slave:>
> Please give me solution, where is i am making mistake.........??
I am implementing serial half duplex communication between two 8051 micro-controllers. My circuit is like this......
> I have wrote a "C" Program for master as well as Slave.
For master:>
Code:
#include<atmel\at89x51.h>
#include"lcd.h"
#define rs P1_0
#define en P1_1
void delay(unsigned int time);
void Uart_init();
void transmit(unsigned char talk);
void trans_string(char *string);
unsigned char sent=0,value3,value1,value2,value4,value5,value6,value7;
unsigned int i=0,j,l,m,n,o,p,q,r,s;
void main()
{
unsigned char DATA_tx[8]={0x01,0x03,0x00,0x78,0x00,0x01,0x04,0x13},DATA_rx[7];
Uart_init();
lcd_init();
lcd_cmd(0x88);
lcd_puts("Transmit");
P1_7=0;
while(1)
{
if(sent==0)
{
delay(5);
P1_7=1;
for(j=0;j<8;j++)
{
transmit(DATA_tx[j]);
}
delay(5);
sent++;
}
P1_7=0;
while(RI==0);
DATA_rx[i]=SBUF;
i++;
RI=0;
if(i==7)
{
value1=DATA_rx[0];
value2=DATA_rx[1];
value3=DATA_rx[2];
value4=DATA_rx[3];
value5=DATA_rx[4];
value6=DATA_rx[5];
//value7=DATA_rx[6];
lcd_cmd(0xC0);
for(j=0;j<7;j++)
lcd_data(DATA_rx[j]);
delay(25);
lcd_cmd(0x80);
l=value4%10; //0
m=value4/10; //0
n=value5/10; //7
o=value5%10; //7
lcd_data(m+0x30);
lcd_data(l+0x30);
lcd_data(n+0x30);
lcd_data(o+0x30);
i=0;
sent=0;
}
}
}
void Uart_init()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
void transmit(unsigned char talk)
{
SBUF=talk;
while(TI==0);
TI=0;
}
void delay(unsigned int time)
{
unsigned int j,k;
for(j=0;j<time;j++)
for(k=0;k<1275;k++);
}
For Slave:>
Code:
#include<atmel\at89x51.h>
#include"lcd.h"
#define rs P2_1
#define en P2_0
void delay(unsigned int time);
void Uart_init();
void transmit(unsigned char talk);
unsigned char sent=0,value3,value1,value2,value4,value5,value6,value7;
unsigned int i=0,j,l,m,n,o,p,q,r,s;
void main()
{
unsigned char DATA_tx[7]={0x01,0x03,0x00,0x00,0x64,0x04,0x13},DATA_rx[8];
Uart_init();
lcd_init();
lcd_cmd(0x88);
lcd_puts("Receive");
P1_7=0;
while(1)
{
P1_7=0;
while(RI==0);
DATA_rx[i]=SBUF;
i++;
RI=0;
if(i==8)
{
value1=DATA_rx[0];
/*value2=DATA_rx[1];
value3=DATA_rx[2];
value4=DATA_rx[3];
value5=DATA_rx[4];
value6=DATA_rx[5];*/
//value7=DATA_rx[6];
lcd_cmd(0xC0);
for(j=0;j<8;j++)
lcd_data(DATA_rx[j]);
if(value1==0x01)
{
delay(10);
P1_7=1;
for(j=0;j<7;j++)
{
transmit(DATA_tx[j]);
}
delay(5);
}
i=0;
}
P1_7=0;
}
}
void Uart_init()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
void transmit(unsigned char talk)
{
SBUF=talk;
while(TI==0);
TI=0;
}
void delay(unsigned int time)
{
unsigned int j,k;
for(j=0;j<time;j++)
for(k=0;k<1275;k++);
}
> Please give me solution, where is i am making mistake.........??
Last edited: