Lecturer 4
Lecturer 4
Lecturer 4
Lecturer Four
BASICS OF SERIAL COMMUNICATION
●
Computers transfer data in two ways:
– Parallel
●
Often 8 or more lines (wire conductors) are used to transfer
data to a device that is only a few feet away
– Serial
●
To transfer to a device located many meters away, the serial
method is used
●
The data is sent one bit at a time
BASICS OF SERIAL COMMUNICATION
●
At the transmitting end, the byte of data must be converted to serial bits using
parallel-in-serial-out shift register.
●
At the receiving end, there is a serial-in-parallel-out shift register to receive the
serial data and pack them into byte
●
When the distance is short, the digital signal can be transferred as it is on a
simple wire and requires no modulation
●
If data is to be transferred on the telephone line, it must be converted from 0s
and 1s to audio tones
– This conversion is performed by a device called a modem,
“Modulator/demodulator”
BASICS OF SERIAL COMMUNICATION
● Serial data communication uses two methods
– Synchronous method transfers a block ofdata at a time
– Asynchronous method transfers a single byte at a time
● It is possible to write software to use either of these methods, but the
programs can be tedious and long
– There are special IC chips made by many manufacturers for serial
communications
● UART (universal asynchronous Receiver-transmitter)
● USART (universal synchronous-asynchronous Receiver-
transmitter)
BASICS OF SERIAL COMMUNICATION
●
If data can be transmitted and received, it is a duplex transmission
– If data transmitted one way a time, it is referred to as half duplex
– If data can go both ways at a time, it is full duplex
●
This is contrast to simplex transmission
BASICS OF SERIAL COMMUNICATION
●
A protocol is a set of rules agreed by both the sender and receiver on
– How the data is packed
– How many bits constitute a character
– When the data begins and ends
●
Asynchronous serial data communication is widely used for
character-oriented transmissions
– Each character is placed in between start and stop bits, this is
called framing
– Block-oriented data transfers use the synchronous method
●
The start bit is always one bit, but the stop bit can be one or two bits
●
The start bit is always a 0 (low) and the stop bit(s) is 1 (high)
8051 connection to RS 232
●
An interfacing standard RS232 was set by the Electronics Industries
Association (EIA) in 1960
●
The standard was set long before the advent of the TTL logic family,
its input and output voltage levels are not TTL compatible
– In RS232, a 1 is represented by -3 ~ -25 V, while a 0 bit is +3 ~
+25 V, making -3 to +3 undefined
8051 connection to RS 232
– l
8051 connection to RS 232
●
Since not all pins are used in PC cables, IBM introduced the DB-9
version of the serial I/O standard
8051 connection to RS 232
●
Current terminology classifies data communication equipment as
– DTE (data terminal equipment) refers to terminal and computers
that send and receive data
– DCE (data communication equipment) refers to communication
equipment, such as modems
●
The simplest connection between a PC and microcontroller requires a
minimum of three pins, TxD, RxD, and ground
RS232 Pins
●
DTR (data terminal ready)
– When terminal is turned on, it sends out signal DTR to indicate that it is ready
for communication
●
DSR (data set ready)
– When DCE is turned on and has gone through the self-test, it assert DSR to
indicate that it is ready to communicate
●
RTS (request to send)
– When the DTE device has byte to transmit, it assert RTS to signal the modem
that it has a byte of data to transmit
●
CTS (clear to send)
– When the modem has room for storing the data it is to receive, it sends out
signal CTS to DTE to indicate that it can receive the data now
RS232 Pins
●
DCD (data carrier detect)
– The modem asserts signal DCD to inform the DTE that a valid
carrier has been detected and that contact between it and the other
modem is established
●
RI (ring indicator)
– An output from the modem and an input to a PC indicates that the
telephone is ringing
– It goes on and off in synchronous with the ringing sound
8051 serial communications Programming
●
To allow data transfer between the PC and an 8051 system without
any error, we must make sure that the baud rate of 8051 system
matches the baud rate of the PC’s COM port
●
Hyperterminal function supports baud rates much higher than listed
below
8051 serial communications Programming
– w
8051 serial communications Programming
SBUF Register
●
SBUF is an 8-bit register used solely for serial communication
– For a byte data to be transferred via the TxD line, it must be placed in
the SBUF register
●
The moment a byte is written into SBUF, it is framed with the
start and stop bits and transferred serially via the TxD line
– SBUF holds the byte of data when it is received by 8051 RxD line
●
When the bits are received serially via RxD, the 8051 deframes it
by eliminating the stop and start bits, making a byte out of the
data received, and then placing it in SBUF
8051 serial communications Programming
●
In programming the 8051 to transfer character bytes serially
1. TMOD register is loaded with the value 20H, indicating the use of timer 1
in mode 2 (8-bit auto-reload) to set baud rate
2. The TH1 is loaded with one of the values to set baud rate for serial data
transfer
3. The SCON register is loaded with the value 50H, indicating serial mode 1,
where an 8-bit data is framed with start and stop bits
4. TR1 is set to 1 to start timer 1
5. TI is cleared by CLR TI instruction
6. The character byte to be transferred serially is written into SBUF register
7. The TI flag bit is monitored with the use of instruction JNB TI,xx to see if
the character has been transferred completely
8. To transfer the next byte, go to step 5
8051 serial communications Programming
– e
8051 serial communications Programming
SCON (serial control) register
●
SCON is an 8-bit register used to program the start bit, stop bit, and data
bits of data framing, among other things
8051 serial communications Programming
SCON (serial control) register
●
SM0, SM1
– They determine the framing of data by specifying the number of bits
per character, and the start and stop bits
●
SM2
– This enables the multiprocessing capability of the 8051
8051 serial communications Programming
SCON (serial control) register
●
REN (receive enable)
– It is a bit-adressable register
– When it is high, it allows 8051 to receive data on RxD pin
– If low, the receiver is disable
●
TI (transmit interrupt)
– When 8051 finishes the transfer of 8-bit character
– It raises TI flag to indicate that it is ready to transfer another byte
– TI bit is raised at the beginning of the stop bit
●
RI (receive interrupt)
– When 8051 receives data serially via RxD, it gets rid of the start and stop bits and places the
byte in SBUF register
– It raises the RI flag bit to indicate that a byte has been received and should be picked up
before it is lost
– RI is raised halfway through the stop bit
REAL-WORLD INTERFACING
Interfacing LCD to 8051
●
LCD is finding widespread use replacing LEDs