8051
8051
8051
Microprocessor Microcontroller
CPU is stand-alone, • CPU, RAM, ROM, I/O
RAM, ROM, I/O, timer and timer are all on a
are separate
single chip
designer can decide on
the amount of ROM, • fix amount of on-chip
RAM and I/O ports. ROM, RAM, I/O ports
versatility • for applications in which
general-purpose cost, power and space
are critical
• single-purpose
History
Intel
1969: Intel was a tiny start-up company in Santa Clara, headed by
Noyce and Moore.
The Busicom
calculator used five
Intel 4001’s, two
4002’s, three
4003’s and the
4004 CPU The original engineering prototype
of the Busicom desk-top printing
calculator, the world’s first
commercial product to use a
microprocessor.
Early Microcontrollers
processor
Micro-processor into Micro-controller
Connecting a processor to 32kb ram & 32kb rom & serial space
processor
Address Range
1 111 1111 1111 1111
FFFF
32KB
8000
1 000 0000 0000 0000
0 111 1111 1111 1111
7FFF
32KB
32kb
16kb
16kb
Microcontroller
8051 PIN DIAGRAM
8051
Schematic
Pin out
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 36 P) 0.3(AD3)
8051 P1.5 6 35 P0.4(AD4)
Foot Print
P1.6 7 34 P0.5(AD5)
P1.7 8 33 P0.6(AD6)
RST 9
8051 32 P0.7(AD7)
(RXD)P3.0 10 (8031) 31 EA/VPP
(TXD)P3.1 11 30 ALE/PROG
(INT0)P3.2 12
(8751) 29 PSEN
(INT1)P3.3 13 (8951) 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)
IMPORTANT PINS (I/O Ports)
One of the most useful features of the 8051 is that it contains four I/O ports (P0 - P3)
Each port can be used as input or output (bi-direction)
Port 0
pins 32-39 (P0.0-P0.7)
8-bit R/W - General Purpose
I/O
Or acts as a multiplexed low
byte address and data bus
for external memory design
Port 0 with Pull-Up Resistors
Vcc
10 K
P0.0
DS5000 P0.1
Port 0
P0.2
8751 P0.3
8951 P0.4
P0.5
P0.6
P0.7
IMPORTANT PINS (I/O Ports)
Port 1
pins 1-8 (P1.0-P1.7)
Only 8-bit R/W -
Port 2
pins 21-28 (P2.0-
P2.7)
8-bit R/W -
General Purpose
I/O
Or high byte of
the address bus
for external
memory design
IMPORTANT PINS (IO Ports)
Port 3
pins 10-17 (P3.0-P3.7)
General Purpose I/O
if not using any of the
internal peripherals
(timers) or external
interrupts.
Port 3 Alternate Functions
IMPORTANT PINS
ALE (out): Address Latch Enable, to latch address outputs at Port0 and Port2
It is an output pin and is active high.
8051 port 0 provides both address and data.
The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the
74LS373 latch.
Pins of 8051
C1
XTAL1
30pF
GND
XTAL Connection to an External Clock Source
N XTAL2
C
EXTERNAL
OSCILLATOR XTAL1
SIGNAL
GND
Pins of 8051
2FH
Bit-Addressable RAM
The stack pointer in
the 8051 is only 8 bits 20H
1FH
wide, which means 18H
Register Bank 3
8051 External
Compact RAM
Micro
Internal
RAM
SFRs
Internal External
Code Code
(Optional)
Types of Memory
On-Chip Memory refers to any memory (Code, RAM,
or other) that physically exists on the microcontroller
itself. On-chip memory can be of several types, but
we'll get into that shortly.
Example :
Num EQU 30
…
MOV R0,Num
MOV DPTR,#data1
…
ORG 100H
data1: db “IRAN”
Register Addressing Mode
MOVRn, A ;n=0,..,7
ADD A, Rn
MOVDPL, R6
MOVDPTR, A
MOVRm, Rn
Direct Addressing Mode
Although the entire of 128 bytes of RAM can be accessed using
direct addressing mode, it is most often used to access RAM loc.
30 – 7FH.
In other word, the content of register R0 or R1 is sources or target in MOV, ADD and SUBB
insructions.
Example:
Write a program to copy a block of 10 bytes from RAM location sterting at 37h to RAM location
starting at 59h.
Solution:
MOV R0,37h ; source pointer
MOV R1,59h ; dest pointer
MOV R2,10 ; counter
L1: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,L1
Indexed Addressing Mode And On-Chip
ROM Access
This mode is widely used in accessing data
elements of look-up table entries located in the
program (code) space ROM at the 8051
MOVC A,@A+DPTR
A= content of address A +DPTR from ROM
Note:
Because the data elements are stored in the
program (code ) space ROM of the 8051, it uses
the instruction MOVC instead of MOV. The “C”
means code.
Timers
Timer
A timer is a specialized type of clock. A timer can be used
to control the sequence of an event or process.
The 8051 comes equipped with two timers.
The 8051 timers have three general functions:
1) Keeping time and/or calculating the amount of time
between events,
2) Counting the events themselves, or
3) Generating baud rates for the serial port.
SFRs relating to timers
TMOD Register:
Synchronization problem at: bit, word, frame level
Signal transitions occur according to a transmitter
clock
Two modes of operation:
asynchronous
synchronous
Serial Communications
Transmission modes
are synchronized
Serial Communications
Asynchronous transmission
Data word (octet) is encapsulated between:
start bit
stop bits(s)
Receiver resynchronizes again at a start of each new
word (or character) received
Serial Communications
Asynchronous transmission
Transmission parameters:
transmission rate (9600bps, 19200bps,
etc.) defines bit length in time
number of stop bits (1, 1.5, 2)
word length (usually 8 bits)
Serial Communications
Asynchronous transmission
Error control: parity
In an N bit word: count number of 1s on the first
N-1 positions
Insert 1 or 0 in the Nth position to get:
even (even parity - E)
Sbps xAz
where:
S is a connection speed (19200, 38400bps,….)
bps: bits per second
x is a number of bits in a word (usually 8)
A is parity (usually none: N)
z is a number of stopbits
38400bps 8N1 is a good bet ;-)
Serial Communications
Synchronous transmission
Transmitter and receiver clocks synchronized
DTE accepts a clock signal generated by DCE
Clock signal transmitted either:
over a separate line ( RS232 lines)
or encoded into the data (Manchester,
differential Manchester encoding) to allow a
single line for both data and clock
No start, stop bits, but still frame synchronization
words are needed
Serial Communications
Comparison of transmission modes
Asynchronous:
suitable for data transmitted at random intervals (e.g.
keyboard to computer)
large overhead (20% or more)
rather low data rates (up to 115.2 kbps, practically 38.4 kbps)
simplicity and availability: UART and RS232 are present in any
PC
used in the great majority of dial-up connections
Synchronous:
low overhead (long frames)
high rates
less prone to errors
Start and stop bits
Data communication classification
SFRs relating to timers
SBUF : Serial Buffer Register
Data moved to SBUF is Transmitted serially
SCON
Mode Selection
Setting the Baud rate
PCON Register:
SMOD -- -- -- GF1 GF0 PD IDL
If SMOD (PCON.7) is set then the same values for TH1 will give
– 19200 etc