Beruflich Dokumente
Kultur Dokumente
Microprocessors
General-purpose microprocessor
CPU
GeneralPurpose
Microprocessor
Data Bus
RAM
ROM
Address Bus
I/O
Port
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
Used in mobile phones, digital
cameras, microwave oven,
washing machines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
8051
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)
8051
Schematic
Pin out
8051 Architecture
IMPORTANT PINS
I/O Ports
One of the most useful features of the 8051 is that it contains four
I/O ports (P0 - P3)
Pins of 8051
Vcc pin 40
Vcc provides supply voltage to the chip.
The voltage source is +5V.
GND pin 20 ground
XTAL1 and XTAL2 pins 19,18
These 2 pins provide clock pulses by which all internal
operations can be synchronized.
Quartz crystal oscillator is used
Typical range from 1MHz to 16 MHz.
Pins of 8051
RST pin 9 reset
Upon applying a high pulse to RST, the microcontroller will
reset and all values in registers will be lost.
Register bank 0 is selected and all bits in PSW are 0
Reset Value
PC
0000
ACC
0000
0000
PSW
0000
SP
0007
DPTR
0000
Pins of 8051
EA pin 31 external access
-- The EA (External Access) pin is used to control the
internal or external memory access.
The signal 0 is for external memory access and signal 1
for internal memory access
PSEN pin 29 program store enable
If the memory access is for a byte of program code in
the external ROM, the pin will go low to enable the ROM
to place a byte of program code on the data bus.
Pins of 8051
ALE pin 30 address latch enable
It is an output pin and is active high.
Activates the port 0 joined with port 2 to provide 16 bit external
address bus to access the external memory.
The ALE multiplexes the P0.
1 for latching address on P0 as A0-A7 in the 16 bit address bus, 0 for
latching P0 as data I/O.
On-Chip Memory
Internal RAM
TCON
TMOD
Both counters use the TMOD (Timer Mode) register for
configuration.
Example:
MOV
MOV
MOV
PUSH
PUSH
PUSH
R6,#25H
R1,#12H
R4,#0F3H
R6
R1
R4
0BH
0BH
0BH
0BH
0AH
0AH
0AH
0AH
F3
09H
09H
09H
12
09H
12
08H
08H
08H
25
08H
25
SP=07H
25
SP=08H
SP=09H
SP=0AH
Example:
MOV
MOV
MOV
PUSH
PUSH
PUSH
POP
POP
POP
0BH
R6,#25H
R1,#12H
R4,#0F3H
R6
R1
R4
R4
R1
R6
0BH
0BH
0BH
0AH
0AH
0AH
09H
0AH
F3
09H
12
09H
12
09H
08H
25
08H
25
08H
SP=0AH
SP=09H
25
SP=08H
08H
SP=07H
Interrupt
Whenever any device needs its service, the device
notifies the microcontroller by sending it an interrupt
signal.
Upon receiving an interrupt signal, the
microcontroller interrupts whatever it is doing and
serves the device.
The program which is associated with the interrupt is
called the interrupt service routine (ISR) or interrupt
handler.
Interrupts
Interrupt
Program
time t
Interrupts
Interrupt
Program
Program
Interrupt Service Routine
time t
Interrupts
Interrupt
Program
Save
Context
Program
Interrupt
Service
Routine
Restore
Context
time t
34
The 8051
Programming
INTRODUCTION
An instruction is an order or command given
to a processor by a computer program. All
commands are known as instruction set and set
of instructions is known as program.
8051 have in total 111 instructions, i.e. 111
different words available for program writing.
Instruction Format
Where first part describes WHAT should be
done (Opcode), while other explains HOW to
do it(operand).
Ex: MOV
R6, #25H
Opcode Operands
The latter part can be a data (binary number)
or the address at which the data is stored.
Addressing Modes
Addressing modes specifies where the data
(operand) is. They specify the source or
destination of data (operand) in several
different ways, depending upon the situation.
Addressing modes are used to know where the
operand located is.
Addressing Modes
There are 4 types of addressing modes:
1.
2.
3.
4.
Immediate addressing.
Register addressing.
Direct addressing.
Register indirect addressing.
dest source
Exchange instructions
XCH a, byte
XCHD a, byte
Arithmetic Instructions
Add
Subtract
Increment
Decrement
Multiply
Divide
Arithmetic Instructions
Mnemonic
Description
ADD A, byte
ADDC A, byte
SUBB A, byte
INC A
increment A
INC byte
INC DPTR
DEC A
decrement accumulator
DEC byte
decrement byte
MUL AB
DIV AB
DA A
ADD
Subtract
Multiply
Division
Logic Instructions
ANL AND
ORL OR
XRL XOR
CPL Complement
CLR - clear
RL rotate left
RLC rotate left through Carry
RR rotate right
RRC rotate right through Carry
SWAP swap accumulator nibbles
Example
8 bit addition
Start
Initialize DPTR
Bring data to registers
A&B
Add data
Transfer result to external
memory location
Stop
Addition program
ORG 8400H
MOV DPTR, #8500H
MOV A, #14H
ADD A, #23H
MOVX @DPTR, A
END
8 bit substraction
Start
Initialize DPTR
Bring data to registers
A&B
Subtract data
Transfer result to external
memory location
Stop
Subtraction program
ORG 8400H
MOV DPTR #8500H
MOV A, #23H
SUBB A, #14H
MOVX @DPTR, A
END
8 bit Multiplication
Start
Initialize DPTR
Initialize accumulator with data1 & B
register with data 2
Multiply the data
Transfer result to external
memory location
Stop
Multiplication program
ORG 8400 H
MOV DPTR,#8800H
MOV 0F0H, #02H
MOV A, #05H
MUL AB
MOVX @DPTR, A
INC DPTR
MOV R0,0F0H
MOV A, R0
MOVX @DPTR, A
END
8 bit Division
Start
Initialize DPTR
Initialize accumulator with dividend & B
register with divisor
Divide the data
Transfer result to external
memory location
Stop
Division program
ORG 8400H
MOV DPTR,#8800H
MOV A,#64H
MOV OFOH,#05
DIV AB
MOVX @DPTR,A
INC DPTR
MOV R0,0F0H
MOV A,R0
MOVX @DPTR,A
END
Applications of 8051
8051
CS:Active low input (P3.2-INT0 pin) used to activate the ADC chip.
WR(startconversion):Active low input used to inform the ADC to
start the conversion process. If CS = 0 when WR makes a low-to-high
transition(P3.3-INT1 pin), the ADC starts converting the analog input
value of Vin to an 8-bit digital number.
RD(dataenable):Active low input used to get converted data out of the
ADC chip. When CS = 0, if a high-to-low pulse is applied to the RD pin
(from T0 pin of port 3), the 8-bit digital output shows up at the D0-D7 data
pins.
.
CS:Active low input (P3.2-INT0 pin) used to activate the DAC chip.
WR:Active low input used to inform the DAC to get data from data pins and
start the conversion process. If CS = 0 when WR makes a low-to-high
transition(P3.3-INT1 pin), the DAC starts converting the digital input to an analog
voltage.
Relay
Heater
Relay
Fan
8051
Preset temperature=23
T>23
T<23