Unit III 8051 Microcontroller
Unit III 8051 Microcontroller
8051 Microcontroller
S.
N Microprocessor Microcontroller
o
Access times for memory and I/O Less access time for built in (memory and I/O
4
devices are more devices)
6 It is more flexible in design point of view Less flexible in design point of view.
It has single memory map for data and It has separate memory map for
8
code data and code
It has address bus, data bus and control Microcontroller communicates with
9 bus for interfacing with the outside outside world through P0, P1,
world. P2,P3 ports
What is Microprocessor?
A microprocessor is a central processing unit (CPU) that is designed to
execute instructions and perform arithmetic and logical operations in a
computer system. It is an integrated circuit that serves as the “brain” of a
computer or other electronic devices.
Microprocessors are responsible for carrying out the instructions of a
computer program by fetching, decoding, and executing them. They are
commonly found in personal computers, laptops, smartphones, and various
electronic devices.
Unlike microcontrollers, microprocessors are typically used in systems that
require general-purpose computing capabilities and are not dedicated to
specific control functions
Microprocessors:
General-purpose microprocessor
• CPU for Computers
• No RAM, ROM, I/O on CPU chip itself
• Example : Intel’s x86, Motorola’s 680x0
8051 Microcontroller
8051 also known as MCS-51 is one of the most popular microcontroller.
Initially, it was created using NMOS technology but since NMOS technology needs more
power to function therefore later Intel introduced a new version of 8051
microcontroller based on CMOS technology and this new edition is called 80C51.
These most modern Microcontrollers need a fewer amount of power to function in
comparison to their forerunners.
8051 is an 8-bit microcontroller that includes 40-pins with dual inline package or DIP,
128 bytes RAM, 4-kb ROM and two 16-bit timers. It also includes four parallel 8-bit
ports that are programmable and addressable based on the requirement. It also has an
on-chip crystal oscillator of frequency 12 MHz integrated in it.
8051 Architecture
CPU (Central Processing Unit)
The Central Processor Unit or CPU is the mind of any processing machine.
It scrutinizes and manages all processes that are carried out in the
Microcontroller.
It interprets the program printed in storage space (ROM) and carries out all of
them and does the projected duty.
It also manages different types of registers in the microcontroller.
Interrupts
Interrupt is a subroutine (Subroutines are programs that are used by other
routines to accomplish a particular task. A set of instructions that are used
repeatedly in a program can be referred to as a Subroutine) call that
temporarily suspends the Microcontroller’s main program and helps it to
perform some other program which is more important than that at that
particular time and resume the main program where it had left it off.
Interrupts provide us a method to postpone the current process, carry out a
sub-routine task and then all over again restart standard program
implementation.
8051 has 5 interrupt sources, out of which two are peripheral Interrupts, two
are timer interrupts and one is a serial port interrupt.
Memory
A program is a set of commands, which is needed by the Microcontroller to
perform a particular task.
These programs need a storage space where they can be stored and later the
microcontroller interpret them and perform the specific task.
8051 microcontroller architecture include two types of memory, such as :
program memory and data memory.
GND
Power Supply Signal
Vcc provides supply voltage to the chip.
The voltage source is +5V.
GND ( pin 20 ): ground
RST ( pin 9 ): reset (Input)
•input pin and active high.
•The high pulse must be high at least 2 machine cycles.
•There are two ways to reset the controller
Power on Reset
Manual Reset
Power-on reset.
Upon applying a high pulse to RST, the microcontroller will reset and all
values in registers will be lost.(PC,ACC,B,DPTR are 0000H and Content of SP
0007H)
Vcc
31
EA/VPP
X1
10 uF 30 pF
X2
RST
9
8.2 K
* Power On Reset.
•Manual Reset
Register A (Accumulator)
• It is an 8 bit register
• It holds a source operand( it defines the data being processed by the
instructions JNZoffset) and receives the result of the arithmetic
instruction( addition, subtraction, multiplication and division)
• The accumulator can be the source or destination for logical operations
and no of special data movement instructions….
Register B
• It is an 8 bit B register
• It is an general purpose register.
• It is used for the Multiply/Divide operation to store the second operand for
MUL & DIV instruction.
• It hold Upper 8 bit of result and remainder in case of division are
stored in B register
Register Set of 8051
Program Status Word (PSW)
* It is an 8 bit register
CY AC F0 RS1 RS0 OV -- P
Timing Register
• It is an two 16 bit register
• It will access lower and upper bytes.
• The TH0 and TL0 represent lower and upper byte of timer 0
• The TH1 and TL1 represent lower and upper byte of timer 1.
• The address of register have been stored in SFR from 80H to FFH.
• There is a Timer control (TCON) and Timer Mode(TMOD) register to
configure all timer/counter in various modes.
Control Register
Instruction Register
RAM
This block provide internal on chip RAM 128 bytes.
ALU
SFR ( Special Function Register)
This register bank is a set of registers
Name Function Name Function
Program
PC
Address
DPTR
Register
0FFFH 4K
EPROM/
0000H ROM
I/O Ports
It has 32 I/O pins configured as four eight bit parallel ports (P0,P1, P2, P3)
all are bidirectional each pin will be configured as input and output (or
Both) under software control. Each port consist of Latch output driver and
an input buffer.
PORT 0
• When connecting an 8051 to an external memory, the 8051 uses ports to send addresses and read instructions.
– 16-bit address : P0 provides both address A0-A7, P2 provides address A8-A15.
– Also, P0 provides data lines D0-D7.
• When P0 is used for address/data multiplexing, it is connected to the 74LS373 to latch the address
Vcc
10 K
P0.0
DS5000 P0.1
Port 0
P0.2
8751 P0.3
8951 P0.4
P0.5
P0.6
P0.7
• Here if there is no pull up, when switch is open
the input is in floating state that means it is
neither high nor low. You cannot know the
state of the pin.
• Now if you use a pull up resistor (usually around
10k)
– when switch is open the input is connected to vcc
through resistor and the input reads high.
– If the switch is closed the input reads low
because no current flows into input pin.
• Not only 8051 we can use pull up resistor for
any microcontrollers, but new microcontrollers
nowadays have inbuilt pull up resistors which
you can configure.
IMPORTANT PINS (IO Ports)
TB1
Read pin
Writing “1” to Output Pin P1.X
TB1
Read pin
Writing “0” to Output Pin P1.X
TB1
Read pin
Reading “High” at Input Pin
1 1 P1.X pin
Internal CPU bus D Q
P1.X
0 M1
Write to latch Clk Q
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
Timer /Counters
Timer is used to count machine cycle and provide a specified time
delay.
C/T(Clock/Timer)
The C/T bit in TMOD register is used to take decision
whether the timer is used as a timer or an counter.
If
C/T=0 : Timer/counter selector bit is cleared to generate
time delay.
C/T=1 : Timer/Counter selector bit is counting pulses from
external input pin Tx (T1 and T0)
TCON (Timer Control Register)
Two registers
• Used to hold data that to be transmitted through TxD it is
write only type.
• Used to hold data from external sources through RxD it
is read only type.
Serial control (SCON) Register
All functions are stopped, the contents of the on-chip RAM and
Special Function Registers are maintained.
* The ALE and PSEN output are held low
* The reset that terminates Power Down
Interrupts
An interrupt is an external or internal event that interrupts the microcontroller to
inform it that a device needs its service.
IP.7: reserved
IP.6: reserved
IP.5: timer 2 interrupt priority bit(8052 only)
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
Interrupt Priorities Example
--- --- PT2 PS PT1 PX1 PT0 PX0