Title: Microprocessors
1Microprocessors
- 8051 Serial Communication Ch10
2Serial Transfer
- Single line
- Cheaper than parallel transfer
- Slower than parallel transfer
- Synchronous transfers a block of characters
- Asynchronous transfers a single character
- Basic method is called Simplex one way
communication.
3Serial Transfer Hardware
- UART Universal asynchronous R/T (on 8051)
- USART Universal synchronous/asynchronous R/T
- Modem (modulator/demodulator) for long distance
(telephone) communication.
4Full Duplex
- Requires two parallel paths
- Allows communication both ways at the same time.
5Half Duplex
- Tx and Rx at all stations.
- Only one path (as in simplex)
- Data goes only one way at a time.
6Communication Protocol
- A protocol is an agreed upon plan established by
usage or convention or treaty. - Authorities attempt to teach us manners which
is another name for protocol. - A communication protocol is needed for
comfortable and productive conversation. - Recall examples of commonly accepted
communication protocol that you use often.
7- Start and stop bits frame the data.
- Signal is high (Mark) until data is sent.
- Space is low.
Frame
8Asynchronous Data Framing Protocol
- Mark is High
- Space is Low
- 1 or 2 stop bits
- 7 or 8 data bits
9Baud Rate
- For practical purposes and unless otherwise
stated, the baud rate is the number of bits
transferred per second (bps). - 100,000 baud is about max for asynchronous serial
com. - Where did they get the word baud?
10Baud rate depends on THREE settings.
- Frequency of system clock oscillator. Can be
changed by changing crystal. - SMOD
- if 0 divide by 32
- if 1, divide by 16
- Timer Preset.
118051 Baud Rate Preset
- 1. Get the machine cycle frequency by dividing
the system clock frequency by 12. - 2. Get the UART frequency by dividing the machine
cycle frequency by 32 - (SMOD 0).
- 3. Get the timer preset by dividing the UART
frequency by the baud rate. - The timer preset is 3 or FDH. This gives an
acutal baud rate of 10417.
12MHz/12 1MHz
1MHz/32 31.25KHz
31.25KHz/9600 3
12Determining the duration of a machine cycle.
- There are 12 system oscillator cycles per machine
cycle. - Divide the system oscillator frequency by 12
12/16MHz 0.75uS12/12MHz 1uS12/11.0592MHz
1.085uS
13Determining the duration of a machine cycle.
- Multiply the period of the system oscillator by
12.
16MHz/12 1.333MHz12MHz/12 1MHz11.0592MHz/12
0.9216MHz
14Determine UART
15Baud Rate Presets with 12MHz system clock (SMOD
0).
16RS232 Standards
- Most widely used serial standard.
- Mark is 3V to 25V
- Space is 3V to 25V
- Need a line driver to make it compatible with
TTL standard. (MAX232)
17RS232 Male Connectors
GND
RxD, TxD
DB-9
TxD, RxD
GND
DB-25
18Female Serial Connection
GND
Tx
Rx
19RS232 and 8051
- Requires a linedriver such as MAX232 chip.
20Serial Control RegisterSCON
1 A byte is ready to go.0 A byte is not
ready.
1 A Byte has been received0 Waiting to
receive a byte.
SM0,SM1,SM2
Set for common framing.
Receiver Enable1 Listening. 0 Not listening.
21Serially Transmit a Character
Puts 0010 0000 in TMOD to make timer 1 8-bit auto
reload.
22Puts 6 in TH1 to produce 9600 baud rate
continuously.
23Puts 0101 0000 in SCON to set framing, enable
REN, and clear both TI, RI
24Starts timer 1 to generate baud rate.
25Wave bye-bye to ASCII A
26Wait till here SBUF empties.
27We know its gone when TI 1
28Now that SBUF is empty, reset TI.
29Lets do it again!
30Put a byte into SBUF.
31Wait until it transmits (thats automatic).
32It is done transmitting when TI sets.
33Reset the transmit flag.
34Do it again.
35Load SBUF.
36Wait for TI.
37When TI sets, proceed with the program.
38Reset IT every time it sets.
39Try it. Copy and paste into an .asm file. Open a
TTY window to see the action.
include ltsfr51.incgt
cseg at 0
org 0 MOV TMOD, 20H
MOV TH1,-3
MOV SCON,50H
SETB TR1 AGAIN MOV SBUF,'A' HERE
JNB TI, HERE CLR
TI SJMP AGAIN
end
40Serially Receive a Character
Timer1 is 8-bit automatic reload.
41Timer1 preset is 3 for 9600 baud.
42Plan for 8 data bits, 1 stop bit, enable the
receiver (REN).
43Turn the timer on.
44Waste time until a byte is received.
45Hey, theres data in my SBUF!
46Copy it right away so SBUF can be used again.
47Give P1 a copy.
48Should have done this after MOV A, SBUF.
49Go back for another byte.
50Wait here for another byte.
51Another byte has arrived.
52Move it to the accumulator.
53Give P1 a copy.
54Put the mail flag down.
55Jump for another byte.
56Connect two R31-JPs by null modem.
Connect all three wires!
Female connector on board.
Female connector on board.
It works if you can detect ASCII A at P1 on the
receiver board.