Unit-4 ES
Unit-4 ES
Example:
Chat Rooms
Telephonic Conversations
Video Conferencing
Example:
Email
Forums
Letters
Asynchronous transmission is
Synchronous transmission is costly.
economical.
Synchronous Transmission Asynchronous Transmission
Errors are detected and corrected in Errors are detected and corrected when
real time. the data is received.
8051 has built-in UART with RXD (serial data receive pin) and TXD (serial data
transmit pin) on PORT3.0 and PORT3.1 respectively.
Asynchronous communication
Asynchronous serial communication is widely used for byte-oriented transmission.
• START bit: It is a bit with which serial communication starts and it is always
low.
• Data bits packet: Data bits can be 5 to 9 bits packet. Normally we use 8 data
bit packet, which is always sent after the START bit.
• STOP bit: This is one or two bits. It is sent after the data bits packet to
indicate the end of the frame. The stop bit is always logic high.
In an asynchronous serial communication frame, the first START bit followed by the
data byte and at last STOP bit forms a 10-bit frame. Sometimes the last bit is also
used as a parity bit.
Interface standard
• 8051 serial communication has TTL voltage level which are 0 v for logic 0 and
5 v for logic 1.
• In computers and most of the old devices for serial communication, RS232
protocol with DB9 connector is used. RS232 serial communication has
different voltage levels than 8051 serial communication. i.e. +3 v to +25 v for
logic zero and -3 v to -25 v for logic 1.
• So to communicate with RS232 protocol, we need to use a voltage level
converter like MAX232 IC.
• Although there are 9 pins in the DB9 connector, we don’t need to use all the
pins. Only 2nd Tx(Transmit), 3rd Rx(Receive), and 5th GND pin need to be
connected.
• To meet the standard baud rates generally crystal with 11.0592 MHz is used.
• As we know, 8051 divides crystal frequency by 12 to get a machine cycle
frequency of 921.6 kHz.
• The internal UART block of 8051 divides this machine cycle frequency by 32,
which gives the frequency of 28800 Hz which is used by UART.
• To achieve a baud rate of 9600, again 28800 Hz frequency should be divided
by 3.
• This is achieved by using Timer1 in mode-2 (auto-reload mode) by putting 253
in TH1 (8-bit reg.)
• So 28800 Hz will get divided by 3 as the timer will overflow after every 3
cycles.
• we can achieve different baud rates by putting the division factor in the TH1
register.
9600 FD
4800 FA
2400 F4
1200 E8
8051 Serial communication Registers
SBUF: Serial Buffer Register
This is the serial communication data register used to transmit or receive data
through it.
Serial control register SCON is used to set serial communication operation modes.
Also it is used to control transmit and receive operations.
Normally mode-1 (SM0 =0, SM1=1) is used with 8 data bits, 1 start bit, and 1 stop bit.
1 = Receive enable
0 = Receive disable
This is the 9th received bit in mode 2 & 3 (9-bit mode), whereas in mode 1 if SM2 = 0
then RB8 hold the stop bit that received
This bit indicates the transmission is complete and gets set after transmitting the
byte from the buffer. Normally TI (Transmit Interrupt Flag) is set by hardware at the
end of the 8th bit in mode 0 and at the beginning of stop bit in other modes.
This bit indicates reception is complete and gets set after receiving the complete
byte in the buffer. Normally RI (Receive Interrupt Flag) is set by hardware in receiving
mode at the end of the 8th bit in mode 0 and at the stop bit receive time in other
modes.
Example
Let's Program 8051 (here AT89C51) to send character data “test” serially at 9600
baud rate in mode 1
* 8051_Serial_UART
* http://www.electronicwings.com
*/
void UART_Init()
{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
}
}
void main()
{
8051 serial interrupt has a vector address (0023H) where it can jump to serve ISR
(Interrupt service routine) if the global and serial interrupt is enabled.
Let's see how the serial interrupt routine will be used in serial communication
programming.
Programming steps
Note: For transmission and reception interrupt, the same interrupt vector address is
assigned, so when the controller jumps to the ISR, we have to check whether it is Tx
interrupt or Rx interrupt by TI and RI bits status.
High-Level Data Link Control (HDLC)
High-level Data Link Control (HDLC) is a group of communication protocols of the data link
layer for transmitting data between network points or nodes. Since it is a data link protocol,
data is organized into frames. A frame is transmitted via the network to the destination that
verifies its successful arrival. It is a bit - oriented protocol that is applicable for both point -
to - point and multipoint communications.
Transfer Modes
HDLC supports two types of transfer modes, normal response mode and asynchronous
balanced mode.
• Normal Response Mode (NRM) − Here, two types of stations are there, a primary
station that send commands and secondary station that can respond to received
commands. It is used for both point - to - point and multipoint communications.
• Asynchronous Balanced Mode (ABM) − Here, the configuration is balanced, i.e. each
station can both send commands and respond to commands. It is used for only point
- to - point communications.
HDLC Frame
HDLC is a bit - oriented protocol where each frame contains up to six fields.
The structure varies according to the type of frame. The fields of a HDLC frame
are −
• Flag − It is an 8-bit sequence that marks the beginning and the end of the frame. The
bit pattern of the flag is 01111110.
• Address − It contains the address of the receiver. If the frame is sent by the primary
station, it contains the address(es) of the secondary station(s). If it is sent by the
secondary station, it contains the address of the primary station. The address field
may be from 1 byte to several bytes.
• Control − It is 1 or 2 bytes containing flow and error control information.
• Payload − This carries the data from the network layer. Its length may vary from one
network to another.
• FCS − It is a 2 byte or 4 bytes frame check sequence for error detection. The standard
code used is CRC (cyclic redundancy code)
Explore our latest online courses and learn new skills at your own pace. Enroll and become
a certified expert to boost your career.
Types of HDLC Frames
There are three types of HDLC frames. The type of frame is determined by the
control field of the frame −
• I-frame − I-frames or Information frames carry user data from the network layer.
They also include flow and error control information that is piggybacked on user data.
The first bit of control field of I-frame is 0.
• S-frame − S-frames or Supervisory frames do not contain information field. They are
used for flow and error control when piggybacking is not required. The first two bits
of control field of S-frame is 10.
• U-frame − U-frames or Un-numbered frames are used for myriad miscellaneous
functions, like link management. It may contain an information field, if required. The
first two bits of control field of U-frame is 11.
https://www.dauniv.ac.in/public/frontassets/coursematerial/embeddedsystems/Chap_5L0
6Emsys3EPArallelPortDevices.pdf
8051 Connections to RS-232
https://youtu.be/-UXpfAggE5Q?si=sG0DGeITx6oF8xB0
https://youtube.com/playlist?list=PLgwJf8NK-
2e7K1ld0H8O_OEyPvjSd6uxx&si=T8vA6xQr0OMuEBln
OR
TCON
TF1 (Timer 1
7 Set to 1 when Timer 1 overflows else 0.
Overflow Flag)
TR1 (Timer 1 Run Set to 1 to start Timer 1, and set to 0 to stop Timer
6
Control Bit) 1.
TF0 (Timer 0
5 Set to 1 when Timer 0 overflows else 0.
Overflow Flag)
TR0 (Timer 0 Run Set to 1 to start Timer 0, and set to 0 to stop Timer
4
Control Bit) 0.
Bit Bit Name Description
Mode 0
Counter Modes
Mode 2: 8-bit Auto-Reload Mode
• Description: The configuration of Timer 0 in Mode 2 is an 8-bit
auto-reload timer. It counts from 00H to FFH (0 to 255) and
then loads the starting value automatically.
• Working Principle: TLx starts at 0 and increases to 255, but
instead of returning to 0, it reloads with the value from THx.
• Usage: Good for jobs like setting baud rates, when the timer
needs to continuously reload with a set value.
• Example: Used for Frequency Measurement.
The Block Diagram for Mode 2 is shown below.
Mode 2
Mode 3
Conclusion
In order to create time delays, measure time intervals, and count
events in embedded systems, 8051 timers and counters are necessary
components. To fully utilize them in a variety of applications, it is crucial
to comprehend how they operate and are configured.
The 8051 features two main types of interrupts, i.e. Hardware interrupts
and software interrupts. The hardware interrupts are triggered by external
signal such as peripheral events or external devices. The microcontroller
can be configured to respond to specific events, allowing for efficient
event-driven programming. Whereas, the Software interrupts, are initiated
by specific instructions in the program code. They provide a mechanism for
the programmer to force the microcontroller to interrupt its normal
execution and execute a predefined routine.
Reset - 0000H
INT0 (External
IE0 0003H
Interrupt 0)
INT1 (External
IE1 0013H
Interrupt 1)
SERIAL COMMMUNICATION
Refer this
https://www.codrey.com/embedded-systems/serial-communication-basics/
"Serial communication" in its most simple form means that data bits travel through a single line,
one by one like ducks in a row. In contrast, in parallel communication you'd have multiple lines
and the transferred bits are evenly distributed over the lines. You may want to picture a street
with one lane vs. a street with many lanes.One might think that parallel is better because you
have more lanes to use. But this is not the case because the bits on the data lines need to be
synchronized. Picture a street with 8 lanes where cars are not allowed to overtake each other but
instead need to arrive at exactly the same time.
UART is actually not a protocol but more a term for a piece of hardware capable of performing
simple protocols like RS232 or RS485
All these protocols are all standardized and they differ greatly in their scope and what they can
do. The most important features from an end-user point of view would be throughput (bits/sec)
and maximum cable length.
RS232 is one of the simplest protocols. It only describes how a single byte with 8 bits can be
transferred over a wire. Nothing more. RS232 is very primitive and can reach speeds up to
~1MBit/sec. Typical speed is slower, around 112KBit/sec.
On the other hand, we have complex protocols like USB3 or PCIExpress. They have many more
features such as:
Theses protocols are insanely powerful and fast. USB 3.x can reach up to 20 GBit/sec, USB 4.x up
to 40 GBit/sec. The protocols are very complex. I have a PCI Express book on my table and it has
around 1.300 pages
The 8255A is a general purpose programmable I/O device designed to transfer the data
from I/O to interrupt I/O under certain conditions as required. It can be used with almost
any microprocessor.
It consists of three 8-bit bidirectional I/O ports (24I/O lines) which can be configured as per
the requirement.
Ports of 8255A
• Port A contains one 8-bit output latch/buffer and one 8-bit input buffer.
• Port B is similar to PORT A.
• Port C can be split into two parts, i.e. PORT C lower (PC0-PC3) and PORT C upper
(PC7-PC4) by the control word.
These three ports are further divided into two groups, i.e. Group A includes PORT A and
upper PORT C. Group B includes PORT B and lower PORT C. These two groups can be
programmed in three different modes, i.e. the first mode is named as mode 0, the second
mode is named as Mode 1 and the third mode is named as Mode 2.
Operating Modes
Mode 1 − In this mode, Port A and B is used as 8-bit I/O ports. They can
be configured as either input or output ports. Each port uses three lines
from port C as handshake signals. Inputs and outputs are latched.
Features of 8255A
• The prominent features of 8255A are as follows −
• It consists of 3 8-bit IO ports i.e. PA, PB, and PC.
• Address/data bus must be externally demux'd.
• It is TTL compatible.
• It has improved DC driving capability.
8255 Architecture
The following figure shows the architecture of 8255A −
8255A - Pin Description
CS
It stands for Chip Select. A LOW on this input selects the chip and enables the
communication between the 8255A and the CPU. It is connected to the decoded address, and
A0 & A1 are connected to the microprocessor address lines.
Their result depends on the following conditions −
CS A1 A0 Result
0 0 0 PORT A
0 0 1 PORT B
0 1 0 PORT C
0 1 1 Control Register
1 X X No Selection
WR
It stands for write. This control signal enables the write operation. When this signal goes low,
the microprocessor writes into a selected I/O port or control register.
RESET
This is an active high signal. It clears the control register and sets all ports in the input mode.
RD
It stands for Read. This control signal enables the Read operation. When the signal is low, the
microprocessor reads the data from the selected I/O port of the 8255.
A0 and A1
These input signals work with RD, WR, and one of the control signal. Following is the table
showing their various signals with their result.
A1 A0 RD WR CS Result
Input Operation
0 0 0 1 0
PORT A → Data Bus
Output Operation
0 0 1 0 0
Data Bus → PORT A
Advantages:
Disadvantages:
Cost: While the 8259 PIC is relatively affordable, it does add cost to a
system, particularly if multiple PICs are required.
Limited Number of Interrupts: The 8259 PIC can manage up to 8
interrupt inputs, which may be insufficient for some applications.
Complex Programming: Although the interface pins and registers of the
8259 PIC are relatively simple, programming the 8259 can be complex,
requiring careful attention to interrupt prioritization and other
parameters.
Limited Functionality: While the 8259 PIC is a useful peripheral for
interrupt management, it does not include more advanced features, such
as DMA (direct memory access) or advanced error correction.
The 8051’s timers/counters are versatile peripherals that can function as:
• Timers: Count internal clock pulses (derived from the system clock) to measure time
or generate delays.
• Counters: Count external events (pulses) applied to specific pins (T0 or T1).
Each timer (Timer 0 and Timer 1) is a 16-bit register that increments with each clock cycle or
external pulse. When the timer overflows (reaches 0xFFFF and resets to 0x0000), it can
trigger an interrupt or set a flag, making it useful for precise timing and synchronization in
embedded systems.
Timer Modes