Vous êtes sur la page 1sur 12

8051 SERIAL COMMUNICATION

Introduction
Computer stores data in two ways: serial and parallel. In parallel data transfer:
8 or more wire conductors are used Distance: a few feet away Example: printer and hard disk

In serial data transfer:


Data is sent one bit at one time Distance: hundreds of feet to million of miles Single data line is used

Basic of Serial Communication


For serial data communication, the byte of data must be converted to serial bit using a parallel in serial out shift register and can be transmitted over a single line. At the receiving end, there must be a serial in parallel out shift register. When the distance is short, the signal can be transferred on a simple wire. For a long distance data communication using communication lines such as telephone, serial data communication requires a modem to modulate and demodulate.

Cont..
Serial data communication use two methods:
Asynchoronous (transfer a single byte of data) Synchronous (transfer a block of data)

Duplex transmission: data can be transmitted and received.


Half duplex: data are transmitted one way at one time Full duplex: data can go both ways.

Simplex transmission: one way communication such as computer only send data to printer.

RS232 standars
To allow compatability among data communication equipment made by various manufacturer, an interfacing standard called RS232 was set by the Electronic Industries Association in 1960. The standard was set before the advent of the TTL logic, its input and output voltage are not TTL compatible. In RS232, a 1 is represented by -3 to -25V while 0 bit is +3 to +25V. Voltage converter must be used such as MAX232 IC

8051 serial communication programming


To allow data transfer between PC and 8051, we must make sure that the baud rate of the 8051 matches the baud rate of the PC. PC baudrate: 110, 150, 300, 600, 1200, 2400, 4800, 9600, 19200.

Baud rate in 8051


Baud rate in 8051 is programmable. Is done with the help of Timer 1. With XTAL =11.0592MHz, find the TH1 value needed to have the following baud rate: 9600, 2400 and 1200.
11.0592MHz/12 =921.6kHz. 921.6kHz/32=28800Hz 28800/3=9600 -3=FD is loaded into TH1 28800/12=2400 -12=F4 is loaded into TH1 28800/24=1200 -24=E8 is loaded into TH1

SBUF register
SBUF is an 8 bit register for serial communication in 8051. For data to be transfered, it must be placed in SBUF register. Example:
MOV SBUF, #D MOV SBUF, A MOV A, SBUF

The moment a byte is written into SBUF, it is framed with the start and stop bit and tranfered serially. When the bits are received, 8051 deframed it by eliminating the stop bit and start bit and placing it in SBUF register.

SCON register
is an 8 bit register used to program the start bit, stop bit and data bits of data framong. SM0 SM1 SM2 REN TB8 RB8 TI RI SM0 =0 SM1= 0 Serial mod 0 SM0=0 SM1=1 serial mod 1, 8 bit data, 1 stop bit, 1 start bit SM0=1 SM1=0 mode 2 SM0=1 SM1=1 mode 3
Mode 1 is our interest

example
MOV TMOD, #20H MOV TH1, #-6 MOV SCON, #50H SETB TR1 AGAIN: MOV SBUF, #A HERE: JNB T1, HERE CLR TI SJMP AGAIN

Cont..
SM2: is not use, is set to 0. REN: receive enable, must be set to 1, 0 = disable TB8: used for mode 2 and mode 3. not used in our application. RB8: is used in mode 2 and 3 TI: transmit interrupt. When 8051 finished the transfer of the 8 bit character, it raise the TI flag to indicate that it is ready to transfer next data. RI: receive interrupt: after 8051 receive data, the RI is raised to indicate that the data should be pick up.

Doubling the baudrate


There are two ways to increase the baud rate:
To use a higher frequency cryystal To change a bit in the PCON register, shown below

SMOD -- -- --- GF1 GF0 PD IDL SMOD must be set to 1. SMOD is not bit addressable
MOV A, PCON SETB ACC.7 MOV PCON,A

Vous aimerez peut-être aussi