Saturday, 8 September 2018

8051: Serial Reception Interface Code



Description:

The serial port of 8051 is full duplex, i.e., it can transmit and receive simultaneously. The register SBUF is used to hold the data. The special function register SBUF is physically two registers. One is, write-only and is used to hold data to be transmitted out of the 8051 via TXD.
Microcontrollers need to communicate with external devices such as sensors, computers and so on to collect data for further processing. Data communication generally done by means of two methods: Parallel and Serial mode. In the parallel mode data bits are transferred in a fast manner using more number of lines. UART or Serial communication in 8051 microcontroller will allow the controller to send and receive data’s just by using two pins .Serial Communication uses only two data lines to establish communication between Microcontroller and external devices
Code:
#include<reg51.h>
#include<rx.h>
#include<ld.h>
void main()
{
char v;
ini();
display("welcome");
lcd();
while(1)
{
ini();
v=recieve();
data1(v);
}
}

/_________________________________rx.h______________________________________________/
void transmit(char x);
void ini();
void delay1();
void display();
int recieve();

int recieve()
{
unsigned char value;
while(RI==0);
value=SBUF;
RI=0;
return value;
}
void ini()
{
TMOD=0X20;
TH1=0XFD;
SCON=0X50;
TR1=1;
}
void transmit(char x)
{
SBUF=x;
TR1=1;
while(TI==0);
delay1();
TI=0;
TR1=0;
}
void display(char*s)
{
while(*s!='\0')
{
transmit(*s);
s++;
}
}
void delay1()
{
int i,j;
for(i=0;i<100;i++)
for(j=0;j<100;j++);
}
/___________________________________ld.h____________________________________________/
sbit rs=P1^0;
sbit en=P1^1;

void cmd(int);
void data1(char );
void lcd();
void delay();




void lcd()
{
cmd(0X38);
cmd(0X0E);
cmd(0X01);
cmd(0X06);
cmd(0X80);
}
void cmd(int a)
{
P2=a;
rs=0;
en=1;
delay();
en=0;
}
void data1(char x)
{
P2=x;
rs=1;
en=1;
delay();
en=0;
}
void delay()
{
int i,j;
for(i=0;i<100;i++)
for(j=0;j<100;j++);
}

Circuit Diagram:


No comments:

Post a Comment