0% found this document useful (0 votes)
10 views25 pages

MA Chap 1

Uploaded by

Jay Ware
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)
10 views25 pages

MA Chap 1

Uploaded by

Jay Ware
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/ 25

Unit 1..

Basiesof Microcontroller
and
intel 8051 Arehitecture
invented in
The first microcontroller was
1970-71, when
Texas Instruments. During
the world's
Intel was working on inventing
Boone of Texas
first microprocessor, Gray concept
Instruments was working on similar
invented microcontroller. Boone
and
chip
designed asingle integrated circuit (1C)
circuits to form acalculator, only
that could hold nearly all the essential was
were not incorporated. The first IC
the display and the keypad 3000
has 5000 transistors providing
named as TMS1302NC. This device memory. It can perform a
memory and 128 bit of access
bits of program
range of functions.

ntroduction
systems, which can be
Microcontroller is one of the powerful control
control applications in industry as
used for the measurement and sometimes
as in a specific application. Microcontroller is
well because it contains all the
described as a "Computer on Chip" Unit (CPU),
Central Processing
features of full computer including
clock circuitry ROM, RAM, input and output ports with special
inbuilt analog to digital conversion
features such as serial communication,
and more recently signal processing.
purpose device, which is meant to read data, perform
It is a general control its environment based
limited calculations on the data and microcontroller is to control
use of
on those calculations. The prime
operation of machine using a fixed program that is stored in
the of system.
ROM and that does not change over the lifetime
(1.1)
S.Y,B.Sc. (Comp. Sci.) :Elect. - P-] S-II 1-2 Basics of Microcontroller ....
Aspecial application of microcontroller is well suited for data logging
as well as monitoring and recording the environmental, physical and
chemical parameters. In addition to the above home monitoring
systems, embedded processorsare used in home appliances.
Microcontrollers have many advantages as compared with the
microprocessors especially in the areas where high integration and
saving of space is required.
The main difference between microprocessor and microcontroller is
given below:
Microprocessor Microcontroller
1. Microprocessor is used in 1. Microcontroller is used in
computer system. It is the embedded systems.
heart of computer.
2. It consists of Memory and I/O 2. Microcontroller consists of
components which are inbuilt internal memory and
externally connected to it. I/O ports.
3. Since memory and I/O are 3 Since memory and 1/0 are
externally connected, the inbuilt, the circuit is small.
circuit becomes large.
4. Cost of the entire system is 4. Cost of the entire system is
more. less.
5. Total power consumption is 5. Total power consumption is
high as compared with less and can be used in
microcontrollers, so cannot be battery operated devices.
used in battery operated
devices.
6. Most of the micro processors 6. Most of the microcontrollers
do not have power saving have power saving modes
features. like idle mode and power
saving mode. This helps to
reduce power consumption
even further.
... (Contd.,;
S.Y.B.Sc. (Comp. Sci.) : Elect, - P-I - S-I1 1-3 Basics of Microcontroller ....

Microprocessor Microcontroller
7. Since memory and I/0 7. Since components are in
Components are externally built, most of the operations
Connected, each instruction are done by internal
will need external
operation, instructions, hence speed is
hence it is relatively slower. fast.
8. Microprocessors are based on 8. Microcontrollers are based
Von-Neur ann architecture on Harvard architecture
where program and data are
where program memory and
stored in same memory Data memory are separate.
module.
9. Mainly used in personal 9. Mainly used in washing
computers. machine, MP3 players, stand
alone systems.
More than ten times as many
are manufactured and sold in the microcontrollers than microprocessors
world inspite of the
recent time, eight bit microcontrollers have become high profile. In
the backbone
for the solution o* application of
intermediate
low power consumpticn and flexibility makecomplexity. Small size,
these devices ideal.
Being software driven, microcontrollers greatly
simplify the design of
sophisticated instrumentation and control circuitry.
Now-a-days everyone is familiar with a term embedded system like
cell phon es, remote controllers, washing
fax machines etc. The meaning of machines, microwave ovens,
which performs embedded system is the system
some specifictask.
In other words, an
embedded products uses microprocessor (or
microcontroller) do one and only one task. These systems are not
tc
generalized. They are assigned some specific sequence of
and requires sort of operations
operations.
automation to control the sequence of

The device which controls and


sequences the flow of operation in a
specified manner is referred as microcontroller.
assigned with some specific task which they Microcontrollers
in a perform
are
way. systematic
S.Y.B.Sc. (Comp. Sci.) :Elect. - P-I - S-I 1-4 Basics of Microcontroller ...

11nternal Block Dlagram of 8051


Microcontroller
Intel Corporation introduces an 8-bit microcontroller called 8051.
This microcontroller had 128 bytes of RAM, 4 k bytes of on-chip
ROM, two timers and four ports all on a single chip.
The 8051 is
an 8-bit processor that means CPU can work on
only 8 bits of
data at atime. It has four 8-bit ports.
ALU
AimelCouner. ParallelVO
Port
GzAcCumulator
Register(s) Serial I/O

Internal
Internal
ROM.
RAM Anterropt
circuits

Stack pointer Clock


circuit

Program counter
Fig. 1.1 :Ainternal block diagram of microcontroller
Fig. 1,1 shows the block diagram of typical microcontroller. It is the
on chip computer. It contains allblocks such as RAM, ROM, parallel
VO and serial /O ports on a single chip. Along with this, it also has
ALU, SP and other registers to perfcrm the features supported by
microprocessor.
Microcontroller can perform simple ar thmetic and logical operations.
The prime use of microcontroller is to control operations with proper
sequence.
This chapter provides a broad overview of the architecture of the
8051. The 8051 introduced by Intel Corporations is also referred as
MCS-51.
Salient Features of 8051 Microcontroller :
The salient features of 8051 microcontroller are :
1. It is an 8-bit microcontroller, designed using NMOS technology.
2. 8-bit data bus, 16-bit address bus.
S.Y.B.Se. (Comp. Scl.): Eloct. P-I - 5-11 1-5 Basics of Microcontroller .

3. 4 k bytes - on-chip ROM.


4. 128 bytes - on-chip RAM.
5. 32 general purpose registers, each of 8-bËt.
6. Operating frequency 12 MHz.
7. Multiply and divide instruction available.
8. It has a boolean processor and supports bitwise operations.
9. 16-bit address bus multiplexed with port 0 and port 2.Port 0 is
also 8-bit data bus.
10. Four I/O ports (8-bit).
"11. 16-bit 2 timers.
11. One serial port.
12. Five interrupt sources.
Table 1.1: MCS-51 family members
Device One Chip One Chip No. of No. of Serial
Data Program Timers Interrupts Port
Memory Memory
Bytes
8031 128 None 2 5 1

8032 256 None 3 6 1

8051 128 4 k bytes 2 5 1


ROM

8052 256 8 k bytes 3 6


ROM

8751 128 4 k bytes 2 5 1


EPROM
8752 256 8 k bytes 3 6 1
EPROM
The block diagram of the 8051 in Fig. 1.2 shows all of the features
which are unique to microcontrollers..
S.Y.B.Sc. (Comp. Sci.) : Elect. - P-I - S-III 1-6
Basics of
Atnaneic Microcontroller ....
and
1ogicAiit RSW tunotion
Kogistars
CRAM A0-A7
DO-D7
8-bit data and
address bus
-I/O

DPTR
KDEH
TITT
DP ROM

16-bit address bus A8-A15


Pon
EA-- Systern Interrupt
ALE tming Byte/bit Counter
PSEN addrasses
unctoh Serial data
TegisterS RD-WR
XTÂL1
XTAL2
Systefn
Irnterrupt
RESET Register
timers 3 P
PGON
VccData buffers
GNDMemory. contöt Register
bank21
SBUF
E0SCONS
TCON
BRegister
bank 1 TMOD

Begister
bank 0

(lnternal RAM structure)


Fig. 1.2:8051 block diagram
The basic architecture of 8051 microcontroller can be divided into
seven parts:
1 Processing unit
2. Register set
3. Memory units
4. /Oports and serial port
5. Timing and control unit
6. Interrupt structures
7. Timers

The programming model of 8051 is shown in Fig. 1.3. From the block
diagram and programming model registers, Special Function
Registers (SFR) and its memory location can be studied.
S.Y.B.Sc. (Comp. Sci.): Elect. - P-I- S-ilI 1-7 Basics of Microcontroller
8 B8 8A8
8898B8
TMODA TCON FFF
Register Registor Rogister Registe:
B Interrupt registers Timerlcounter registers
Ragiste Regster
Math registers 88 88A. 88D 8 B
ETHO TLOH1TL1
eounterConter counter Counter
Timer/counter registers
8 98
B849987e
SCON SBU PGON PSW.
Do
7F RegistarRegster Register Register
Serial data registers Flags
Gareral
area SP
30
2F
Regisler
Bit 7E
addrasS Stack pointer register
Bit Addresses for This RAM
20 arep Area Only
00
1FRegister
Sbank
183
17Register 883 B82 16 No AddresS
10
bankag Data pointer
OF
DPH DPE Program counter
Regieter Data and code addressing
08 bank
1 registers
07bARRT

Register 06ERAR6
05R6 880SA90%
Port 0
Porta aAD8BO
Port2
Bank Lafch atch Port3
0 04R4
03P3
Latoh Latch
02 R2:E
Number of
01R1Sk bits
Direct byte address
00ROR
Byte Internal 000
Addresses RAM Internal
ROM
Note: Indicates bit addressable
Fig. 1.3 :8051
1 2Registers
programming model
Fig. 1.3 shows the
programming model having collection of 8-bit and
16-bit registers. These
to cperate using the registers and memory locations can be made
part of the design. Thesoftware instructions that are incorporated as a
program instructions are related with the
1-8 Basics of Microcontroller ....
S.Y.B.SC. (Comp. Sci.) : Elect. - P-I - S-lI
control of registers and digital data paths that are physically
contained inside the 8051.
In CPU, registers are used to store information temporarily. That
information could be a byte of data to be processed, or ar address
pointing to the data to be fetched.
D, D6 Ds D D3 D, D1 Do
8-bit Register
The 8-bit register is shown from the MSB (Most Significant Bit) D, to
the LSB (Least Significant Bit) D, with an 8-bit data type. 8051
contains large number of registers. Some of the widely used registers
are Accumulator Aand Bregister, register Ro, R, Re Rg, Ra, Rs, Ro R,
as well as Data Pointer (DPTR), Stack Pointer (SP) and Program
Counter (PC). All the above registers are 8-bit except DPTR and PC.
There are two math registers name y Accumulator A and B. These
registers (A and 8) are mostly used in arithmetic and logical
operations as well as used in data transfer between 8051 and
external memory. B register is used with A for multiplication and
division operations. Some Special Function Registers (SFR) are also
there in 8051.
Each register with an exception of Program Counter (PC) has an
internal 1 byte address assigned to it. Some registers marked with *
(asterisk sign) are both bit and byte acdressable. i.e. the entire byte
of data at each register address may be read or altered, or individual
bits may be read or altered. Software instructions are generally able
to specify a register by its address, its symbolic name or both.
1.3 Flags and Program Status Word (PSW)
The 8051 has a flag registers to indicate arithmetic condition. These
are 1-bit registers provided to store the results of certain program
instructions. Other instructions can test the condition of flags and
make the decisions based on the flag status.
The flags may be conveniently addressed and they are grouped
inside the Program Status Word (PSW) and Power Control register
(PCON).
1.3.1 PSW (Program Status Word) Register
The Program Status Word (PSW) Register is an 8-bit register. It is
referred as flag register.
Basics of Microcontroller
s.Y.B.Sc. (Comp. Sci.): Elect. - P-1- S-II 1-9

are used by the


Although PSW is 8-bit wide registe, only 6-bits of it
flags.
8051. The two unused bits are user definable
flags, meaning that
Four of the flags are called conditional or math an instruction is
results after
they indicate some conditions that
executed.
Parity (P) and
These four flags are Carry (C), Auxiliary Carry (AC),
Overflow (OV).
CY AC FO RS1 RSO ov- P
Bit Symbol
PSW.7 CY Carry flag
PSW.6 AC Auxiliary carry flag
PSW.5 FO User flag 0
PSW.4 RS1 Register bank select bit 1
PSW.3 RSO Register bank select bit 0
PSW.2 OV Overflow flag
Reserved for future use
PSW.1
PSW.0 P Parity flag
carry out from D, bit. This
Carry flag (C): This flag is set if there is a subtraction. It can be set
affected after an 8-bit addition or
flag bit is
"SETB C" and "CLR C".
to 1 or 0 directly by an instruction
to D4 during an
Auxiliary carry flag (AC) : If there is a carry from isDacleared. This flag
otherwise it
ADD or SUB operation, this bit is set,
(Binary Codéd Decimal)
is used by instructions that perform BCD
arithmetic.
the number of ls in A
Parity flag (P): The parity flag reflects odd number of
(accumulator) register only. If register A contains an of ls.
even number
ls then P = 1. Therefore, P = 0 if A has an
a signed number
Overflow flag (0V): This flag is set if the result of overflow into the
bit to
operation is too large, causing the high order
detect errors in unsigned
sign bit. In general, the carry flag is used to
arithmetic operations.
Register BankSelect Bits (RSO and RS1) :
divided intodifferent
The 128 bytes on chip memory location are four register
sections, out of which 00H to 1FH is divided into
S.Y.B.Sc. (Comp. Scl.) : Elect. P-I - S-In
1-10 Basics of Microcontroller
banks. Bit PSW.4 and
PSW.3 are RS1 and RS0
selects the register bank.
RSO
RS1
respectively which
Registr Bank Address
1
1
00H 07H
1 08H OFH
1 2
3 10H17H
18H 1FH
14DAap
aointer and Program
The 8051
contains two 16-bit Cournter PG
registers,
Program Counter (PC). Each is used to
Data Pointer (DPTR) and
memory. hold the address of a byte in
DPTR is a 16-bit
register consisting of two 8-bit DPH
are used for and DPL,
code access orhandling memory addresses from internal and Which
external data access. external
It is possible to
use DPH (Data
Pointer Lower byte) Pointer Higher byte) or DPL (Data
instruction. separately or single 16-bit
DPTR in an
Program Counter (PC) is a
next instruction to be 16-bit register which always points to the
fetched from ROM. And it is
incremented
JMP and CALL
after each
instruction execution. PC gets affected by automatically
instruction.
PC register does not
have an internal address.
PC is 16-bit wide,
means it can fetch address
64 k byte of code. 0000H to FFFFH, total
1.5 The Stack and
Stack
Stack Pointer (SP)
referred to an internal RAM is used to store and
quickly. retrieve data
The 8-bit StackPointer (SP)
address which always pointsregister is used to hold an
to top of the stack that isinternal RAM
address of memory location at which it holds the
last byte in the stack is
When data is to be placed onto the stored.
stack, SP gets
one and then data is placed on the
stack. increnmented by
S.Y.BSc. (Comp. Sci.) : Elect. - P-[ - S-IM 1-11 Basics of Microcontroller ....

While the data is retrieved from the stack, the data is taken out first
and then stack pointer is decremented.
" Fig. 1.4 shows the stack operations.
CPU CPU
action action

SP0 Store data Address:OA|Get data SP0A

SP0g Store data Address 09l Get data SP 09

SP 08 Store data Address 08 Get data SP =08

SP07
PAddress
07 SPP07
Storlng data
on the stack Internal RAM
Getting data
(increment from the
then store) stack (get then
decrement)
Fig. 1.4: Stack operations
On reset, stack pointer contains the value 07H.
The stack size is limited to the size o
internal RAM. The stack is
overlapped on bank 1 because they have same starting address, even
though bank 1 can be used separately by
the SP has to be initialized programmer. In this case,
somewhere else by the programmer, so
that bank 1 and stack would rot be
overlapped.
1.6 Special
FunctionRegister (SFR)
These 128 bytes are reserved for SFRs. From
SFRS are addressed. Table 1.2 address 80H to FFH all
shows the list of SFRs which may be
addressed like internal RAM.
Some of the SFRs marked with asterisk ()
are bit addressable.
Not all
addresses from 80H to FFH are used for SFRs. Some of the addresses
are not defined. In the
instruction, user can either specify the SFR
name or the address of the SFR.
Microcontroller ..
1-12 Basics of
Elect. P-I -S-III
S.Y.B.Sc. (Comp. Sci.) :
opcodes by their functional names, such as
SFRS are named in certain opcode by thei address, such as
referen ced by other
A orTH0, are
OEOH or 8CH.
a
the program must start with
Note that, any address used in accumulator A begins with 0
number, thus address EOH for the SFR
assembler error.
i.e. OEOH, otherwise there will be
internal RAM address
Table 1.2 : SFR names and equivalent
Internal RAM Address
Name Function
(HEX)
Accumulator OEO
A
Arithmetic OFO
B
Addressing external memory 83
DPH
Addressing external memory 82
DPL
Interrupt enable control OA8
IE
OB8
IP Interrupt priority
Input/Output port latch 80
PO
P1 Input/Output port latch 90

P2 Input/Output port latch A0

P3 Input/Output port latch OBO

PCON Power control 87

PSW Program status word ODO

SCON Serial port control 98

SBUF Serial port data buffer 99

SP Stack pointer 81

TMOD Timer/counter mode control 89

TCON Timer/counter control 88

TLO Timer 0 low byte 8A


THO Timer 0 high byte 8C

TL1 Timer 1 low byte 8B

TH1 Timer 1 high byte 8D


tystal ocilatr Create o NM
ALE add=o PSEN pin
ontroller
HO ins.
The 8051 microcontroller has an important feature of in-built
Input/Output /O) ports. Through-these pörts,
directly interface with the outside world. microcontroller can
The 8051 incorporate many functions which are economically and
technically feasible.
The main constraint that limits numerous functions is the
pins available to the 8051 circuit designers. Po gves number of
wbin
Anly
und
Pin Diagram of 8051 and Its \aweE Tbit
Description :
P1.0
40 + 5V
P
Dort P1.1

P1.2
Je (ADO)PO.0
(AD1)PO.1
P1.3
(AD2)P0.2
P1.4
(AD3)PO.2
P1.5
(AD4)PO.4
P1.6
(AD5)PO.5
P1.7 8
(AD6)PO.6
Reset ’ RST (AD7)PO.7
Recevo P3.0(RXD) 10 (Vpp)/EAEaly
8051.

TronsmP3.1(TXD)
initupt P3.2(0NTO)
(PROG) ALEEble
Pr
29 PSEN -
inte oP3.3((NTT) 13 (A15)P2.7
Timer P3.4(TO)14 (A14)P2.6
Time P3.5(T1)15 (A13)P2.5
Fwrile/Read P3.6(WR) (A12)P2.4
RecddataP3.7(RD) (A11)P2.3
ECuSa ceil a XTAL2 (A10)P2.2
oeilosr XTAL1 9 (A9)P2.1

Ground (A8)P2.0
crak 12Mhrg Fig. 1.5 : Pin diagram of 8051
P2 Gives hisher bit
S.Y.B.Sc. (Comp. Sci.) : Elect. - P-I-
S-I 1-14
Fig. 1.5 shows pin Basics of Microcontroller
IC, 32diagram
It is a 40 pin of 8051.
each port takes 8 pins are set aside for the 4
pins. The rest of the ports (P0
XTAL2, RST, EA, PSEN and pins are Vcc P3), where
Out of these 8 ALE. GND, XTAL1,
pins, six of them
EA) are used by all (VCC, GND, XTAL1,
in ordermembers of 8051 and XTAL2, RST and
connected to
is from work the system,
8031 families. They must be
microcontroiier
The other two pins
8051 or 8031 family. regardless of
whether the
Below details of these PSEN and ALE are
six mainly used in 8031
Vcc Pin 40
: pins are given: systems.
source is +5 V.provides the supply voltage to the chip.
GND: Pin 20 is ground. The voltage
XTAL1 and XTAL2 : The 8051
external clock to run it. A has on-chip oscillator but
these pins (pin no. 19 crystal oscillator is requires an
and 18). connected
capacitor between
them, of value 30 It also needs the
as shown in Fig. pF. One side of capacitor is between
1.6. connected to ground
30 pF
XTAL1

30 pF XTAL2
Gnd

Fig. 1.6
Speed of 8051 refers to the
connected to XTAL1 and XTAL2. For maximum frequency of oscillator
of oscillator then speed at example, if 12 MHz is frequency
8051 is also 12 MHz.
RST : Pin 9 is the RESET pin. It is
pu'se to this pin, the active high input pin. Upon applying
activities. This is mìcrocontroller will reset and terminates all
also referred as
cause all values in registers to be power-on-reset.
lost.
Activating reset will
S-III 1-15 Basics of Microcontroller ....
S.Y.B.Sc. (Comp. Scl.):Elect. - P-I-
Table L.3: On RESET values of some registers
Value
Reglster
PC 0000.

ACC 0000
B 0000

PSW 0000
SP 0007
Value of PC is reset to 0000H fTrcing microcontroller to fetch the first
instruction rom ROM memory location 0000H. Therefore, we must
place the code at location 0000H.
Fig. 1.7 shows the reset circuit of 8051.

PVoc
10 uf
30 pF EAVPR
11.052 MHz
w
T830 pF
RST

Fig. 1.7: Reset circuit


EA: In 8051, it comes with on-chip ROM to
store programs. To
access on-chic ROM, EA is connected to Vcc. To access off-chip
ROM,
EA pin has to be connected to
ground to indicate that the code is
stored externally.
PSEN : This is an output pin which
stands for Program Store
Enable. In case of off-chip ROM, this pin is
of ROM to read the ROM
connected to the OE pin
ROM.
contents. It acts as RD in case of off-chip
S.Y.B.Sc. (Comp. Sci.) :Elect. - P-J- S-I 1-16 Basics of Mlcrocontroller ...

ALE : Address Latch Enable is an output pin and it is active high.


When 8051 is connected to external memory, port 0 provides both
address and data on multiplexed bus. In order to demultiplex it, ALE
signal is üsed.
1.8 Ports
In 8051, there are four 8-bit ports PO, P1, P2 and P3.
All the ports upon RESET are configured as inputs and are ready to
use as input ports. When the first O is written to a port, it
becomes an
output. To reconfigure as an inut port. logic '1 must be sert to the
port.
Each port has D type output latch for each pin. The SFR for each port
is made up of these eight latches wh'ch can be addressed at SFR
address for that port.
The ports are not capable of driving loads that require currents in the
tens of milliamperes (mA).
1.8.1 Port 0
Port 0 occupies a total of 8 pins (Pin 32 - Pin 39). It can be used for
input or output as shown in Fig. 1.8.
Port 0 ’ Address data lines
Enhancement
Control signals mode FET Vcc
Address!Dala AWO
1
Read latch bit 0scillator Depletion
0 periods mode FET

Internal bus Gont.ol Pin Internal FET Pull-up


Write to latch logic 0:X
Port SFR latch

Read pin data


Fig. 1.8 : Port Gpin configuration
Port 0 pins may serve as inputs, outputs or as a bidirectional low
order address and data bus for external memory when used
together.
For example, when a pin is to be used as an input, a logic '1' must be
written to the correspondinc port 0 latch by the program, thus
P-I- S-III 1-17 Basics of Microcontroller
S.Y.B.Sc. (Comp, Sci.) :Elect.
causes the
turning both of the output transistors OFF which in turn
essentially
pin to "loat" in a high-impedance state and the pin is
connected to the input buffer.
programmed to a 0
When used as an output, the pin latches that are that are
pin. All latches
will turn ON the lower FET, grounding the
resistors will bé
programmed to a 1 stillfloat thus, external pull-up
an output,
needed to supply logic high when port 0 is used as
memory, internal
When port 0 is used as an address bus to external
gates of the Field
control signals switch the address lines to the
bit will turn the
Effect Transistors (FETs). A logic '1 on an address
alogic high at the
upper FET ON and the lower FET OFF to provide
the upper
pin. When the address bit is zero, the lower FET is ON and
FET is OFF to provide a logic low at the pin.
circuits
After the address has been formed and latched into external
around to
by the Address Latch Enable (ALE). pulse, the bus is turned
become a data bus. Port 0 now reads data from the external memory
and must be configured as an input, so logic '1 is automatically
written by internal control logic to all port 0 latches.
Port 0 is different than other ports as it does not have the pull-up
registers, while all other ports have internal pull-up registers. In case
of port 0, external pull-up registers are provided as shown in the
Fig. 1.9.
oVcc
10 k

PO.0 Port 0
VPO.1
P0.2
8051 PO
PO4
PO5
Po.6
PO7
Fig. 1.9 : Port 0
This is due to the fact that PO is an open drain configuration. In order
to make it as input port, it must be programmed by writing 1 to all
the pins.
S.Y.B.SC. (Comp. Sci.) : Elect. P-I- S-IM 1-18Baslcs of
Dual role of port 0 : Mlcrocontroller .5
be used as Port Ois also
address bus or data bus.designed as ADo - AD¬,
O
provides both address and data. case of external allows it to
In
order address bus (Ao - A) 8051 has a memor, port
for demultiplexing it. and data bus (Do- DT).multiplexed
ALE lowered
1.8.2 Port 1 signal is used
Read latch bit
Vcc
Internal
FET
Internal bus Pull-up
Write to latch
Pin

Port SFR latch


Read pin data
Fig. 1.10: Port 1pin
Port 1 is a 8
pins port (Pin 0 - Pin 7). configuration
output. It has internal pull-up
It can be
used as input or
just write '1' to all resistors.
pins of port 1 as To configure it as input
functioning. shown in Fig. 1.10. It has no port
1.8.3 Port 2 dual
It is
again 8-bit port. It has an
input port, it must be internal pull-up registers. To
shown in Fig. programmed by writing 1 make it as
1.11. to all its bits as
Control signals
Address/Data
Read latch bit
Vcc
Internal
FET
Internal bus Pull-up
Write to latch
GontrO
oglc
Port SFR .atch

Read pin data


Fig. 1.11: Port 2 pin
configuration
SY.B.Se. (Comp. Sci) : Elect. - P-I-S-M 1-19 Basics of
Microcontroller ...
Dual role of port 2: Port 2 also acts as a higher order
address bus.
In case of accessing external memory (64 k bytes) it
provides the higher
o*der address (As - A1s).
1.8.4 Port 3
Port 3 is 8-bit pot. It can-be I/P or O/P port. By default it is
output
port. It has internal pull-up registers. O/P port is commonly used for
scme important signals. As this port is a dual functioning port, it is
normally used for the other purpose listed in Table 1.4. The Fig. 1.12
shows port 3 pin configuration.
Alterrate output
Read latch bit Vcc
Internal
FET
pull-up
Internal bus
Wr te to latch
3X
Port SFR latch

Read pln data


Altermate input
Fig. 1.12: Port 3 pin
configuration
Table 1.4
P3 bit P3-0 P3-1 P3-2 P3-3 P3.4 P3-5 P3-6 P3-7
Function
RxDTxDINT INT1 To TË WR RD
19 Internal.
Memor
A functioning combuter must have
memory for program code bytes,
commonly in ROM and RAM memory for variable data that can be
altered as the program run. he 8051 has internal RAM and ROM
memory for these functions.
1.9.1 lnternal RAM
The 128 byte intenal RAM. vhich is organized into
three distinct
areas is shown in Fig. 1.13.
S.Y.B.Sc. (Comp. Sci.) : Elect. -P-I - S-I 1-20 Basics of Microcor

Byte
Byte
Address
Address
7F
1F

3Bank 1E Ro
1D SR5
1C
1B
1A
19
18
17

2Bank 16R6:
15 R
14
13 R3
12 R{
11 R1 Byle Bit
10 RO Address Address
OF R7 2F ZR
Bank
1 OE R6 2E 7 7 7 0
OD R5 2D G8
0C R4 2C 6 60
OB R3 2B
OA R2 2A
50
09 29 4F 48
08 RO 28
27 40
07 RT 3E
0Bank 06 R6 26 37 30
05 RE 25 2F28.
04 24
03 23
18
02
10:
01 21 08
00 RO 20 07 00 30
7
Working Registers Bit Addressable
General Purpose
Fig. 1.13 : Internal RAM organization
Thirty-two bytes from address 00H to 1FH that make up 32
registers are organized as four banks of eight registers each. working
1-21 Basics of Microcontroller....
trollerT.Y.B.Sc. (Comp. Sci) : Elect. - P-I- S-II
0 to 3 and are made up
The four register banks are numbered from
of eight registers named RO to R7.
(when its bank is selected)
Each register can be addressed by narme is RO (if bank 3 is currently
of bank 3
or by its RAM address. Thus, RO 3 is selected or not).
selected) oraddress 18H (whether bank
determine which bank of registers is
Bits RSO and RS1 in the PSW
program is running.
currently in use at any time when the
used as general purpose RAM.
Register banks not selected can be
Bank 0 is selected on reset.
area of 16 bytes occupies RAM byte addresses 20H
A bit-addressable addressable bits.
to 2FH, forming a total of 128
addressable bit may be specified by its bit address of 00H to 7FH,
An from 20H to 2FH. Thus, for
may form a byte address
or 8-bits address 29H.
example, bit address 4FH is also bit 7 of byte
only to
Addressable bits are useful when the program need
remember a binary event (switch ON, light OFF etc.).
area, from 30H to 7FH is
A general purpose RAM and above bit
addressable as bytes.
1.9.2 Internal ROM

The 8051 is organized so that data memory and program co de


entities.
memory can be in two entirely different physical memory
Each has the same address ranges.
contained in an
A corresponding block of internal program code,
internal ROM, occupies code address space 0000H to OFFFH.
from
The PC is ordinarily used to address program code bytes
OFFFH, which
address 0000H to FFFFH. Program address higher than
8051 to
exceed the internal ROM capacity will cause the
automatically fetch code bytes from external program memory.
external memory,
Code bytes can also be fetched exclusively from an
address 0000H to FFFFH, by connecting the external access
pin (EA
pin 31) to ground.
1.10 EXternal Memory
There are several reasons for adding an external memory with 8051.
When the project- is in the prototype stage and internal ROM
memory is not enough, external memory is needed.
S.Y.B.S c. (Comp. Sci.) : Elect. - P-I- S-III
1-22 Basics of
External memory, which
needed when 128 bytes is
accessed by the
Mi
DPTR,
crocontroller ..

Eig. 1.14 of
internal data may also be
shows the
connections between storage is not sufficient
FA pin is 8051 and external
connected VCC to indicate that the
to memory.
stored in the on-chip ROM. If it is program code is
is connected to GND. in off-chip
As PC of 8051 is
(external ROM) then EA
16-bit, it is capable of
memory.
PO and P2
addressing 64 k bytes
external
provide the 16-bit address to
PO provides lower
8-bit access external memory.
address A8 - A15. address A0 - A7 and P2
provides higher 8-bit
PO is also used to
PO port is
provide the 8-bit data bus DO - D7.
multiplexed
to demultiplex the port and ALE signal of
As a result to
port when ALE = 1. It is used microcontroller
is used
for the address path.
extract the address from PO pins, PO
74LS373 latch and ALE to enable the latch.
is connected to
PSEN : Another iimportant signal for
enable) PSEN which is connected to 8051 is PSEN
(programme store
program code. It is important to the OE onpin of ROM containing
of 8051 emphasize role of PSEN and EA
when EA is connected to
from external ROM using PSEN GND, the 8051 fetches
signal. (Fig. 1.14 shows opcode
ROM with 8051.) interfacing 8 k
EA P3.7 (RD)
CP3a (WR)
PSEN
P2:7 A12
8051F2.0 2864
ALE A8 A8 (2764)
AD7
PO:7 A7 8kx8
P0:0 74LS373
ADO OGAO A0
D7DO
D7

DO
Fig. 1.14 : Interfacing of 8051 and external
memory
S.Y.B.Sc. (Comp. Sc.) :Elect. - P-I - S-II 1-23 Basics of Microcontroller ...

For 8 k bytes memory, 13 address lines are required, out of which


lower 8 lines are taken from PO by demultiplexing it and higher 5-bits
are taken from port 2.
PSEN is connected to OE and CE of memory to aelct it and as well to
read data frcm memory. Observe that EA is grounded, specifying it
as external memory.
1.10.1 8051 Data Memory Space
Program counter in 8051 is 16-bit and therefore it can access upto
64 k bytes of program code. But in some examples data is pla ced in
code space and used the instruction "MOVCA, @ A+PPTR" to get the
data.
In 8051 fami y, there is also separate data memory space.
While
program space is accessed by PC, the data space is accessed by the
DPTR register and instruction called MOVX is used for that. MOVXA,
@DPTR is widely used instruction to read external data
1.10.2 Interfacing External ROM to 8051
memory.
In Fig. 1.15, it is shown to interface 8 k
bytes external data memory
(ROM) with 8051.
RD
WR A15
PSEN
A12A13o
8051 P20 A12
ALE A8 8kx8.
P0. AD7
A7 Data
ROM
PO0 74LS373
ADO 0GA0 A0 b7 D0
D7

DO
Fig. 1.15: Interfacing with data ROM
In this case, RD is
connected to OE of memory chip. While chip select
(CE) is connected to simple address
decoding logic. PSEN is not used
as it is a data memory. Again
EA is GND to show that it is
memory. external
S.Y.B.Sc. (Comp. Scl.) : Elect. - P-[- S-II 1-24 Basics of Microcontroller ....
For 8 k bytes memory, 13 address lines are
lower 8 lines are taken from PO by required, out of which
are taken from port 2. demultiplexirg
it' and higher 5-bits
1.10.3 Interfacing External RAM to 8051
MOVX A, @ DPTR is the instruction used to
read external RAM, This
has many applications where
collecting large rumber of bytes data is
required.
" Fig. 1.16 shows the interfacing
external data RAM with 8051. Note
that RD and WR is connected to OE and WE of
RAM. While chip
select (CE) is connected to simple address decoding logic.
8051
P3.7 (RD)
P36 (WR) A15
PSEN
P2.7 A14
EA12A13 A13
P2.0
ALE A8 8k8
AD7 Data
PO:7 RAM
PO.0 74LS373
ADO OcAO A0 D7 DO
D7

DO

Fig. 1.16:Interfacingwith external data RAM


" Fig. 1.17 shows timing associated with an external memory access
cycle.
During any memory access cycle, port Ois time multiplexed. That is, it
first provides the lower byte of the 15-bit memory address and then
acts as a bidirectional data bus to write or read a byte of memory
data.
Port 2 provides the high byte of the memory address during the
entire memory read/write cycle.
The lower address byte from port 0 must be latched into an external
register to save the byte. Address byte save is accomplished by the
ALE clock pulse that provides the correct timing for 74373 to latch.
The port Opins then become free to serve as a data bus.
Basícs of Microcontroller
S.Y.B.Sc. (Comp. Sci.) : Elect. P-l - S-II
1-25

" If the memory acçess is for a byte of program code in the ROM. tha
PSEN (Program Store Enable) pin will go low to enable the ROM to
is for a
place a byte of program code on the data bus. If the access
RAM byte, the WR (write) or RD (read) pins will go' loW, enabling data
to flow between the RAM and data bus.

A0-A7 DO-D7
Port 0

Port 2 A8-A15

ALE Latch address


ALE pulse
External Memory Addressing
PSEN pulse
PSEN
Enable ROM

Reading ROM Using PSEN


Read pulse
RD
Enable read
Write pulse
WR
Enable write
Accessing RAM Using RD or WR

Fig. 1.17:External memory timing


111 OScillator and clock
The 8051 has on-chip oscillator but requires an external clock to run
it. It is a heart of the 8051 which generates the clock pulses by which
internal operations are synchronized. Most often a quartz crystal
oscillator is connected to inputs XTAL1 (pin 19) and XTAL2 (pin 18).
The quartz crystal os cillator connected to XTAL1 and XTAL2 also
need two capacitors of 30 pF value. One side of capacitor is
connected to ground as shown in Fig. 1.18.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy