0% found this document useful (0 votes)
2 views

Module-3

Uploaded by

anu.spamm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module-3

Uploaded by

anu.spamm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Department of Electronics and Computer Science

TE(ETRX) SEM-V
Microcontrollers & Applications
By
Dr. Arun Chavan

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Internal Hardware

Memory Organization

Pin Configuration

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Architecture
Features of 8051
• 40 pin chip, requires +5v dc supply, provides TTL compatible signals
• 4KB bytes on-chip program memory (ROM), expandable up to 64 KB
• 128 bytes on-chip data memory (RAM), expandable up to 64 KB
• Four register banks of 8 registers each
• 128 user defined software flags (128 bit addressable memory)
• 8-bit bidirectional data bus
• 16-bit unidirectional address bus
• 32 general purpose registers each of 8-bit
• Two, 16 bit Timer/Counters
• One full duplex serial port
• Three internal and two external Interrupts
• Four 8-bit input/output ports (Port 0, Port 1, Port 2, Port 3)
• 16-bit program counter (PC) and data pointer(DPTR)
• Provides on chip clock generator ckt.
8051 Architecture

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Architecture

8051 CPU PSW (Program Status Word)

• ALU - 8 bit

• A - Register (8-Bit)

• B - Register (8-Bit)

• SP- Register (8-Bit)

• PSW- Register (8-Bit)

• PC- Register (16-Bit)

• DPTR- Register (16-Bit)


Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Data Memory
RAM Organization in 8051

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Data Memory
ROM Organization in 8051

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Microcontroller
Pin Configuration
8051 Microcontroller
Pin Configuration

Pins 1 to 8 − These pins are known as


Port 1. This port doesn’t serve any other
functions. It is internally pulled up, bi-
directional I/O port.
Pin 9 − It is a RESET pin, which is used to
reset the microcontroller to its initial
values.
Pins 10 to 17 − These pins are known as
Port 3. This port serves some functions like
interrupts, timer input, control signals,
serial communication signals RxD and
TxD, etc.
Pins 18 & 19 − These pins are used for
interfacing an external crystal to get the
system clock.
Pin 20 − This pin provides the power
supply to the circuit. Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Microcontroller
Pin Configuration
Pins 21 to 28 − These pins are known as Port 2.
It serves as I/O port. Higher order address bus
signals are also multiplexed using this port.
Pin 29 − This is PSEN pin which stands for
Program Store Enable. It is used to read a signal
from the external program memory.
Pin 30 − This is ALE pin which stands for
Address Latch Enable. It is used to demultiplex
the address-data signal of port.
Pin 31 − This is EA pin which stands for
External Access input. It is used to
enable/disable the external memory interfacing.
Pins 32 to 39 − These pins are known as Port 0.
It serves as I/O port. Lower order address and
data bus signals are multiplexed using this port.
Pin 40 − This pin is used to provide power
supply to the circuit.
Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Microcontroller

Quiz

1. Which Port of 8051 is used as Address/Data


a. Port 0 b. Port 1 c. Port 2
2. When EA* pin is grounded, 8051 can address how much amount
of external ROM
a. 64 Kb b. 60 Kb c. 4 Kb
3. T0 & T1 inputs are used by the Timer/Counter in
a. Timer mode b. Counter mode c. Timer as well as
Counter mode
4. Which Port of 8051 is used as Higher Order Address Bus
a. Port 0 b. Port 1 c. Port 2
5. RxD & TxD are alternate functions of which two port pins
a. P3.0 & P3.1 b. P3.2 & P3.3 c. P3.4 & P3.5
Dr. Arun Chavan, Department of Electronics
and Computer Science
Assignment no - 4

Short Questions (2 Marks)

1. List the subunits of CPU


2. What are the alternate functions of Port 3 pins

Descriptive Questions (5 Marks)

1. Discuss ‘Memory Organization’ in 8051


2. Draw and explain PSW for 8051.
Timer/Counter of 8051

• The Timer and Counter in 8051 Microcontroller has two 16-bit


Timer/Counter registers : Timer/Counter 0 and Timer/Counter 1, can be
configured to operate either as timers or event counters.

• In the “Timer” mode, the register is incremented after every machine


cycle. Thus, one can think of it as counting machine cycles. Since a
machine cycle consists of 12 oscillator periods, the count rate is 1/12 of
the oscillator frequency.

• In the “Counter” mode, the register is incremented in response to, a 1-to-


0 transition at its corresponding external input pin, T0, T1. In this mode,
the external input is sampled during every machine cycle. When the
samples show a high in one cycle and a low in the next cycle, the count is
incremented.

• In addition to the “Timer” or “Counter” selection, Timer/Counter 0 and


Timer/Counter 1 have four operating modes from which to select.
Timer/Counter of 8051

• The SFRs for the two timer/counters are TL0 (8Ah) and TH0 (8Ch) for
Timer/Counter 0 while TL1 (8Bh) and TH1 (8Dh) for the Timer/Counter 1.

• TCON (88h) and TMOD (89h) control their operation & modes.

• There are four modes of operation of the two timer/counters set by TMOD

TMOD:
Timer/Counter of 8051

TCON:

Dr. Arun Chavan, Department of Electronics


and Computer Science
Timer/Counter of 8051
Timer/Counter Modes

Mode 0:

Dr. Arun Chavan, Department of Electronics


and Computer Science
Timer/Counter of 8051
Timer/Counter Modes

Mode 1:

Dr. Arun Chavan, Department of Electronics


and Computer Science
Timer/Counter of 8051
Timer/Counter Modes

Mode 2:

Dr. Arun Chavan, Department of Electronics


and Computer Science
Timer/Counter of 8051
Timer/Counter Modes

Mode 3:

Dr. Arun Chavan, Department of Electronics


and Computer Science
Timer/Counter of 8051
Delay Routine using Timer-0
ORG 0000H
MOV P1, #00H
MOV TMOD, #01H
LOOP:CPL P1.5
ACALL DELAY
SJMP LOOP

DELAY:MOV R0, #10


MOV TL0, #00H
MOV TH0, #00H
SETB TR0
TIMERLOOP:JNB TF0, TIMERLOOP
CLR TF0
DJNZ R0, TIMERLOOP
CLR TR0
RET

Dr. Arun Chavan, Department of Electronics


and Computer Science
Timer/Counter of 8051
Write assembly language program to generate the delay of 500 us and 1 sec using T1M1(timer 1
in mode 1) and T0M1(timer 0 in mode 1) respectively, assume the oscillator frequency as 12
MHz.

Delay-500 us Delay-1 Sec

Delay:Mov TMOD, #10H Delay:Mov R0, #20


Mov TL1, #0CH Mov TMOD, #01H
Mov TH1, #FEH Again:Mov TL0, #B0H
SETB TR1 Mov TH0, #3CH
Here: JNB TF1, Here SETB TR0
CLR TR1 Here: JNB TF0, Here
CLR TF1 CLR TR0
RET CLR TF0
DJNZ R0, Again
RET

Dr. Arun Chavan, Department of Electronics


and Computer Science
Timer/Counter of 8051
Quiz

1. Which mode of Timer/Counter is 8-bit auto reload mode


a. Mode 0 b. Mode 1 c. Mode 2
2. Timer/Counter acts as 13-bit Timer/Counter in
a. Mode 0 b. Mode 2 c. Mode 1
3. TF0 & TF1 bits are part of which SFR
a. TMOD b. TCON
4. Timer/Counter can be programmed in one of the four modes with
a. TMOD b. TCON
5. In Timer mode the Timer/Counter value is incremented after every
machine cycle
a. True b. False
Dr. Arun Chavan, Department of Electronics
and Computer Science
Serial Port of 8051
Serial Port

• One full duplex serial port


• TxD & RxD pins for serial communication
• Can be programmed in 4 different modes
• Baud rate is programmable
• SFRs associated with the serial port are SCON, PCON & SBUF

Dr. Arun Chavan, Department of Electronics


and Computer Science
Serial Port of 8051
SCON
Serial Port of 8051
PCON

Dr. Arun Chavan, Department of Electronics


and Computer Science
Serial Port of 8051
Modes of Serial Port

Mode 0
Simple 8-bit shift register
• Serial Data enters and exits
through RxD
• Half duplex communication
• 8 bits are transmitted/received
(LSB first)
• The baud rate is fixed at 1/12
the oscillator frequency

Dr. Arun Chavan, Department of Electronics


and Computer Science
Serial Port of 8051
Modes of Serial Port
Mode 1
• 8-bit UART
• Serial Data enters and exits through RxD & TxD respectively
• Full duplex communication
• 10-bits are transmitted/received (1-start bit, 8-data bits, 1-stop bit)
• The baud rate is given by (2SMOD/32)* [Fosc/12(256-TH1)]

Dr. Arun Chavan, Department of Electronics


and Computer Science
Serial Port of 8051
Modes of Serial Port
Mode 2
• 9-bit UART
• Serial Data enters and exits
through TxD & RxD
respectively
• Full duplex communication
• 11-bits are transmitted/received (1-start bit, 8-data bits, 1-user
programmable bit, 1-stop bit)
• The baud rate is given by (2SMOD/64)* Fosc

Dr. Arun Chavan, Department of Electronics


and Computer Science
Serial Port of 8051
Modes of Serial Port

Mode 3
9-bit UART
• Serial Data enters and
exits through TxD & RxD
respectively
• Full duplex communication
• 11-bits are transmitted/received (1-start bit, 8-data bits, 1-user
programmable bit, 1-stop bit)
• The baud rate is given by (2SMOD/32)* [Fosc/12(256-TH1)]

Dr. Arun Chavan, Department of Electronics


and Computer Science
Serial Port of 8051
Write assembly language program to transmit the character ‘S’ to the serial port,
use 9600 as the baud rate (assume the oscillator frequency as 12 MHz)?

Org 0000H
SJMP Start

Start:
Mov SCON, #40H ;program the serial port
Mov PCON, #00H ;program SMOD bit = 0
Mov TMOD, #20H;program timer 1 in mode 2
Mov TL1, #0FDH;load the count for 9600 baud
Mov TH1, #0FDH;load the count for 9600 baud
SETB TR1; timer 1 ON
Mov SBUF, #’S’; write the character in the SBUF register
Here: JNB TI, Here; check the interrupt register for TI
CLR TI; reset TI when found set
CLR TR1; timer 1 OFF
Stop: SJMP Stop
END Dr. Arun Chavan, Department of Electronics
and Computer Science
Serial Port of 8051
Quiz

1. In Mode 1, serial port acts as


a. 8-bit UART b. 9-bit UART c. 8-bit shift reg.
2. Baud rate is fixed in
a. Mode 3 b. Mode 1 & Mode 3 c. Mode 0 & Mode 2
3. Baud rate in Mode 1,2 &3 is doubled by _______ SMOD-bit
of PCON register
a. Setting b. Resetting
4. The vector location for serial interrupts TI & RI is
a. 0003H b. 000BH c. 0023H
5. In Mode 1 & 3 baud rate depends on Timer-1 overflow rate
a. True b. False
Dr. Arun Chavan, Department of Electronics
and Computer Science
Assignment no - 5

Descriptive Questions (5 Marks)

1. Write a delay routine for 8 msec using Timer/Counter-0 of 8051, assume the OSC frequency
to be 12 MHz
2. What will be the count programmable in the serial port of 8051 for the baud rate of 4200

Descriptive Questions (10 Marks)

1. Discuss the modes of Timer/Counter of 8051 with associated SFRs & logic diagram for
internal hardware.
2. Discuss the modes of serial port of 8051 with SFRs associated
Interrupt Structure of 8051
Interrupts
• 8051 has five interrupt sources
• INT0, INT1,TF0 ,TF1 , TI/RI
All the interrupts can be enabled or disabled using the IE (interrupt
enable) register
• Higher/Lower priority for interrupts can be programmed with IP
(interrupt priority) register
Interrupt Address
• All the interrupt sources are
INT0 0003H
vectored INT1 0013H
• SFRs associated with interrupt TF0 000BH
Structure of 8051 are IE, IP TF1 001BH
& TCON TI/RI 0023H
Interrupt Structure of 8051
SFRs associated with Interrupt structure of 8051
IE (Interrupt Enable) Register
Bit Address AF AE AD AC AB AA A9 A8

Bit Details EA X X ES ET1 EX1 ET0 EX0

Bit Details High Value(1) Low Value(0)


EA Least significant 5 bits can decide enable or disable of Disable all five interrupts. It just ignores the rest five
these five interrupts bits
ES Enable Serial Port Interrupt Disable Serial Port Interrupt

ET1 Enable Timer1 interrupt Disable Timer1 interrupt

EX1 Enable external interrupt 1 (INT1) Disable external interrupt 1 (INT1)

ET0 Enable Timer0 interrupt Disable Timer0 interrupt

EX0 Enable external interrupt 0 (INT0) Disable external interrupt 0 (INT0)


Interrupt Structure of 8051
SFRs associated with Interrupt structure of 8051
IP (Interrupt Priority) Register
Bit Address BF BE BD BC BB BA B9 B8

Bit Details X X X PS PT1 PX1 PT0 PX0

Bit Details High Priority(1) Low Priority(0)

PS High level priority of Serial port interrupt Low level priority of Serial port interrupt

PT1 High level priority of Timer1 interrupt Low level priority of Timer1 interrupt

PX1 High level priority of external interrupt 1 Low level priority of external interrupt 1
(INT1) (INT1)
PT0 High level priority of Timer0 interrupt Low level priority of Timer0 interrupt

PX0 High level priority of external interrupt 0 Low level priority of external interrupt 0
(INT0) (INT0)
Interrupt Structure of 8051
The interrupt system of 8051

Dr. Arun Chavan, Department of Electronics


and Computer Science
Interrupt Structure of 8051
The interrupt structure of 8051

Dr. Arun Chavan, Department of Electronics


and Computer Science
Interrupt Structure of 8051

Quiz

1. How many hardware interrupt sources on 8051


a. 2 b. 3 c. 5
2. Masking/Unmasking of interrupt sources is possible with
a. IE-Reg b. IP-Reg c. TCON-Reg
3. Vector location for TF0(Timer 0 Overflow) interrupt is
a. 0003H b. 000BH c. 001BH
4. Triggering level for INT0 & INT1 is programmable with
a. IE-Reg b. IP-Reg c. TCON-Reg
5. When assigned equal priority to all the interrupt sources, which
interrupt will be served first if all are received simultaneously.
a. TF0 b. INT0 c. TI/RI
Dr. Arun Chavan, Department of Electronics
and Computer Science
Power Saving Modes in 8051
Power Saving Modes
• Basically, programmed for saving power consumed by the controller i.e. I2R
loss.

• Two Power saving modes are provided, Idle & Power down

• SFR associated with power saving modes is PCON

PCON (Power Control Register)

Dr. Arun Chavan, Department of Electronics


and Computer Science
Power Saving Modes in 8051

Idle Mode
• Programed with D0-bit of
PCON
• CPU does not get continuous
clock
• Interrupt, Serial Port &
Timer connected from clock
• Oscillator circuit active
• Internal RAM, SFR contents
unchanged
• Terminated by hardware
interrupt or hardware reset
Dr. Arun Chavan, Department of Electronics
and Computer Science
Power Saving Modes in 8051

Power Down Mode

• Programed with D1-bit of


PCON
• CPU, Interrupt, Serial Port &
Timer disconnected from
clock
• Oscillator circuit inactive
• Internal RAM, SFR contents
unchanged
• Terminated with hardware
reset only
Dr. Arun Chavan, Department of Electronics
and Computer Science
Power Saving Modes in 8051

Power Saving Modes

Parameter Power Down Mode Idle Mode


Initialized by setting PCON.1 PCON.0
Any Enabled Hardware Interrupt
Terminated By By Hardware Reset Only
or Hardware Reset
Remain
Condition of If interrupted
Reinitialized Unchanged
SFRs after Exit
If resetted Reinitialized
Condition of Internal RAM Unchanged Unchanged
Condition of Ports during Sleep Unchanged Unchanged
On-Chip Oscillator Inactive Active
CPU status Inactive Inactive

Dr. Arun Chavan, Department of Electronics


and Computer Science
Power Saving Modes in 8051

Quiz

1. Power saving modes are programmed with the SFR


a. SCON b. TCON c. PCON
2. _____ bit of PCON is used to program ‘Idle Mode’
a. PCON.0 b. PCON.1 c. PCON.2
3. During ‘Power Down Mode’ CPU clock is active
a. True b. False
4. To terminate ‘Idle Mode’ 8051 needs to be
a. Resetted b. Interrupted c. Resetted or Interrupted
5. In Idle Mode clock is not provided to
a. Timer/Counter b. Serial Port c. CPU

Dr. Arun Chavan, Department of Electronics


and Computer Science
Assignment no - 6

Short Questions (2 Marks)

1. Draw the format of SFRs IE and IP for the interrupt structure of 8051
2. Draw and explain the bits related to power saving modes in the SFR PCON of 8051

Descriptive Questions (5 Marks)

1. Discuss ‘Power Saving Modes’ of 8051.

Descriptive Questions (10 Marks)

1. Discuss the interrupt structure of 8051 with SFRs and logic diagram for internal hardware
Thank You

Dr. Arun Chavan, Department of Electronics


and Computer Science

You might also like