Академический Документы
Профессиональный Документы
Культура Документы
(8051)
Microprocessors:
General-purpose microprocessor
CPU for Computers
No RAM, ROM, I/O on CPU chip itself
Example Intels x86, Motorolas 680x0
CPU
GeneralPurpose
Microprocessor
Data Bus
RAM
ROM
I/O
Port
Address Bus
General-Purpose Microprocessor System
Timer
Serial
COM
Port
Microcontroller :
A smaller computer
On-chip RAM, ROM, I/O ports...
Example Motorolas 6811, Intels 8051, Zilogs Z8 and PIC 16X
CPU
I/O
Port
RAM ROM
Serial
Timer COM
Port
A single chip
Microcontroller
Microcontroller
CPU, RAM, ROM, I/O and
timer are all on a single chip
fix amount of on-chip ROM,
RAM, I/O ports
for applications in which cost,
power and space are critical
single-purpose
Advantages over
Microprocessor
Cost is lower
Standalone microprocessor never used
Advantages of
Microcontroller
Low cost
Small size of product
Easy to troubleshoot and maintain
More reliable
Additional memory, I/O can also be added
Software security feature
All features available with 40 pins.
Useful for small dedicated applications and not
Block Diagram
External interrupts
Interrupt
Control
On-chip
ROM for
program
code
Timer/Counter
On-chip
RAM
Timer 1
Timer 0
CPU
OSC
Bus
Control
4 I/O Ports
P0 P1 P2 P3
Address/Data
Serial
Port
TxD RxD
Counter
Inputs
Accumulator (ACC):-
DPTR:- 16- bit register contains a higher byte (DPH) and lower byte (DPL) of
Timer Registers:-
Control Registers:-
IP, IE, TMOD, TCON, SCON and PCON contain control and
status information for interrupts, timers/counters and serial
port.
SFR registers.
Instruction Register:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
8051
(8031)
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
Vcc
P0.0(AD0)
P0.1(AD1)
P0.2(AD2)
P0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14)
P2.5(A13)
P2.4(A12)
P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)
Signal Description of 8051:RESET:- resets the 8051, only when it goes high for
EA*/Vpp
program memory.
PSEN* :- Program store enable is an active-low output signal that acts as a
strobe to read the external program memory. Goes low during external
program memory accesses.
Port 0(P0.0- P0.7) :-
During external memory accesses, port 2 emits higher eight bits of address
(A8-A15) which are valid, if ALE goes high and EA is low.
Port 3(P3.0- P3.7) :- acts as 8-bit bidirectional bit addressable I/O port.
Also serve the alternate functions
Signal Description of 8051:XTAL1 and XTAL2: Inbuilt oscillator which derives the necessary clock
frequency for the operation of the controller.
XTAL1 is the input of the amplifier and XTAL2 is the output
of the amplifier.
Crystal is connected externally between these two pins to
complete the feed back path to start oscillations. The
controller can be operated on an external clock.
SP, DPH,DPL,TMOD,TH0,TL0,TH1,TL1,SBUF,PCON
Byte addressable, 8bit each.
DPTR data pointer, accesses external. memory. DPH + DPL
= DPTR
Starting 32 bytes of RAM general purpose register,
Registers
A
B
R0
DPTR
DPH
DPL
R1
R2
PC
PC
R3
R4
R5
R6
R7
PSW (8)
Some 8-bit Registers of the 8051
SP (8)
8051 features
Internal ROM 4K, RAM 128bytes
Thirty two I/O pins arranged as 4 8 bit ports P 0 P3
Two 16 bit timer/counters T0 and T1
using SBUF
Control registers TCON, TMOD, SCON, PCON, IP
and IE
Two external and three Internal Interrupt sources
Oscillator and clock circuits
are gated to the counter by the run bit and the gate bit or
the external input bits INTX*.
register.
TMOD
counter.
Pulse input is divided by 32d in TL so that TH
counts the original oscillator frequency reduced
by a total 384d.
Timer flag is set whenever THx goes from FF H
to 00 H, or in 0.0164 seconds for a 6 MHz crystal
if THx starts at 00H.
8-bit counter.
Mode bits are set to 0 1 in TMOD.
Timer flag would be set in 1311 seconds using a
6 MHz crystal.
in TMOD configures
the timer to use only the TLx counter as an 8-bit
counter.
THx is used to hold a value that is loaded into
TLx every time TLx overflows from FF H to 00 H.
Timer flag is also set when TLx overflows.
Exhibits an auto-reload feature: TLx will count up
from the number in THx, overflow, and be
initialized again with the contents of THx.
Counting: Difference between counting and timing is the source of the clock
Memory Addressing
Total memory logically divided into program
FFFFH
Internal external memories are distinguished by
PSEN* signal.
In ROM-less version of 8051 PSEN* used to
access external memory
memory access.
Internal data memory two parts - 128 bytes
Internal RAM and secondly set of addresses from
80-FF H for SFRs
128 bytes from 00 7FH are addressed using
direct or indirect
SFR addresses
(80 FF H) only direct
addressing mode
Memory Addressing
Lower 128 bytes in three sections
00-1F
Interrupts of 8051
Provides five sources of Interrupts.
INT0 * and INT1* are two external interrupt
inputs
These are processed internally by IE0 and IE1 flags
Serial Data Input/Output: Cost effective way to communicate is to send and receive
Serial Data Interrupts: Slow process, occupying many milliseconds per data byte
to accomplish.
Serial data flags are available in SCON to aid in efficient
data transmission and reception.
Transmission is under the control of program, but the
reception is unpredictable.
TI and RI are set in SCON whenever a byte is transmitted
is or received.
The program must read these flags to determine which
caused the interrupt and then clear the flag.
written to SBUF.
TI is set to a 1 when the data has been transmitted and
signifies that SBUF is empty.
If the program fails to wait for the TI flag and overwrites
SBUF while a previous data byte is in the process of being
transmitted, the results will be unpredictable.
of
SCON.
Baud rates are fixed for mode 0 and variable using timer1
and the SMOD bit in SCON for modes 1,2 and 3.
RXD.
TXD is connected to the internal shift frequency pulse to
supply shift pulses to external circuits.
Baud rate is fixed at 1/12 of the oscillator frequency, the
same rate is used by the timers when in the timer
configuration.
TXD shift clock is a square wave that is low for machine
cycle states s3-s4-s5 and high for s6-s1-s2.
When transmitting, data is shifted out of RXD, the data
changes on the falling edge of s6p2, or one clock pulse
after the rising edge of the output TXD shift clock.
written to SBUF.
TI is set to a 1 when the data has been transmitted and
signifies that SBUF is empty.
If the program fails to wait for the TI flag and overwrites
SBUF while a previous data byte is in the process of being
transmitted, the results will be unpredictable.
Data Reception: Will begin if the receive enable bit (REN) in SCON is set to 1 for
all modes.
In addition, for mode 0 only, RI must be cleared to 0.
Receiver Interrupt flag RI is set after data has been received in
all modes. Setting REN is the only direct program control that
limits the reception of unexpected data; the requirement that
RI also be 0 for mode 0 prevents the reception of new data
until the program has dealt with the old data and reset RI.
Reception can begin in modes 1,2 and 3 if RI is set when the
serial stream of bits begins. RI must have been reset by the
program before the last bit is received or the incoming data will
be lost. Incoming data is not transferred to SBUF until the last
data bit has been received so that the previous transmission
can be read from SBUF while the new data is being received.
TMOD Register:
Gate :
is high.
TCON Register:
Memory addressing
Memory Addressing
Lower 128 bytes in three sections
00-1F 32 bytes 4 banks 00,01,10,11 each
Interrupts of 8051
5 sources of Interrupts
INT0 and INT1 bars external interrupt inputs
These are processed internally by IE0 and IE1 flags
Two timers which generate int when FFFFH
Serial port interrupt if R1 or T1 is set.
EA
---
: Global enable/disable.
: Undefined.
Addressing modes
Direct - MOV R0, 89 H, Eg 89 of TMOD
operands 8 bit address field
Internal data RAM and SFRS only
Indirect - ADD A, @ R0
Address is stored in R0 or R1 or SP if 8bits
16 bit addresses only in DPTR
Addressing Modes
Indexed Addressing
MOVC A, @A+DPTR
JMP @ A + DPTR
Used to access only program memory not data
Used for look up table manipulations
Only PC or data pointer 16 bit storage registers
allowed
Base address in PC or DPTR, relative addr in A