0% found this document useful (0 votes)
43 views34 pages

L7 - 8051 Interrupt, Timer and Addressing Modes

The document discusses the 8051 microcontroller's interrupt structure, timers, addressing modes, and serial communication capabilities. It describes the five interrupt types, how interrupts are prioritized and enabled, and how the interrupt service routines function. It explains how the two 16-bit timers work and how their various operating modes are set in the TMOD register. It also outlines the immediate, register, direct, register indirect, and indexed addressing modes supported. Finally, it provides basics on serial communication and differences between serial and parallel data transfer.

Uploaded by

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

L7 - 8051 Interrupt, Timer and Addressing Modes

The document discusses the 8051 microcontroller's interrupt structure, timers, addressing modes, and serial communication capabilities. It describes the five interrupt types, how interrupts are prioritized and enabled, and how the interrupt service routines function. It explains how the two 16-bit timers work and how their various operating modes are set in the TMOD register. It also outlines the immediate, register, direct, register indirect, and indexed addressing modes supported. Finally, it provides basics on serial communication and differences between serial and parallel data transfer.

Uploaded by

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

8051 MICRCONTROLLER

INTERRUPT, TIMER AND


ADDRESSING MODES
Farhan Sadaf
Lecturer, Dept. of CSE
INTERRUPT STRUCTURE
 An interrupt is an external or internal event that disturbs the
microcontroller to inform it that a device needs its service.
 The program which is associated with the interrupt is called the
interrupt service routine (ISR) or interrupt handler.
 Upon receiving the interrupt signal, the Microcontroller finish
current instruction and saves the PC on stack.
 Jumps to a fixed location in memory depending on type of
interrupt starts to execute the interrupt service routine until
RETI (return from interrupt).

2
INTERRUPT STRUCTURE
 After executing the RETI the microcontroller returns to the
place where it was interrupted.
 The 8051 microcontroller has FIVE interrupts in addition to
Reset. They are :
 Timer 0 overflow Interrupt
 Timer 1 overflow Interrupt
 External Interrupt 0 (INT0)
 External Interrupt 1 (INT1)
 Serial port events Interrupt.

3
INTERRUPT STRUCTURE
 Each interrupt has a specific place in code memory where
program execution (interrupt service routine) begins.
 External Interrupt 0: 0003 H
 Timer 0 overflow: 000B H
 External Interrupt 1: 0013 H
 Timer 1 overflow: 001B H
 Serial Interrupt : 0023 H
 Upon reset all Interrupts are disabled & do not respond to
the Microcontroller. These interrupts must be enabled by
software in order for the Microcontroller to respond to
them.
 This is done by an 8-bit register called Interrupt Enable 4

Register (IE).
INTERRUPT ENABLE REGISTER

• EA : Global enable/disable. To enable the interrupts this bit


must be set High.
• --- : Undefined-reserved for future use.
• ET2 : Enable /disable Timer 2 overflow interrupt.
• ES : Enable/disable Serial port interrupt.
• ET1 : Enable /disable Timer 1 overflow interrupt.
• EX1 : Enable/disable External interrupt1.
• ET0 : Enable /disable Timer 0 overflow interrupt. 5

• EX0 : Enable/disable External interrupt0


INTERRUPT STRUCTURE
PRIORITY
 Upon reset the interrupts have the following priority. (Top to
down). The interrupt with the highest PRIORITY gets serviced
first.
 External interrupt 0 (INT0)
 Timer interrupt 0 (TF0)
 External interrupt 1 (INT1)
 Timer interrupt 1 (TF1)
 Serial interrupt (RI+TI)

6
INTERRUPT PRIORITY
REGISTER

• IP.7 and IP.6: reserved


• IP.5: Timer 2 interrupt priority bit
• IP.4: Serial port interrupt priority bit
• IP.3: Timer 1 interrupt priority bit
• IP.2: External interrupt 1 priority bit
• IP.1: Timer 0 interrupt priority bit
• IP.0: External interrupt 0 priority bit
7
INTERRUPT (FROM BOOK)
 Time Flag interrupt
 Serial Port interrupt

 External interrupts

 Reset

 Interrupt control

 Interrupt Enable/Disable

8
TIMERS IN 8051
MICROCONTROLLERS
 The 8051 microcontroller has two 16-bit timers Timer 0 (T0)
and Timer 1 (T1) which can be used either to generate accurate
time delays or as event counters.

 These timers are accessed as two 8-bit registers TL0, TH0 &
TL1 ,TH1 because the 8051 microcontroller has 8-bit
architecture.

9
TIMER 0
 The Timer 0 is a 16-bit register and can be treated as two 8-bit
registers (TL0 & TH0) and these registers can be accessed
similar to any other registers like A,B or R1,R2,R3 etc…
 Ex : The instruction Mov TL0,#07 moves the value 07 into
lower byte of Timer0.
 Similarly Mov R5,TH0 saves the contents of TH0 in the R5
register.

10
TIMER 1
 The Timer 1 is also a 16-bit register and can be treated as two
8-bit registers (TL1 & TH1) and these registers can be accessed
similar to any other registers like A,B or R1,R2,R3 etc…
 Ex : The instruction MOV TL1,#05 moves the value 05 into
lower byte of Timer1.
 Similarly MOV R0,TH1 saves the contents of TH1 in the R0
register

11
TIMER MODE OPERATION (FROM
BOOK)
 Timer Mode 0
 Timer Mode 1

 Timer Mode 2

 Timer Mode 3

12
TMOD REGISTER
 The various operating modes of both the timers T0 and T1 are
set by an 8-bit register called TMOD register. In this TMOD
register the lower 4-bits are meant for Timer 0 and the higher 4-
bits are meant for Timer1.

13
TMOD REGISTER
 GATE: This bit is used to start or stop the timers by hardware.
When GATE = 1 ,the timers can be started / stopped by the
external sources. When GATE = 0, the timers can be started or
stopped by software instructions like SETB TR0 or SETB TR1
 C/T (clock/Timer) : This bit decides whether the timer is used
as delay generator or event counter. When C/T = 0 ,the Timer
is used as delay generator and if C/T = 1 the timer is used as
an event counter. The clock source for the time delay is the
crystal frequency of 8051.

14
TMOD REGISTER
 M1,M0 (Mode) : These two bits are the timer mode bits. The
timers of the 8051 can be configured in four modes.Mode0,
Mode1, Mode2 and Mode3.The selection and operation of the
modes is shown below.
S.No M0 M1 Mode Operation
1 0 0 0 13-bit Timer mode
Use the THX register as an 8-bit counter and the TLX
as a 5-bit counter.

2 0 1 1 16-bit Timer mode.


Use the THX register as an 8-bit counter and the TLX
as an 8-bit counter.
3 1 0 2 8-bit auto reload. THX contains a value that is to be
loaded into TLX each time it overflows. Use only TLX
register as an 8 bit counter.

4 1 1 3 Split timer mode. In this mode, Timer 0 is configured as


2 separate 8 bit timers and Timer 1 is stopped 15
ADDRESSING MODES
The way in which the instruction is specified.

 Immediate
 Register

 Direct

 Register Indirect

 Indexed

16
IMMEDIATE ADDRESSING MODE
 Immediate Data is specified in the instruction itself

Egs:
MOV A, #65H
MOV A, #’A’
MOV R6, #65H
MOV DPTR, #2343H
MOV P1, #65H

17
REGISTER ADDRESSING MODE
MOV Rn, A ;n=0,..,7
ADD A, Rn
MOV DPTR, R6

18
DIRECT ADDRESSING MODE
Although the entire of 128 bytes of RAM can be accessed using
direct addressing mode, it is most often used to access RAM
loc. 30 – 7FH.

MOV R0, 40H


MOV 56H, A
MOV A, 4 ; ≡ MOV A, R4
MOV 6, 2 ; copy R2 to R6
; MOV R6,R2 is invalid !

19
REGISTER INDIRECT ADDRESSING MODE
In this mode, register is used as a pointer to the data.

MOV A, @R0 ; move content of RAM location


where address is held by R0 into A

MOV @R1, B

In other word, the content of register R0 or R1 is sources or


target in MOV, ADD and SUB instructions.

20
INDEXED ADDRESSING MODE AND
ON-CHIP ROM ACCESS
This mode is widely used in accessing data elements of look-up
table entries located in the program (code) space ROM at the
8051

MOVC A, @A+DPTR
A= content of address A + DPTR from ROM
Note:
Because the data elements are stored in the program (code )
space ROM of the 8051, it uses the instruction MOVC instead
of MOV. The “C” means code.

21
8051- SERIAL COMMUNICATION

22
BASICS OF SERIAL
COMMUNICATION

23
TYPES OF SERIAL
COMMUNICATIONS

24
DATA TRANSFER AND PARALLEL
DATA TRANSFER
S.No Serial Communication Parallel Communication
1 Data is transmitted bit after the bit in a single line Data is transmitted simultaneously through group of
lines(Bus)
2 Data congestion takes place No, Data congestion
3 Low speed transmission High speed transmission
4 Implementation of serial links is not an easy task. Parallel data links are easily implemented in hardware

5. In terms of transmission channel costs such as data bus It is more expensive


cable length, data bus buffers, interface connectors, it is less
expensive

6 No , crosstalk problem Crosstalk creates interference between the parallel lines.

7 No effect of inter symbol interference and noise Parallel ports suffer extremely from inter-symbol
interference (ISI) and noise, and therefore the data can be
corrupted over long distances.

8 The bandwidth of serial wires is much higher. The bandwidth of parallel wires is much lower.

9 Serial interface is more flexible to upgrade , without Parallel data transfer mechanism rely on hardware
changing the hardware resources and hence not flexible to upgrade.
25
10 Serial communication work effectively even at high Parallel buses are hard to run at high frequencies.
frequencies.
SERIAL COMMUNICATION IN 8051
MICROCONTROLLER
 The 8051 has two pins for transferring and receiving data by
serial communication.
 These two pins are part of the Port3(P3.0 &P3.1).

 Serial communication is controlled by an 8-bit register called


SCON register, it is a bit addressable register.
 SCON (Serial control) register :

 The SCON register is an 8-bit register used to program the start


bit, stop bit, and data bits of data framing, among other things.

26
SCON (SERIAL CONTROL)
REGISTER

SM0 SCON.7 Serial port mode selector

SM1 SCON.6 Serial port mode selector

SM2 SCON.5 Used for multiprocessor mode communication (not


applicable for 8051)

REN SCON.4 Receive enable. Set or cleared by making this bit either 1 or
0 foe enable /disable reception.

TB8 SCON.3 9th data bit transmitted in modes 2 and 3 (not widely used)

RB8 SCON.2 9th data bit received in modes 2 and 3.it is not used in mode
0 & mode 1.If SM2 = 0 RB8 is the stop bit . (not widely
used)

TI SCON.1 Transmit interrupt flag

RI SCON.0 Receive interrupt flag.


27
SBUF REGISTER
 SBUF is an 8-bit register used solely for serial communication
in the 8051.
 For a byte of data to be transferred via the TxD line, it must be
placed in the SBUF register.
 Similarly, SBUF holds the byte of data when it is received by
the 8051 ‘s RxD line.
 SBUF can be accessed like any other register in the 8051.

 Look at the following examples of how this register is


accessed:

28
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 pin.
 Similarly, 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 the SBUF.

29
SCON (SERIAL CONTROL)
REGISTER
 SM0, SM1 : These two bits of SCON register determine the
framing of data by specifying the number of bits per character
and start bit and stop bits. There are 4 serial modes.
SM0 SM1
0 0 : Serial Mode 0
0 1 : Serial Mode 1
1 0 : Serial Mode 2
1 1 : Serial Mode 3

30
SCON (SERIAL CONTROL)
REGISTER
 In the SCON register, when serial mode 1 is chosen, the data
framing is 8 bits, 1 stop bit, and 1 start bit, which makes it
compatible with the COM port of IBM/compatible PCs.
 In serial mode 1, for each character a total of 10 bits are
transferred, where the first bit is the start bit, followed by 8 bits
of data, and finally 1 stop bit.

31
SCON (SERIAL CONTROL)
REGISTER
 REN (Receive Enable) also referred as SCON.4. When it is
high, it allows the 8051 to receive data on the RxD pin. So to
receive and transfer data REN must be set to 1.When
REN=0,the receiver is disabled. This is achieved as below
SETB SCON.4
& CLR SCON.4

32
SCON (SERIAL CONTROL)
REGISTER
 TI (Transmit interrupt) is the D1 bit of SCON register. When
8051 finishes the transfer of 8-bit character, it raises the TI flag
to indicate that it is ready to transfer another byte. The TI bit is
raised at the beginning of the stop bit.
 RI (Receive interrupt) is the D0 bit of the SCON register.
When the 8051 receives data serially ,via RxD, it gets rid of
the start and stop bits and places the byte in the SBUF register.
Then 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.

33
Thank You

34

You might also like