UNIT-1
UNIT-1
A smaller computer
On-chip RAM, ROM, I/O ports...
Example:Intel’s 8051, Motorola’s 6811, Zilog’s Z8 and PIC 16X
Microcontroller
MICROCONTROLLERS VS MICROPROCESSORS
MICROPROCESSOR:
❖ A CPU built into a single VLSI chip is called a microprocessor.
❖ It is a general-purpose device and additional external circuitry is added to make it a
microcomputer.
❖ The microprocessor contains arithmetic and logic unit (ALU), Instruction decoder and
control unit, Instruction register, Program counter (PC), clock circuit (internal or external),
reset circuit (internal or external) and registers.
❖ But the microprocessor has no on chip I/O Ports, Timers, Memory etc.
❖ For example, Intel 8085 is an 8-bit microprocessor and Intel 8086/8088 a 16-bit
microprocessor.
❖ The block diagram of the Microprocessor is shown in Fig.4.1
MICROCONTROLLER:
❖ A microcontroller is a highly integrated single chip, which consists of on chip CPU
(Central Processing Unit), RAM (Random Access Memory), EPROM/PROM/ROM
(Erasable Programmable Read Only Memory), I/O (input/output) – serial and parallel,
timers, interrupt controller.
❖ For example, Intel 8051 is 8-bit microcontroller and Intel 8096 is 16-bit microcontroller.
❖ The block diagram of Microcontroller is shown in Fig.4.2.
S. No Microprocessor Microcontroller
A microprocessor is a general
A microcontroller is a dedicated chip which
1 purpose device which is called a
is also called single chip computer.
CPU
A microcontroller includes RAM, ROM,
A microprocessor do not contain on
serial and parallel interface, timers,
2 chip I/O Ports, Timers, Memories
interrupt circuitry (in addition to CPU) in a
etc..
single chip.
Microprocessors are most Microcontrollers are used in small,
3 commonly used as the CPU in minimum component designs performing
microcomputer systems control-oriented applications.
Microprocessor instructions Are Microcontroller instructions are both bit
4
mainly nibble or byte addressable addressable as well as byte addressable.
Microprocessor instruction sets are Microcontrollers have instruction sets
5 mainly intended for catering to catering to the control of inputs and
large volumes of data. outputs.
Microprocessor based system Microcontroller based system design is
6
design is complex and expensive rather simple and cost effective
The instruction set of a Microcontroller is
The Instruction set of
very simple with less number of
7 microprocessor is complex with
instructions. For, ex: PIC microcontrollers
large number of instructions.
have only 35 instructions.
A microprocessor has zero status
8 A microcontroller has no zero flag.
flag
8051
Pin Description of the 8051
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3 4 37 P0.2(AD2)
P1.4 5 8051 36 P0.3(AD3)
P1.5 6 35 P0.4(AD4)
P1.6 7
(40 PIN) 34 P0.5(AD5)
P1.7 8 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RXD)P3.0 10 31 EA/VPP
(TXD)P3.1 11 30 ALE/PROG
(INT0)P3.2 12 29 PSEN
(INT1)P3.3 13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14)
(T1)P3.5 15 26 P2.5(A13)
(WR)P3.6 16 25 P2.4(A12)
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
Pins of 8051
VCC pin 40 :VCC provides supply voltage to the chip. [+5V]
GND pin 20 :ground
XTAL1 and XTAL2 pins 19,18 : C2
These 2 pins provide external XTAL
clock frequency for the operation. 30p 2
F
C1
XTAL
30p 1
F
GN
D
Program Status Word: Set of flags contains the status information. It is one of the SFR.
Data Pointer: 16-bit register contains a high byte (DPH) and low byte (DPL). It has been
allotted two addresses in the SFR bank for its two bytes DPH and DPL.
Port 0 to 3 Latches and Drivers: These 4 latches and driver pairs are allotted to each of the 4
on-chip I/O ports. These latches have been allotted addresses in the SFR bank. Using the
allotted address the user can communicate with these ports (P0,P1,P2,P3)
Serial Data Buffer: It contains 2 independent register one of them is transmit buffer, which is a
parallel-in-serial-out register. The other is a receive buffer, which is a serial-in-parallel-out
register. It is one of the SFR.
Timer Registers: Two 16-bit registers. TL0, TH0 represent the lower and higher byte of timer
register 0, similarly TL1, TH1 represent the lower and higher byte of timer register 1.
10
Control Registers: It contains control and status information for interrupts
Timing and Control Unit: It derives all the necessary timing at control signals register for
internal operation of the circuit.
Oscillator: It generates the basic timing clock signal for the operation of the circuit using
crystal oscillator.
Instruction Register: This register decodes the opcode of an instruction to be executed and
gives information to the timing and control unit to generate necessary signals on the execution
of instruction.
EPROM and Program Address Register: It provides an on chip EPROM and a mechanism to
internally address it.
RAM and RAM Address Register: It provide internal 128 bytes of RAM and a mechanism to
address it internally.
ALU: It performs 8-bit arithmetic, logical operations over the operands held by temporary
register TMP1 and TMP2. users can’t access these temp. register.
11
ADDRESSING MODES
OF 8051
12
ADDRESSING MODES OF 8051
The 8051 provides a total of five distinct addressing
modes.
1. Immediate Addressing mode
2. Register Addressing mode
3. Direct Addressing mode
4. Register Indirect Addressing mode
5. Indexed Addressing mode
6. Register Specific Addressing mode
13
1) Immediate Addressing Mode
The operand comes immediately after the op-code.
The immediate data must be preceded by the pound sign, "#".
Ex: MOV A, #25H ; load 25H into A
MOV DPTR, #3481H ; DPTR=3481H
14
3) Direct Addressing Mode
It is most often used to access RAM locations 30 - 7FH.
In the direct addressing mode, the data is in a RAM memory location
whose
address is known, and this address is given as a part of the instruction
Ex: MOV 56H,A ; save content of A in RAM location 56H
MOV R4,34H ; move contents of RAM location 34H to R4
16
8051
INSTRUCTION SET
17
DATA TRANSFER INSTRUCTIONS
18
DATA TRANSFER INSTRUCTIONS
19
DATA TRANSFER INSTRUCTIONS
20
21
ARITHMETIC OPERATORS
M.M.Arun Prasath., AP/ECE 26 February 2014 23
24
LOGICAL OPERATIONS
JUMP & BRANCH INSTRUCTIONS
26
8051
TIMER/COUNTER
SERIAL DATA INPUT/OUTPUT
8051 has a serial data communication circuit that uses
Register Serial port data Buffer (SBUF):
SBUF is physically two registers.
One is write only and is used to hold data to be transmitted out of
the 8051 via TXD
Other is read only and holds the received data from external
sources via RXD
Register Serial port control (SCON):
Controls data communication
There are four programmable modes for serial data
communication that are chosen by setting the SMx bits in SCON.
Register Power mode control (PCON):
Controls data rates and pins RXD & TXD
SCON 7 6 5 4 3 2 1 0
SM0 SM1 SM2 REN TB8 RB8 TI RI
SMOD: Serial baud rate modify bit. Set to double baud rate
using timer 1 for modes 1,2 & 3.
6-4: Not implemented.
GF1: General purpose user flag bit 1.
GF0: General purpose user flag bit 0.
PD: By setting this bit the microcontroller enters the Power
Down mode
IDL: By setting this bit the microcontroller enters
the Idle mode.
34
35
INTERRUPTS
Interrupts may be generated by the internal chip
operations or provided by the external sources.
5 interrupts are available in 8051
3 are generated automatically by the internal operations:
Timer flag 0, Timer flag 1 & Serial port interrupt (RI or
TI)
2 are triggered by external signals provided by the
circuitry that is connected to pins INT0‾ and INT1‾
Programmer is able to alter control bits in the IE, IP and
TCON.
INTERRUPT ENABLE (IE)
7 6 5 4 3 2 1 0
EA -- ET2 ES ET1 EX1 ET0 EX0