Serial data reception using 8051

SOFTWARE: KEIL MICRO VISION 4.0

SIMULATOR:
PROTEUS 8.0

CIRCUIT DIAGRAM:




WORKING:

Here in this project, I have received the data from the virtual terminal and displayed the received data on an lcd.When all the data get received, the RI flag in the SCON register becomes equal to 1 which indicates the complete reception of data(8 bit).

Received data gets stored into the SBUF register. I have taken the received data from the SBUF register and send this data on an lcd. I have used a 9600 baud rate.All the serial communication is done using TXD and RXD pin of 8051.

PROGRAM:

#include<reg51.h>
sbit RS = P2^0; 
sbit EN = P2^2;

void lcd_init(void); // lcd initialization function
void lcd_command(unsigned char c);// lcd command function
void lcd_data(unsigned char d);// lcd data function
void delay(unsigned int t); // delay function

int main()
{
unsigned char r;
lcd_init(); // lcd initialization

TMOD=0x20; // timer 1 in mode 2
SCON=0x50; // mode 1,8 bit data,1 stop bit,1 start bit
TH1=0xfd; // 9600 baud rate
TR1=1; // start timer 1
RI=0;   // clear receive flag
while(1)
{
while(RI==0); // wait untill reception is complete
r = SBUF;
RI=0; // clear RI for next reception
if(r==8)   // if backspace is pressed
{
lcd_command(0x01); // clear display
}
else
{
lcd_data(r); // display the received data on an lcd
}
}
}

void lcd_init()
{
lcd_command(0x01); // clear display
lcd_command(0x06); // Entry mode
lcd_command(0x38);//8 bit mode,2 line,5x7 matrix
lcd_command(0x0c); // display on,cursor off
lcd_command(0x80); // first location(begining)
}

void lcd_command(unsigned char c)
{
P1=c;
RS=0; // select command register
EN=1;  // send high to low pulse on enable pin
delay(2);
EN=0;
delay(4);
}

void lcd_data(unsigned char d)
{
P1=d;
RS=1; // select data register
EN=1;  // send high to low pulse on enable pin
delay(2);
EN=0;
delay(4);
}

void delay(unsigned int t)
{
unsigned int i;
for(i=0;i<t*1240;i++);
}

PROGRAM DESCRIPTION:

First I have initialized the lcd. After that I have followed the steps mentioned below.

Steps for serial data reception in serial mode 2:

1.Set the timer 1 in mode 2.
2.Set the SCON register in mode 2 with REN bit enable.
3.Select the baud rate and send the data with respect to that baud rate to TH1 register(as mentioned in above table). 
4.Start the timer 1.
5.Clear the RI flag.
6.Wait for the RI flag to set 1.
7.Take the data from the SBUF register.
8.Clear the RI flag to receive the next data.
9.For continuous process, repeat from step 6.

For selecting the baud rate send the below data to the TH1 register.



Whatever data we typed on the virtual terminal that data will get displayed on an lcd. Pressing of backspace key will clear the lcd screen.

VIDEO:



















Comments

Popular posts from this blog

Digital Thermometer using 8051 and ADC 0808 Interfacing With 8051

how to display numbers on lcd?

To display custom characters on the lcd using 8051 micro-controller.