8051 New PDF
8051 New PDF
8051 New PDF
A 8-BIT MICROCONTROLLER
D. Ganguly
Department of Electrical Engineering
Bengal Engineering & Science University, Shibpur
Microcontrollers: Embedded or
External Memory?
I / O ports
Control Input & Output pins
Clocking
Clock &
Timing
RAM
Processor Architecture
Code Memory
Code memory is the memory that holds the actual 8051 program
that is to be run. This memory is limited to 64K and comes in
many shapes and sizes: Code memory may be found on-chip,
either burned into the microcontroller as ROM or EPROM (one
of the distinguishing factors from version to version is how much
ROM/EPROM space the chip has) . Code may also be stored
completely off-chip in an external ROM or, more commonly, an
external EPROM. Flash RAM is also another popular method of
storing a program.
Types of Memory (Contd.)
External RAM
The 8051 also supports what is called External RAM. As the
name suggests, External RAM is any random access
memory which is found off-chip. Since the memory is off-chip
it is not as flexible in terms of accessing, and is also slower.
For example, to increment an Internal RAM location by 1
requires only 1 instruction and 1 instruction cycle. To
increment a 1-byte value stored in External RAM requires 4
instructions and 7 instruction cycles. In this case, external
memory is 7 times slower! What External RAM loses in
speed and flexibility it gains in quantity. While Internal RAM
is limited to 128 bytes (256 bytes with an 8052), the 8051
supports External RAM up to 64K.
Program Memory Map
FFFF H
EA’ = 0 External
PSEN’ = 0 Memory PSEN’ from 8051
1000H
0FFF H 0FFF H
Internal External Overlap from
4K on-chip
Memory Memory 0000 to 0FFF h
EPROM*
0000H 0000H
EA’ = 1 EA’ = 0
The 8051 uses 8 "R" registers (R0, R1, R2, R3, R4, R5, R6,
and R7) which are used in many of its instructions.
These registers are generally used to assist in manipulating
values and moving data from one memory location to another.
ADD A,R4 is the same as ADD A, 04h as long as the default
register bank R0 is chosen
Bit Memory
Accumulator
B register – used only in MUL AB and DIV AB
The "R" registers
The Data Pointer (DPTR) - only user-accessible 16-bit register.
When the 8051 accesses external memory it will access external
memory at the address indicated by DPTR
The Program Counter (PC) - 2-byte address which tells the 8051
where the next instruction to execute is to be found in memory
The Stack Pointer (SP) - When the 8051 is initialized SP will be
initialized to 07h. SP is modified by the instructions PUSH, POP,
ACALL, LCALL, RET, and RETI and also by interrupts.
Special Function Register (SFR) Memory
Other SFRs allow the user to set the serial baud rate, control and access
timers, and configure the 8051s interrupt system
All SFRs whose addresses are divisible by 8 can be accessed with bit
operations
SFRs (Contd.)
SCON (Serial Control, address 98h, bit-addressable) used to configure the behaviour of
the 8051's on-board serial port
SBUF (Serial Buffer, address 99h) used to send and receive data via the on-board serial
port
IE (Interrupt Enable, address A8h,bit-addressable) used to enable and disable specific
interrupts
IP (Interrupt Priority, address B8h, bit-addressable) used to specify the relative priority of
each interrupt
PSW (Program Status Word, address D0h, bit-addressable) contains the carry flag, the
auxiliary carry flag, the overflow flag, the parity flag and the register bank select flags
ACC (Accumulator, address E0h, bit-addressable)
B (B Register, address F0h, bit-addressable)
A common practice when semiconductor firms wish to develop a new 8051 derivative is
to add additional SFRs to support new functions that exist in the new chip.
SFRs (Contd.)
SFRs (Contd.)
The 8051 uses ports P0 and P2 to address the external memory. Thus when
using external RAM or code memory only ports P1 and P3 may be made use of
SP (address 81h) should be initialized to 2Fh as the first instruction of every
program unless the register banks and bit variables are not going to be used
PCON (Power Control, address 87h) is used to control the 8051's power
control modes
TCON (Timer Control, address 88h, bit-addressable) used to configure and
modify the way in which the 8051's two timers operate
TMOD (Timer Mode, Addresses 89h) used to configure the mode of
operation of each of the two timers
TL0/TH0 (Timer 0 Low/High, Addresses 8Ah/8Ch)
TL1/TH1 (Timer 1 Low/High, Addresses 8Bh/8Dh)
Addressing Modes
6 C/T1 When this bit is set the timer will count events on T1 1
(P3.5). When this bit is clear the timer will be
incremented every machine cycle.
3 GATE0 When this bit is set the timer will only run when 0
INT0 (P3.2) is high. When this bit is clear the timer
will run regardless of the state of INT0.
2 C/T0 When this bit is set the timer will count events on T0 0
(P3.4). When this bit is clear the timer will be
incremented every machine cycle.
13-bit Time Mode (mode 0) - bits 0-4 of TLx and bits 0-7 of THx
16-bit Time Mode (mode 1)
8-bit Auto Reload Time Mode (mode 2) - THx holds the "reload
value" and TLx is the timer itself . Very commonly used for
establishing a baud rate
Split Timer Mode (mode 3) - When Timer 0 is placed in mode 3,
it essentially becomes two separate 8-bit timers (TL0 and TH0 act
as Timer 0 and Timer 1). All the bits that are related to Timer 1 will
now be tied to TH0. While Timer 0 is in split mode, the real Timer 1
(i.e. TH1 and TL1) can be put into modes 0, 1 or 2 normally
TCON (Bit-addressable)
SCON
Bit Name Bit Explanation of function SM0 SM1 Serial Explanation Baud
Address mode Rate
7 SM0 9Fh Serial port mode bit 0 0 0 0 8-bit Shift Oscilla
Register tor / 12
6 SM1 9Eh Serial port mode bit 1.
0 1 1 8-bit UART Set by
5 SM2 9Dh Mutliprocessor Communications Timer
Enable (explained later) 1 (*)
4 REN 9Ch Receiver Enable. This bit must be
1 0 2 9-bit UART Oscilla
set in order to receive characters.
tor / 32
3 TB8 9Bh Transmit bit 8. The 9th bit to (*)
transmit in mode 2 and 3.
1 1 3 9-bit UART Set by
2 RB8 9Ah Receive bit 8. The 9th bit received
in mode 2 and 3. Timer
1 (*)
1 TI 99h Transmit Flag. Set when a byte
has been completely transmitted.
Receive Flag. Set when a byte has
* : The baud rate indicated in this
0 RI 98h table is doubled if PCON.7 (SMOD) is
been completely received.
set
Serial Communication (Contd.)
The first line of the above code segment waits for the 8051 to set
the RI flag; again, the 8051 sets the RI flag automatically when it
receives a character via the serial port.
Interrupts
6 - AEh Undefined
Interrupt Flag Interrupt Handler
Address Undefined
5 - ADh
External 0 IE0 0003h
4 ES ACh Enable Serial Interrupt
Polling Sequence
External 0 Interrupt
Timer 0 Interrupt
External 1 Interrupt
Timer 1 Interrupt
Serial Intrrupt
Interrupts(Contd.)