KEMBAR78
FMA Notes Unit - 4 | PDF | Computer Engineering | Digital Technology
0% found this document useful (0 votes)
13 views22 pages

FMA Notes Unit - 4

The document discusses the various types of interrupts in the 8051 microcontroller, including reset, internal, serial, and external interrupts, along with their corresponding service routines and priority levels. It also covers serial communication methods, including asynchronous and synchronous data transfer, and details the relevant registers for managing serial communication. Additionally, it outlines the operating modes of the serial port and the configuration of baud rates for effective data transmission.

Uploaded by

HoD Electrical
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views22 pages

FMA Notes Unit - 4

The document discusses the various types of interrupts in the 8051 microcontroller, including reset, internal, serial, and external interrupts, along with their corresponding service routines and priority levels. It also covers serial communication methods, including asynchronous and synchronous data transfer, and details the relevant registers for managing serial communication. Additionally, it outlines the operating modes of the serial port and the configuration of baud rates for effective data transmission.

Uploaded by

HoD Electrical
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

8051 Interrupts

Interrupts are the events that temporarily suspend the main program, pass the
control to the external sources and execute their task. It then passes the control
to the main program where it had left off.
Interrupts are of different types like software and hardware, maskable and non-
maskable, fixed and vector interrupts, and so on. Interrupt Service Routine
(ISR) comes into the picture when interrupt occurs, and then tells the processor
to take appropriate action for the interrupt, and after ISR execution, the
controller jumps into the main program.

Types of Interrupts in 8051 Microcontroller


When an interrupt occurs, the microcontroller executes the interrupt service
routine so that memory location corresponds to the interrupt that enables it.
The Interrupt corresponding to the memory location is given in the interrupt
vector table below.
Interrupt vector
Interrupt Flag
address
Reset - 0000H
IE0 0003H
Timer 0 TF0 000BH
IE1 0013H
Timer 1 TF1 001BH
Serial TI/RI 0023H

1. Reset
Reset is the highest priority interrupt, upon reset 8051 microcontroller
start executing code from 0x0000 address.

2. Internal interrupt (Timer Interrupt) (TF0 and TF1)


8051 has two internal interrupts namely timer0 and timer1. Whenever
timer overflows, timer overflow flags (TF0/TF1) are set. Then the
microcontroller jumps to their vector address to serve the interrupt. For
this, global and timer interrupt should be enabled.
3. Serial interrupt (RI/TI)
8051 has serial communication port and have related serial interrupt flags
(TI (Transfer Interrupt) /RI (Receiver Interrupt)).
When the last bit (stop bit) of a byte is transmitted, TI serial interrupt flag
is set and when last bit (stop bit) of receiving data byte is received, RI
flag get set.
4. External interrupts
8051 has two external interrupt and . External interrupt has
two types of activation level

1. Edge triggered
2. Level triggered

Whenever a low level / falling edge is detected on the / pin


while global and external interrupts are enabled, the controller jumps to
interrupt service routine (ISR) to serve interrupt.
Interrupt Registers

A. IE register (Interrupt Enable Register)


IE register is used to enable/disable interrupt sources.

It is Enable All interrupt Bit


EA = 1: Enable all interrupts, provided corresponding enable bit
IE.7
for the interrupt is set
(EA)
EA = 0: Disable all interrupts, even though corresponding enable
bit for the interrupt is set
IE.6 & IE.5 Unused bits for 8051 microcontroller
It is Enable Serial Interrupt Bit
IE.4
ES = 1: Enable Serial Interrupt, provided that EA bit must be set.
(ES)
ES = 0: Disable Serial Interrupt
It is Enable Timer1/Timer0 Interrupt Bit
IE.3/IE.1 ET1/ET0 = 1: Enable Timer1/Timer0 Interrupt, provided that EA
(ET1/ET0) bit must be set.
ET1/ET0 = 0: Disable Timer1/Timer0 Interrupt
It is Enable External1/ External0 Interrupt Bit
IE.2/IE.0 EX1/EX0 = 1: Enable External1/External0 Interrupt, provided that
(EX1/EX0) EA bit must be set.
EX1/EX0 = 0: Disable External1/External0 Interrupt
B. Interrupt priority
In the table, interrupts priorities upon reset are shown. As per 8051 interrupt
priorities, lowest priority interrupts are not served until microcontroller is
finished with higher priority ones. In a case when two or more interrupts arrives
microcontroller queues them according to priority.

Priority Intr. bit / flag


1 INT0
2 TF0
3 INT1
4 TF1
5 (TI/RI)
B.1. IP Register (Interrupt priority register)
8051 has interrupt priority register to assign priority to interrupts.
An interrupt having high priority is acknowledged first and then low
priority interrupt will acknowledge.

Bits Functions
IP.7, IP.6, Unused bits for 8051 microcontroller
IP.5
It is Serial Interrupt Priority Bit
IP.4
PS = 1: Assign high priority to Serial Interrupt
(PS)
PS = 0: Assign low priority to Serial Interrupt
It is Enable Timer1/Timer0 Interrupt Bit
IP.3/IP.1
PT1/PT0 = 1: Assign high priority to Timer1/Timer0 Interrupt
(PT1/PT0)
PT1/PT0 = 0: Assign low priority to Timer1/Timer0 Interrupt
It is Enable External1/ External0 Interrupt Bit
IP.2/IP.0
PX1/PX0 = 1: Assign high priority to External1/ External0 Interrupt
(PX1/PX0)
PX1/PX0 = 0: Assign low priority to External1/ External0 l Interrupt
Serial Communication in 8051 Microcontroller

Microcontrollers need to communicate with external devices such as sensors,


computers and so on to collect data for further processing. Data communication
generally done by means of two methods:

1. Parallel data transfer and


2. Serial data transfer

Parallel data transfer Serial data transfer

8 data lines are needed to transfer a 1 data lines are needed to transfer a
byte of data. byte of data.
8 bit data is transferred at a time Only 1 bit data is transferred at a time
Time required to transfer the data is Time required to transfer the data is
less. more.
Data transfer is fast Data transfer is slow.
More advantageous over small More advantageous over long distance.
distance.
Cost of connecting two distance point Cost of connecting two distance point
is high for long distance. is low for long distance.

Fig. Transfer of data serially


A. Types of communication

The communication links are classified on the basis of transmission:


1) Simplex and 2) Duplex

1) Simplex:
 The simplex is one way transmission.
 The data will be transmitted only in one direction

2) Duplex
 The duplex is two way transmissions.
 Half Duplex: Half duplex means data will be transmitted in both
directions but at one time, only one device can transmit. This
means that the line has to turn around after communication is
complete in one direction.

 Full Duplex: full duplex means data may be transmitted in both


directions at one time, while one device is transmitting, it can also
receive data transmitted from other device at same time.
B. Serial Transmission format
1. Asynchronous Data Transfer

 It is “Character” oriented data transfer.


 One data bit is transferred at a time.
 When data is not transferred the output line of transmitter is High
i.e. Marking State.
 The start of data is indicated by a low start bit, which is used to
synchronised transmitter and receiver. After the start bit, data bits
are transfer serially.
 The data bits are followed by a one or more high stop bits. After
the stop bits same logical level is maintained on output lines.
 The receiver will check for marking state. When it detects low on
data line then it is treated as valid start bit.
 After start bit receiver will start accepting data bits D0 to D7. At
the end it will check stop bits and go back to initial marking state.
 The asynchronous data transfer format consists of a start bit, data
bits and stop bits called as Frame.
 The clock to both transmitter and receiver are separate. But
operating frequency for both is maintained same.
2. Synchronous Data Transfer

In Synchronous Data Transfer, at the same time, bytes are transmitted as


blocks in a continuous stream of bits.

 It is “Block of data” oriented data transfer.


 The block of data bytes transferred serially one after the other.
 Before sending data, special characters are transferred by
transmitter to receiver to achieve synchronization between
transmitter and receiver. This special character called as Sync
Character.
 To start transmission, the Sync Character bits are sent by
transmitter followed by data bits.
 When data is not transferred the output line of transmitter is High
i.e. Marking State.
 The receiver will go on checking input lines; and comparing
whatever data received with Sync Character.
 When match occurs then it is consider as the receiver is in
synchronization with transmitter.
 When the receiver is synchronized, then it will go on accepting
data bits in the same sequence.
 The clock of both transmitter and receiver is same to avoid wrong
data bits.
 Ex: Video conference, messages
BAUD RATE: The transmitter and receiver are configured to communicate at
some data transfer rate before communication starts. This data transfer rate or
number of bits transmitted per second is called baud rate for handling serial
communication.

UART: It stands for Universal Asynchronous Receiver-Transmitter. A UART


generates its internal data clock to the microcontroller. It synchronizes that
clock with the data stream by using the start bit transition. The receiver needs
the baud rate to know ahead of time to properly receive the data stream.
C. 8051 Serial Communications registers
1. SBUF Register (Serial Buffer register)

 Buffer which is used for holding the data before sending / after receiving
is called Serial Buffer.
 In 8051 Micro-controller there are two 8 bits serial buffer register.
 One is write only and is used to hold data is to be transmitted from micro-
controller via the TxD pin P3.1. It is Parallel in Serial out (PISO) register.
 While other is read only and used to hold data that is received from the
external source via the RxD pin P3.0. It is Serial in Parallel out (SIPO)
register.
2. SCON Register (Serial Control register)

Memory Address = 98 H
D7 D6 D5 D4 D3 D2 D1 D0
SM0 SM1 SM2 REN TB8 RB8 TI RI

Bit 7 & 6: SM0 & SM1 (Serial Mode control Bits)


These bits are serial mode bits and are used for selecting the operating
modes of serial port.
SM0 SM1 Mode Description Baud Rate
0 0 0 8 bit Shift Register Fixed Baud Rate
0 1 1 8 bit UART Variable Baud Rate
1 0 2 9 bit UART Fixed Baud Rate
1 1 3 9 bit UART Variable Baud Rate
Note: Mode 0 and Mode 1 used for one serial port (Uniprocessor)
Mode 2 and Mode 3 used for two serial ports (Multiprocessor)

Bit 5: SM2 (Multiprocessor control bit)


In 8051, there is only one serial port. So this is don’t care condition.
SM2 = 1, Multiprocessor serial port
SM2 = 0, Uniprocessor serial port

Bit 4: REN (Receiver enable bit)


This bit allows the data from external peripheral device to micro-
controller.
REN = 1, receiver is enable
REN = 0, receiver is disable

Bit 3: TB8 (Consider when serial Mode 2 and serial Mode 3 is used)
In 8051, there is only one serial port. So this is don’t care condition.
It is the 9th programmable transmitted bit along with data byte in
multiprocessor mode.
TB8 = 1, when the byte transmitted is data bit
TB8 = 0, when the byte transmitted is address bit

Bit 2: RB8 (Consider when serial Mode 2 and serial Mode 3 is used)
In 8051, there is only one serial port. So this is don’t care condition.
It is the 9th received programmable bit along with data byte in
multiprocessor mode.
RB8 = 1, when the byte received is data bit
RB8 = 0, when the byte received is address bit

Bit 1: TI (Transmit Interrupt flag)


TI = 1, When one byte of data transmission is completed TxD pin
P3.1
TI = 0, When one byte of data transmission is not completed

Bit 0: RI (Receive Interrupt flag)


RI = 1, When one byte of data reception is completed through RxD
pin P3.0
RI = 0, When one byte of data reception is not completed
3. PCON Register (Power Control register)

Memory Address = 87 H
D7 D6 D5 D4 D3 D2 D1 D0
SMOD -- -- -- GF1 GF0 PD IDL

Bit 7: SMOD (Serial Mode selection bit)

Speed of serial communication is decided by this SMOD bit called as


Baud rate.

When SMOD is reset then it is indicated that data is transmitted or


received by microcontroller at defined baud rate.

When SMOD is set then it is indicated that data is transmitted or received


by microcontroller at double the defined baud rate.

Bit 6, 5 & 4: Reserve bit

Bit 3 & 2: GF1 and GF0 (General purpose flags)

These flags are used by the programmer to indicate the status of the
various conditions

Bit 1: PD (Power Down)

When PD is set, internal oscillator stops and power is reduced to 2V from


5V for power saving purpose.

Bit 0: IDL (Ideal Power saving mode)

When IDL is set, the clock signal is stopped to CPU, but is suppled to
interrupt, timer and serial port blocks. It can be reset by hardware interrupt.
Operating Modes of Serial Port
Mode 0:

 It is a uniprocessor mode.
 In this mode of serial port, synchronous communication is used. It is 8-bit
shift register mode.
 There are TWO 8-bit shift register which are PISO and SIPO shift
register.
 Two signals i.e. data signals and clock signals are used in this mode.
 Data is transmitted and received by RxD pin and clocks are provided with
the help of TxD pin.
 PxD pin is used for transmitting the data through SIPO and for receiving
the data from PISO.
 With this arrangement, data can be transmitted to parallel device and data
can be received from parallel device.
 In the mode there is Fixed Baud Rate (fosc / 12)

Mode 1: (Standard 8-bit UART mode)


 It is a uniprocessor, synchronous serial communication mode.
 It is used to transfer data between 8051 and peripheral devices.
 In this mode data is transmitted or received by asynchronous manner. i,e
1 start bit, 8 bit data, 1 stop (Framing of 10-bit) will be transmitted or
received.
 In this mode, Baud rate is variable and which is decided by timer 1
overflow rate. Timer 1 in mode 2 is used to control the baud rate.
Mode 2: (9-bit UART mode with fixed baud rate)
 It is a multiprocessor, synchronous serial communication mode.
 It is used to transfer data between 8051 and peripheral devices.
 Generally used to transfer the data between two micro-controller.
 In this mode data is transmitted or received by asynchronous manner. i,e
1 start bit, 8 bit data, 1 9th programmable bit, 1 stop (Framing of 11-bit)
will be transmitted or received.
 In this mode, Baud rate is fixed.

Mode 3: (9-bit UART mode with variable baud rate)


 It is a multiprocessor, synchronous serial communication mode.
 It is used to transfer data between 8051 and peripheral devices.
 Generally used to transfer the data between two micro-controller.
 In this mode data is transmitted or received by asynchronous manner. i,e
1 start bit, 8 bit data, 1 9th programmable bit, 1 stop (Framing of 11-bit)
will be transmitted or received.
 In this mode, Baud rate is variable and which is decided by timer 1
overflow rate. Timer 1 in mode 2 is used to control the baud rate.
RS 232

-3 to -25 logic 1

+3 to +25 logic 0

-13 to +13

-ve = 1

+ve = 0

DTE – Data Terminal Equipment (Computer)

DCE – Data Communication Equipment (Modem)

Fig: RS232

Fig: MAX232 (Convert TTL to RS232 voltage level)


RS-232

 In communication, RS232, (Recommended Standard 232) is standard


introduced in 1960 for serial communication transmission of data.
 An RS232 serial port was once a standard feature of a personal computer,
used for connections to modems, printers, mica, data storage,
uninterruptible power supply, and other peripheral devices.
 In RS232 standard a bit 0 is represented by +3 to +25 V, while a bit 1 is
represented by -3 to -25 V.
 Hence, for connecting any RS232 to micro-controller voltage converters
like MAX232 are required.
 MAX232 is a line driver (Voltage converter) that converts TTL
(Transister - Transister Logic) level to RS232 voltage level and vice
versa.
 This communication is useful for point to point communication at slow
speed.
 Ex. COM1 port in PC can be used for mouse, COM2 port in PC can be
used for modem.
RS232 male connector

Pin Description DB-9 Connector:


PIN No. Pin Name
1 DCD (Data Carrier Detect)
2 RxD (Received Data)
3 TxD (Transmitted Data)
4 DTR (Data Terminal Ready)
5 GND (Signal ground)
6 DSR (Data Set Ready)
7 RTS (Request to Send)
8 CTS (Clear to Send)
9 RI (Ring Indicator)

Signal Specifications
RS232 works on the two-way communication that exchanges data to one
another. There are two devices connected to each other, (DTE) Data
Transmission Equipment & (DCE) Data Communication Equipment
The Data Terminal Equipment (DTE) wants to send data to Data
Communication Equipment (DCE). The following signals are used.

1. DTR (Data Terminal Ready)


 The DTE alerts the DCE for communication by sending this signal.
2. DSR (Data Set Ready)
 The DCE send this signal to the DTE to inform DTE that DCE
prepares itself for the communication.
3. RTS (Request to Send)
 Once DTE receives the DSR signal, it prepares itself for the data
transfer.
 DTE send the RTS signal to DCE to inform that it is ready for the
data transfer.
4. DCD (Data Carrier Detect)
 In response to RTS, DCE tries to make contact with the remote
MODEM.
 If the carrier is detected it informs the DTE about it through the
DCD signals.
5. CTS (Clear to Send)
 Once a stable contact is established with the remote MODEM, the
DCE sends the CTS to DTE.
 Due to this transmission begins.
Interfacing PC to 8051 using RS232 standard.
 The PCs are based on 8086, 80286, 80386, 80486 and Pentium
microprocessor.
 Generally PCs have two COM ports, COM1 and COM2 . Both the
ports have RS232 type connection.
 The COM1 is used for mouse and COM2 is used for connecting
devices like MODEM.

MAX232
The Max-232 IC is started by the maxim integrated products in 1987. It is an
integrated circuit which converts the signals from the RS232 serial port to the
proper signal which are used in the TTL compatible digital logic circuits. The
MAX232 can convert the signals like RX, TX, CTS, and RTS and it is a dual
driver/receiver.

The MAX-232 IC is an integrated circuit which consists of 16 pins and it is a


resourceful IC mostly used in the voltage level signal problems. Generally, the
MAX-232 IC is used in the RS232 communication system for the conversion of
voltage levels on TTL devices that are interfaced with the PC serial port and the
Microcontroller. This IC is used as a hardware layer converter like to
communicate two systems simultaneously. The image of MAX232 is shown
below.
The MAX232 consist of 16 pins with 3 major blocks. The power supply of this
integrated circuit is 5V which is compatible with most of the embedded systems. In
the three major blocks, the first block is a voltage doubler by using the IC
switched capacitor techniques are used to make the voltage doubler. If once the
voltage is doubled, then the second block is converted to +10V and -10V.
The main function of voltage level is converted in the 3rd block which consists
of the two transistors and 2 receivers. The following diagram shows the
construction of the MAX232.

You might also like