Vous êtes sur la page 1sur 29

Serial

communication
Contents
Types of communication.

UART in 8051.

Max circuitry.

Baud rate in 8051.

Registers regarding serial communication.

Programming steps.
Serial Communication

Type of Communication

1.Parallel
2.Serial
Parallel transmission
Serial transmission
Synchronous transmission
Asynchronous transmission
UART in 8051
An UART, universal asynchronous receiver /
transmitter is responsible for performing the main
task in serial communications with computers.

The device changes incoming parallel information to


serial data which can be sent on a communication
line. A second UART can be used to receive the
information.
To communicate with pc or other devices we need
some standards like RS232.

A driver(MAX232) is used to convert TTL level to


RS232 voltage level.
Max circuitry
Value of capacitors is 10uF

Controller
section

RS232
section
Baud Rates in the 8051
• The 8051 transfers and receives data serially at many
different baud rates by using UART.
• UART divides the machine cycle frequency by 32 and
sends it to Timer 1 to set the baud rate.
• Signal change for each roll over of timer 1

11.0592 MHz
Machine cycle 28800 Hz
XTAL frequency ÷ 32
÷ 12 Timer 1
oscillator 921.6 kHz By UART To timer 1
To set the
Baud rate
Baud Rates in the 8051

• Timer 1, mode 2 (8-bit, auto-reload)


• Define TH1 to set the baud rate.
– XTAL = 11.0592 MHz
– The system frequency = 11.0592 MHz / 12 = 921.6
kHz
– Timer 1 has 921.6 kHz/ 32 = 28,800 Hz as source.
– TH1=FDH means that UART sends a bit every 3
timer source.
– Baud rate = 28,800/3= 9,600 Hz
SCON Register
• Serial control register: SCON
SM0, SM1 Serial port mode specifier
REN (Receive enable) set/cleared by software
to enable/disable reception.
TI Transmit interrupt flag.
RI Receive interrupt flag.
SM2 = TB8 = TB8 =0 (not widely used)

SM0 SM1 SM2 REN TB8 RB8 TI RI


* SCON is bit-addressable.
SM0, SM1

• SM1 and SM0 determine the framing of data.


– SCON.6 (SM1) and SCON.7 (SM0)
– Only mode 1 is compatible with COM port of PC.
SM1 SM0 Mode Operating Mode Baud Rate

0 0 0 Shift register Fosc./12


0 1 1 8-bit UART Variable by timer1
1 0 2 9-bit UART Fosc./64 or Fosc./32

1 1 3 9-bit UART Variable


REN (Receive Enable)
• SCON.4
• Set/cleared by software to enable/disable reception.
– REN=1
• If we want the 8051 to both transfer and
receive data, REN must be set to 1.
– REN=0
• The receiver is disabled.
• The 8051 can not receive data.
TI (Transmit Interrupt Flag)

• SCON.1
• When the 8051 finishes the transfer of the 8-
bit character, it raises the TI flag.
• TI is raised by hardware at the beginning of
the stop bit in mode 1.
• Must be cleared by software.
RI (Receive Interrupt)

• SCON.0
• Receive interrupt flag. Set by hardware
halfway through the stop bit time in mode 1.
Must be cleared by software.
• When the 8051 receives data serially via RxD,
it gets rid of the start and stop bits and place
the byte in the SBUF register.
• Then 8051 rises RI to indicate that a byte.
• RI is raised at the beginning of the stop bit.
Transfer Data with the TI flag
• The following sequence is the steps that the 8051
goes through in transmitting a character via TxD:
1. The byte character to be transmitted is written into the
SBUF register.
2. It transfers the start bit.
3. The 8-bit character is transferred one bit at a time.
4. The stop bit is transferred.

8-bit char
SBUF
bit by bit
TI UART TxD
Steps to transmit data
from uc to pc
1.Load SCON register.
2.Laod TMOD register(select timer mode 2).
3. Load baud rate in TH.
4. Start the timer.
5. Place character in SBUF.
6. Monitor TI flag.
7. Clear TI flag.
Steps to Receive data
from pc to uc
1.Load SCON register.
2.Laod TMOD register(select timer mode 2).
3. Load baud rate in TH.
4. Start the timer.
5. Monitor RI flag.
7. Read SBUF.
8. Clear RI.
#include<reg51.h>
void main()
{

int i;
char arr[]="Advance Technology”;
TMOD=0x20; SBUF=arr[i];
SCON=0x50; while(TI==0);
TH1=0xFD; TI=0;
TR1=1; if(i==17)
while(1) TR1=0; }
{ }
for(i=0;i<=17;i++) }
{
Analog to digital
converter (ADC)
Contents
About ADC(0809).

Pin description of 0809 ADC.

Interfacing with 8051.

Programming steps.
Analog to Digital Converter
An analog-to-digital converter is a device which
converts continuous signals to discrete digital
numbers. The reverse operation is performed by
a digital-to-analog converter (DAC).

Typically, an ADC is an electronic device that


converts an input analog voltage (or current) to
a digital number proportional to the magnitude
of the voltage or current.
ADC 0809

8 analog
Channel
multiplexing.
Interfacing of ADC with 8051
Steps to interface 0809 ADC
with 8051 uc
1.Set initial values of SOC,EOC and OE.
2.Set ADD A, ADD B,ADD C.
3.Low to high pulse on ALE.
4.Low to high pulse on SOC with clock.
5.Monitor EOC bit.
6.Read data.
7.Repeat the steps.
#include<reg51.h>

sbit ALE=P1^3;
sbit SOC=P0^0;
sbit OE=P0^2;
sbit EOC=P0^1;
sbit SET0=P1^0;
sbit SET1=P1^1;
sbit SET2=P1^2; void main(void)
sbit CLOCK=P0^3; {

void clock(void); while(1)


void delay(int x); {
SET0=1;
SET1=1; //for the select line
SET2=1;
ALE=1;
SOC=1;
clock();
ALE=0; void clock(void)
SOC=0; {
clock(); int a,b;
while(!EOC); for(b=0;b<=1000;b++)
OE=1; {
P3=P2; for(a=0;a<30;a++);
} CLOCK=~CLOCK;
} }
}

Vous aimerez peut-être aussi