Serial data transmission using 8051
SOFTWARE: KEIL MICRO VISION 4.0
SIMULATOR: PROTEUS 8.0
CIRCUIT DIAGRAM:
Here in this project, I have transmitted the data to the virtual terminal. When all the data gets transmitted, the TI flag in the SCON register becomes equal to 1 which indicates the complete transmission of data(8 bit).
Data which needs to be transmitted is first placed into the SBUF register and after that the further procedure is performed as mentioned below.I have used a 9600 baud rate. All the serial communication is done using TXD and RXD pin of 8051.
PROGRAM:
#include<reg51.h>
int main()
{
unsigned char *d="WELCOME TO THE EMBEDDED SYSTEM"; // data which gets transmitted to the virtual terminal
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
TI=0; // clear transmit flag
while(*d!='\0')
{
SBUF=*d; // send data to serial buffer
d++;
while(TI==0); // wait untill transmission is complete
TI=0; // clear TI for next transmission
}
while(1);
}
PROGRAM DESCRIPTION:
I have followed the steps mentioned below to transmit the data to the virtual terminal.
Steps for serial data transmission in serial mode 2:
1.Set the timer 1 in mode 2.
2.Set the SCON register in mode 2.
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 TI flag.
6.Send the data to the SBUF register.
4.Start the timer 1.
5.Clear the TI flag.
6.Send the data to the SBUF register.
7.Wait for the TI flag to set 1.
8.Clear the TI flag to transmit the next data.
9.For continuous process, repeat from step 6.
9.For continuous process, repeat from step 6.
For selecting the baud rate send the below data to the TH1 register.
Whatever data we send it get displayed on the virtual terminal.
VIDEO:
VIDEO:
Comments
Post a Comment