0% found this document useful (0 votes)
27 views

LAB 13 8051 Serial Programming in C

Uploaded by

tanveer1111110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

LAB 13 8051 Serial Programming in C

Uploaded by

tanveer1111110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

8051 SERIAL

PROGRAMMING IN C
INTRODUCTION

In serial communication, the data is sent one bit at


a time, in contrast to parallel communication, in
which the data is sent a byte or more at a time.
The 8051 has serial communication capability
built into it.
EXAMPLES
A program for the 8051 to transfer letter “A” serially at 4800
baud rate continuously

#include <reg51.h>
void main(void)
{
TMOD=0x20; //timer 1, mode 2 (auto reload)
TH1 = -6; //4800 baud rate
SCON=0x40; //8-bit, 1 stop
TR1 = 1; //start timer 1
while(1)
{
SBUF = ‘A’; //letter "A" to be transferred
while(TI==0); //wait for the last bit
TI = 0; //clear TI for next char
} //keep sending A
}
EXAMPLES
A program to receive bytes of data serially, and put them in P1. Set the
baud rate at 4800, 8-bit data and 1 stop bit.

#include <reg51.h>
void main(void)
{
char x;
TMOD=0x20; //timer 1, mode 2 (auto reload)
TH1 = -6; //4800 baud rate
SCON=0x50; //8-bit, 1 stop, REN enabled
TR1 = 1; //start timer 1
while(1)
{
while(RI==0); //wait for character to receive
x = SBUF; //save incoming byte in x
RI = 0; //clear RI for next char
P1 = x; //send data to port 1
} //keep sending A
}
EXERCISES
Write an 8051 C program to transfer serially the
letter “Z” continuously at a 1200 baud rate.
EXERCISES
Write an 8051 C program to transfer serially the
message “We love our country” continuously at a
57,600 baud rate.
EXERCISES
Write a C program to simultaneously transmit and
receive data at 9.6kbps baud rate.

You might also like