Vous êtes sur la page 1sur 42

Contents:

Contents:
Introduction Introduction
Block Diagram and Block Diagram and Pin Description of the 8051 Pin Description of the 8051
Registers Registers
Memor mapping in 8051 Memor mapping in 8051
!tack in the 8051 !tack in the 8051
I"# Port Programming I"# Port Programming
$imer $imer
Interrupt Interrupt
Why do we need to learn
Why do we need to learn
Microprocessors/controllers?
Microprocessors/controllers?

The microprocessor is the core of


computer systems.

Nowadays many communication, digital


entertainment, portable devices, are
controlled by them.

A designer should now what types of


components he needs, ways to reduce
production costs and product reliable
.
.
!ifferent aspects of a
microprocessor/controller

"ardware #$nterface to the real world

%oftware #order how to deal with inputs


The necessary tools for a
The necessary tools for a
microprocessor/controller
microprocessor/controller

&'(# &entral 'rocessing (nit

$/)# $nput /)utput

*us# Address bus + !ata bus

Memory# ,AM + ,)M

Timer

$nterrupt

%erial 'ort

'arallel 'ort
CP%
General-
Purpose
Micro-
processor
R&M R#M
I"#
Port
$imer
!erial
C#M
Port
Data Bus
&ddress Bus
General-Purpose Microprocessor System
Microprocessors#
Microprocessors#

CPU for Computers

No RAM, ROM, I/O on CPU chip itself

!ample Intel"s !#$, Motorola"s $#%!%


Many chips on mother"s &oar'
General-purpose microprocessor
R&M R#M
I"#
Port
$imer
!erial
C#M
Port
Microcontroller
CP%

A smaller computer

On-chip RAM, ROM, I/O ports(((

!ample Motorola"s $#)), Intel"s #%*), +ilo,"s +# an' PIC )$-


A sin,le chip
Microcontroller .
Microprocessor

CPU is stan'-alone, RAM,


ROM, I/O, timer are separate

'esi,ner can 'eci'e on the


amount of ROM, RAM an'
I/O ports(

e!pansi/e

/ersatility

,eneral-purpose
Microcontroller
0
CPU, RAM, ROM, I/O an'
timer are all on a sin,le chip
0
fi! amount of on-chip ROM,
RAM, I/O ports
0
for applications in 1hich cost,
po1er an' space are critical
0
sin,le-purpose
Microprocessor /s( Microcontroller

m&e''e' system means the processor is em&e''e' into that


application(

An em&e''e' pro'uct uses a microprocessor or microcontroller to 'o


one tas2 only(

In an em&e''e' system, there is only one application soft1are that is


typically &urne' into ROM(

!ample printer, 2ey&oar', /i'eo ,ame player


m&e''e' System
)( meetin, the computin, nee's of the tas2 efficiently an' cost
effecti/ely
0
spee', the amount of ROM an' RAM, the num&er of I/O ports
an' timers, si3e, pac2a,in,, po1er consumption
0
easy to up,ra'e
0
cost per unit
4( a/aila&ility of soft1are 'e/elopment tools
0
assem&lers, 'e&u,,ers, C compilers, emulator, simulator,
technical support
5( 1i'e a/aila&ility an' relia&le sources of the microcontrollers(
6hree criteria in Choosin, a Microcontroller
Block Diagram
Block Diagram
CP%
#n'chip
R&M
#n'chip
R#M for
program
code
( I"# Ports
$imer 0
!erial
Port
#!C
Interrupt
Control
)*ternal interrupts
$imer 1
$imer"Counter
Bus
Control
$*D R*D
P0 P1 P+ P,
&ddress"Data
Counter
Inputs
Pin Description of the 8051
Pin Description of the 8051
-
.
/
0
1
2
3
4
5
-6
--
-.
-/
-0
-1
-2
-3
-4
-5
.6
06
/5
/4
/3
/2
/1
/0
//
/.
/-
/6
.5
.4
.3
.2
.1
.0
./
..
.-
'-.6
'-.-
'-..
'-./
'-.0
'-.1
'-.2
'-.3
,%T
7,8!9'/.6
7T8!9'/.-
7T69'/.0
7T-9'/.1
8TA:.
8TA:-
;N!
7$NT69'/..
7$NT-9'/./
7,!9'/.3
7W,9'/.2
<cc
'6.67A!6
9
'6.-7A!-9
'6..7A!.
9
'6./7A!/9
'6.07A!09
'6.17A!19
'6.27A!29
'6.37A!39
=A/<''
A:=/',);
'%=N
'..37A-19
'..27A-0
9'..17A-/
9'..07A-.
9'../7A--9
'...7A-69
'..-7A59
'..67A49
461-

Wednesday, %eptemb
er .0, .6-0
Mahdi "assanpour

&reated by bibe
&reated by bibe
7i,ure 8a9( -6A: Connection to #%*) 7i,ure 8a9( -6A: Connection to #%*)
&.
,0p-
&-
,0p-
8TA:.
8TA:-
;N!

Usin, a ;uart3 crystal oscillator

<e can o&ser/e the fre;uency on the -6A:4 pin(



Pins of 8051 Pins of 8051

+"( +"(

RS6 pin = reset


>
It is an input pin an' is acti/e hi,h normally lo1 (

6he hi,h pulse must &e hi,h at least 4 machine cycles(


>
It is a po1er-on reset(

Upon applyin, a hi,h pulse to RS6, the


microcontroller 1ill reset an' all /alues in re,isters
1ill &e lost(

Reset /alues of some #%*) re,isters


-igure ./01 Po2er'#n R)!)$ Circuit -igure ./01 Po2er'#n R)!)$ Circuit
5% p7
5% p7
#(4 ?
)% u7
@
Acc
))(%*=4 MB3
A/APP
-)
-4
RS6
5)
)=
)#
=

Pins of 8051 Pins of 8051

,"( ,"(

/A pin 5) e!ternal access


>
6here is no on-chip ROM in #%5) an' #%54 (
>
6he /A pin is connecte' to GNC to in'icate the co'e is
store' e!ternally(
>
/PSN A: are use' for e!ternal ROM(
>
7or #%*), /A pin is connecte' to Acc(
>
D/E means acti/e lo1(

/PSN pin 4= pro,ram store ena&le


>
6his is an output pin an' is connecte' to the O pin of the
ROM(
Pins of 8051 Pins of 8051

("( ("(

A: pin 5% a''ress latch ena&le


>
It is an output pin an' is acti/e hi,h(
>
#%*) port % pro/i'es &oth a''ress an' 'ata(
>
6he A: pin is use' for 'e-multiple!in, the a''ress
an' 'ata &y connectin, to the G pin of the FG:S5F5
latch(

I/O port pins


>
6he four ports P%, P), P4, an' P5(
>
ach port uses # pins(
>
All I/O pins are &i-'irectional
(
(
Wednesday, %eptemb
er .0, .6-0
Mahdi "assanpour
Bar'1are Structure of I/O Pin
Bar'1are Structure of I/O Pin

ach pin of I/O ports


>
Internal CPU &us communicate 1ith CPU
>
A C latch store the /alue of this pin

C latch is controlle' &y D<rite to latchE


> <rite to latch ) 1rite 'ata into the C latch
> 4 6ri-state &uffer

6H). controlle' &y DRea' pinE


>
Rea' pin ) really rea' the 'ata present at the pin

6H4. controlle' &y DRea' latchE


> Rea' latch ) rea' /alue from internal latch
> A transistor M) ,ate

GateI%. open

GateI). close
! :atch
! :atch
#
#
Wednesday, %eptemb
er .0, .6-0
Mahdi "assanpour
Wednesday, %eptemb
er .0, .6-0
Mahdi "assanpour
Wednesday, %eptemb
er .0, .6-0
Mahdi "assanpour
Wednesday, %eptemb
er .0, .6-0
Mahdi "assanpour
Wednesday, %eptemb
er .0, .6-0
Mahdi "assanpour
Other Pins
Other Pins

P), P4, an' P5 ha/e internal pull-up resisters(


>
P), P4, an' P5 are not open 'rain(

P% has no internal pull-up resistors an' 'oes not


connects to Acc insi'e the #%*)(
>
P% is open 'rain(
>
Compare the fi,ures of P)(- an' P%(-(

Bo1e/er, for a pro,rammer, it is the same to pro,ram


P%, P), P4 an' P5(

All the ports upon RS6 are confi,ure' as output(


Wednesday, %eptemb
er .0, .6-0
Mahdi "assanpour
Port % 1ith Pull-Up Resistors
Port % 1ith Pull-Up Resistors
P%(%
P%()
P%(4
P%(5
P%(G
P%(*
P%($
P%(F
D!5000
8351
8451
5cc
10 6
P
o
r
t

0
Port 5 Alternate 7unctions
Port 5 Alternate 7unctions
)F )F RC RC P5(F P5(F
)$ )$ <R <R P5($ P5($
)* )* 6) 6) P5(* P5(*
)G )G 6% 6% P5(G P5(G
)5 )5 IN6) IN6) P5(5 P5(5
)4 )4 IN6% IN6% P5(4 P5(4
)) )) 6!C 6!C P5() P5()
)% )% R!C R!C P5(% P5(%
Pin Pin -unction -unction P, Bit P, Bit

R)!)$ 5alue of !ome 8051 Registers: R)!)$ 5alue of !ome 8051 Registers:
0000 DP$R
0003 !P
0000 P!7
0000 B
0000 &CC
0000 PC
Reset 5alue Register
R&M are all 8ero
1
1

Registers
A
H
R%
R)
R5
RG
R4
R*
RF
R$
CPB CP:
PC
CP6R
PC
Some #%*) )$-&it Re,ister
Some #-&itt Re,isters of
the #%*)
Memory mapping in 8051
Memory mapping in 8051

ROM memory map in 8051 family


%%%%B
%777B
%%%%B
)777B
%%%%B
F777B
#F*)
A6#=C*)
#F*4
A6#=C*4
0
CS*%%%-54
4 /.
from Atmel Corporation
from Callas Semicon'uctor

RAM memory space allocation in the 8051


F7B
5%B
47B
4%B
)7B
)FB
)%B
%7B
%FB
%#B
)#B
%%B
Re,ister Han2 %
( Stac2 ) Register Bank 1
Re,ister Han2 4
Re,ister Han2 5
Hit-A''ressa&le RAM
Scratch pa' RAM
!tack in the 8051
!tack in the 8051

6he re,ister use' to access


the stac2 is calle' !P 8stac2
pointer9 re,ister(

6he stac2 pointer in the #%*)


is only # &its 1i'e, 1hich
means that it can ta2e /alue
%% to 77B( <hen #%*)
po1ere' up, the SP re,ister
contains /alue %F(
F7B
5%B
47B
4%B
)7B
)FB
)%B
%7B
%FB
%#B
)#B
%%B
Re,ister Han2 %
( Stac2 ) Register Bank 1
Re,ister Han2 4
Re,ister Han2 5
Hit-A''ressa&le RAM
Scratch pa' RAM
Timer #
Timer #
TM)! ,egister
TM)! ,egister
#
#

;ate # When set, timer only runs while $NT76,-9 is


high.

&/T # &ounter/Timer select bit.

M- # Mode bit -.

M6 # Mode bit 6.
T&)N ,egister#
T&)N ,egister#

T>-# Timer - overflow flag.

T,-# Timer - run control bit.

T>6# Timer 6 overflag.

T,6# Timer 6 run control bit.

$=-# =?ternal interrupt - edge flag.

$T-# =?ternal interrupt - type flag.

$=6# =?ternal interrupt 6 edge flag.

$T6# =?ternal interrupt 6 type flag.


$nterrupt #
$nterrupt #
$nterrupt =nable ,egister #
$nterrupt =nable ,egister #

=A : Global enable/disable.

--- : ndefined.

=T. #=nable Timer . interrupt.

=% #=nable %erial port interrupt.

=T- #=nable Timer - interrupt.

=8- #=nable =?ternal - interrupt.

=T6 # =nable Timer 6 interrupt.

=86 # =nable =?ternal 6 interrupt. .

Vous aimerez peut-être aussi