Professional Documents
Culture Documents
Introduction
Block Diagram and Pin Description of the 8051
Registers
Memory mapping in 8051
Stack in the 8051
I/O Port Programming
Timer
Introduction :
Three criteria in Choosing a Microcontroller:
1. meeting the computing needs of the task efficiently and cost
effectively
speed, the amount of ROM and RAM, the number of I/O
ports and timers, size, packaging, power consumption
easy to upgrade
cost per unit
2. availability of software development tools
assemblers, debuggers, C compilers, emulator, simulator,
technical support
3. wide availability and reliable sources of the microcontrollers .
Embedded System :
Development process
Planning of tasks & interactions
Revise !
edit
Debugging ???
taskcode1.A51
Assembler
misc.LIB
taskcode2.c
C-compiler
Linker/Locator
Embedded Systems
Download to board
Burn in EPROM
Fall 2004
Block Diagram
External interrupts
Interrupt
Control
On-chip
ROM for
program
code
Delay
Generation
Labs
Timer/Counter
On-chip
RAM
Timer 1
Timer 0
Counter
Inputs
CPU
OSC
Bus
Control
4 I/O Ports
P0 P1 P2 P3
Stepper
motor
etc. Lab
Address/Data
Serial
Port
TxD RxD
PC Interface
Lab.
10
Internal
Data
Bus
ROM
Like
Brain
Oscillator
Like
Heart
Prepares
the
sequence
of
operation
s
Data flow
Like
BloodFlow
Ports like
Hands/Legs
11
12
13
14
Internal
Data
Bus
ROM
Like
Brain
Oscillator
Like
Heart
Prepares
the
sequence
of
operation
s
Data flow
Like
BloodFlow
Ports like
Hands/Legs
15
Signal
Pins
Figure
8051
pinouts &
Functions
Fetch Cycle
18
19
21
Pin 18
C2
XTAL2
30pF
C1
Pin 19
XTAL1
30pF
GND
Pin 20
22
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
RST pin 9 reset
It is an input pin and is active high normally low .
The high pulse must be high at least 2 machine cycles.
It is a power-on reset.
Upon applying a high pulse to RST, the microcontroller will
reset and all values in registers will be lost.
23
Pins of 8051
Pins of 8051
ALE pin 30 address latch enable
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.
I/O port pins
The four ports P0, P1, P2, and P3.
Each port uses 8 pins.
All I/O pins are bi-directional.
25
+
10 uF
31
30 pF
8.2 K
30 pF
11.0592 MHz
19
18
EA/VPP
X1
X2
9 RST
27
P89V51 RD2 :
Electrical Specs.( Threshold
Voltages)
29
30
31
A Pin of Port 1
Read latch
TB2
Vcc
Load(L1)
Internal CPU
bus
Write to latch
Clk
P1.X
pin
P1.X
Q
M1
TB1
P0.x
Read pin
8051 IC
32
Vcc
TB2
Vcc
Write to latch
Clk
P1.X
pin
P1.X
Q
M1
output 1
TB1
Read pin
8051 IC
33
Vcc
TB2
ground
Write to latch
Clk
P1.X
pin
P1.X
Q
M1
output 0
TB1
Read pin
8051 IC
34
TB2
2. MOV A,P1
Vcc
external pin=High
Load(L1)
P1.X pin
P1.X
Write to latch
Clk
M1
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
8051 IC
35
Vcc
2. MOV A,P1
TB2
Load(L1)
external pin=Low
MOV P1,#0FFH
Internal CPU bus
P1.X pin
P1.X
Write to latch
Clk
M1
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
8051 IC
36
37
Is it too much?
- its the beginning LOADING
EFFECT
( SOURCE
IS IN
PROBLEM
LOAD
38
A Pin of Port 0
Read latch
TB2
Internal CPU
bus
Write to latch
Clk
P0.X
pin
P1.X
Q
M1
TB1
P1.x
Read pin
8051 IC
39
Port 0
P0.0
DS5000 P0.1
P0.2
8751
P0.3
P0.4
8951
P0.5
P0.6
P0.7
10 K
40
Address
Lines
Bi-Directional
Data Lines
41
Data 5Ch
is in Flash
Memory
Instruction:
MOV A,# 3CH
74
3C
42
At RAM Address
3C hex - -
Instruction:
MOV A,3CH
Data is
7F hex
ACC
data
will be
7F h
E5
3C
43
85
80
A0
44
45
46
47
Registers of 8051
48
30H
2FH
Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H
Register Bank 3
Register Bank 2
Register Bank 1( Stack)
Register Bank 0
49
Address Modes
; C bit 0 of P0
Prof. Cherrice
EE/CS-152: Microprocessors
andTraver
mov R5,0fah
ANL A,#08H
mov c,23h.2
; Data from RAM location ; 23hex bit .2 is
transferred to carry
mov 35.7,c
; Data from Carry Flag bit is transferred ;
to RAM location 35 decimal bit .7 i.e. ; 23H
Mov p0.1 , c
; Carry bit is transferred to Port 0 bit .1
End
( NOTE : RAM Loactions 20 hex to 2f hex are Bit
Addressable Area ).
51
2F 7F
2E
2D
2C
2B
2A
29
28
27
26
25
24
23
1A
22
21
20
10
0F
07
08
06
05
04
03
02
01
00
Prof. Cherrice
EE/CS-152: Microprocessors
andTraver
7FH
Scratch pad RAM
30H
2FH
20H
1FH
18H
17H
10H
0FH
08H
07H
00H
Bit-Addressable
RAM
Register Bank 3
Register Bank 2
( Stack)
Register Bank 1
Register Bank 0
53
Stacks
push
pop
stack pointer
stack
Prof. Cherrice
EE/CS-152: Microprocessors
andTraver
Timers
There are TWO general purpose 16 bit timers
TIMER MODES:
MODE 0
MODE 1
MODE 2
MODE 3
55
TIMER MODE 0
Setting timer X mode bits to 00 in the TMOD
registers results in using THX register as an
8 bit counter and TLX as a 5 bit counter;
pulse input is divided by 32d in TL so that
TH counts the original oscillator frequency
by a total 384d.
56
TIMER MODE 1
SIMILAR TO MODE 0 EXCEPT tlx IS
CONFIGURED AS A FULL 8 BIT COUNTER
57
TIMER MODE 2
The TLX is used as an 8 bit counter and
THX is used to hold a value that is loaded
into TLX every time TLX overflows from FFH
to 00H.
58
TIMER MODE 3
Timer 0 in mode 3 becomes two completely
separate 8 bit counters. Time 1 may work in
Mode 0, 1 and 2.
59
60
TMOD Register:
high.
62
TCON
IE1: External interrupt 1 edge flag. Set to 1 when H to L
edge signal is received on port 3 pin 3.3 ( INT1)
IT1: External interrupt 1 signal type control bit. Set to 1 by
program to enable external interrupt 1 to be triggered by a
falling edge signal. Set to 0 by by program to enable a low
level signal on external interrupt 1 to generate and
interrupt.
IE0: External interrupt 0 edge flag. External interrupt 1
edge flag. Set to 1 when H to L edge signal is received on
port 3 pin 3.2(INT0)
IT0: External interrupt 0 signal type control bit
63
Port 3
Port 2
Port 0
64
Port 3
Crystal
11.0592 MHz
Capacitors
30 pF
Microcontroller
Burge
Strip
Header
Port 2
Port 0
65
Port 3
Crystal
11.0592 MHz
Capacitors
30 pF
Microcontroller
Burge
Strip
Header
Port 2
Port 0
66
Pin 40
of
89c51
ATMEL 89c51 Microcontroller
Pin 1 of
89c51
Pin 20
Of
89c51
67
68
Two
Capacitors
33 pF
ATMEL 89c51 Microcontroller
69
70
PORT 1
LED
Array
71
Stepper
Motor
Stepper Motor
Interfacing
P1.0 to P1.3
PORT 1 thru
ULN 2003
Driver
72
Pin 10,11
to
MAX232
RS232 port
of P.C.
73
74
75
76
Microcontroller W/S
LAB. EXPERIMENTS
77
DESTINATION
OF DATA
MOV A,#56H
FLASH
MEMORY
ACCUMULATOR IMMEDIATE
MOV A,56H
MOV A,R1
Instruction
ADDRESSING
MODE
Infinite Loops
Prof. Cherrice
EE/CS-152: Microprocessors
andTraver
81
Lab. Experiment:
Alternately Blink LEDs at PORT 1 considering Delay
MOV A,#55H
MOV P1,A
LOOP: MOV R5,#0FFH
REPEAT3:
MOV R3,#0FFH
REPEAT2:
DJNZ R3,REPEAT2
DJNZ R5,REPEAT3
CPL A
MOV P1,A
JMP LOOP
Delay Loop
82
Lab. Experiment:
Connect LED Array to PORT 1. Scroll LEDs
one by one , in sinking mode
MOV A,#80H
MOV P1,A
LOOP: MOV R5,#0FFH
REPEAT3:
MOV R3,#0FFH
REPEAT2:
DJNZ R3,REPEAT2
DJNZ R5,REPEAT3
RR A
MOV P1,A
JMP LOOP
Delay Loop
83
MOV A,#0FFH
AGAIN:
MOV A,P0
MOV P1,A
JMP AGAIN
84
LOOP:
SETB P1.0
MOV R5,#3FH
CALL DELAY
CLR P1.0
MOV R5,#0FFH
CALL DELAY
JMP LOOP
DELAY:
NOP
DJNZ R5,AGAIN
RET
85
86
C1 EQU P1.0
C2 EQU P1.1
C3 EQU P1.2
C4 EQU P1.3
DATA EQU P1
DELAY:
MOV R7,#0FFH
AGAIN:
NOP
NOP
DJNZ R7,AGAIN
RET
87
88
89
90
mov R5,0fah
ANL A,#08H
mov c,23h.2
mov 35.7,c
Mov p0.1 , c
End
( NOTE : RAM Loactions 20 hex to 2f hex are Bit
Addressable Area ).
91
Microcontrollers
92
8051 Pin-out
RST Reset
HIGH for 2 clock cycles
Resets registers and
program counter (to 0000h)
for an orderly startup.
93
pwm_o
clk
25% duty cycle average pwm_o is 1.25V
pwm_o
clk
50% duty cycle average pwm_o is 2.5V.
96
Rotation achieved by
applying specific voltage
sequence to coils
Controller greatly simplifies
this
Sequence
1
2
3
4
5
Vd
A
+
+
+
1
B
+
+
+
A
+
+
16
B
+
+
Vm
2 MC3479P 15
14
13
12
Bias/Set
11
Phase A
Clk
10
CW/CCW
O|C
Full/Half Step
GND
Red
White
Yellow
Black
B
B
GND
A
A
B
B
Fall 2004
MC3479P
Stepper Motor
Driver
10
7
2 A B 15
3 A B 14
void main(void){
sbit clk=P1^1;
sbit cw=P1^0;
8051
CW/CCW
CLK
P1.0
P1.1
void delay(void){
int i, j;
for (i=0; i<1000; i++)
for ( j=0; j<50; j++)
i = i + 0;
}
Stepper
Motor
1K
+V
Q1
Q2
1K
Fall 2004
8051
P2.4
/*main.c*/
sbit notA=P2^0;
sbit isA=P2^1;
sbit notB=P2^2;
sbit isB=P2^3;
sbit dir=P2^4;
GND/ +V
P2.3
P2.2
P2.1
P2.0
Stepper
Motor
+V
Q1
B
1K
Q2
330
void delay(){
int a, b;
for(a=0; a<5000; a++)
for(b=0; b<10000; b++)
a=a+0;
}
void move(int dir, int steps) {
int y, z;
/* clockwise movement */
if(dir == 1){
for(y=0; y<=steps; y++){
for(z=0; z<=19; z+4){
isA=lookup[z];
isB=lookup[z+1];
notA=lookup[z+2];
notB=lookup[z+3];
delay();
}
}
}
Fall 2004
4 register banks
100
8051 SFRs
Blue: related to the I/O ports
101
102
103
104
105
106
107
108
RAM
109
110
111
112
113
114
115
mov R5,0fah
ANL A,#08H
mov c,23h.2
mov 35.7,c
Mov p0.1 , c
End
( NOTE : RAM Loactions 20 hex to 2f hex are Bit
Addressable Area ).
116
T
A
N
K
MicroController
2 C.O. /
DPDT
Relay
89c51
DC Motor
117
MOV P1,#FFh
MOV A,P1
LOOP:
MOV R1,P1
MicroController
89c51
From sensor 1st
Pin 1
P1.0
From sensor 2nd
Pin 2
P1.1
P 2.0
118