Está en la página 1de 27

1

www.khdaw.com

1.2
1.3

1974 ----1976
1976 ----1978

1978 ----

co

1982 ----8 16 32
1.5

kh
da
w.

1 4 8 16
32

1.6 MCS-51
803180518751

8031 1 8 cpu128BRAM21 SFR4 8


I/O 1 2 16 / EPROM

w.

8051 8031 4KBROM 1

ww

4KB

8751 8031 4KB EPROM 1 4KB

EPROM
1.7 MCS-51 80C51
MCS-51 80C51 CMOS
CPU
RAM
1.8 8051 8751 C
A

www.khdaw.com

www.khdaw.com

1.9 B
A B

1.10

MCS-51

2.1 MCS-51

co

CPU RAM ROM/EPROM


8031 4 8 I/O P0 P1 P2 P3
1

kh
da
w.

2 16 /21 SFR

CPU
RAM 128B
52 256B 64KB
ROM/EPROM
5 2 /

w.

I/O
CPU

ww

2.2 MCS-51 EA

PC 0FFFH

80518751 4KB

8031

2.3 MCS-51
12 1

www.khdaw.com

www.khdaw.com

2.4 MCS-51 6 MHZ 1 2


2.5 5 5 MCS-51 5

0003H

0T0

000BH

0013H

1T1

001BH

0023H

co

2.6 RAM 30H 26H


2.7 A 63HP 0

kh
da
w.

2.8
A8031 CPU RAM EPROM

C MCS-51 I/O 1

DPC

w.

2.9 8031 R4 04H PSW=00H


0

ww

2.10 1 12MHZ 1

CPU 12
6 S1-S6 2 P1 P21

12 S1P1S1P2S2P1S2P2S6P2 12MHZ
1 1s
2.11 PC DPTR
ADPTR PC

B 16

C 1

www.khdaw.com

www.khdaw.com

DDPTR 2 8 PC

12 RAM

00H-1FH 32 4 8 8
R0-R7 20H-2FH 16 128
1 00H-7FH
2.13 8031 EA
2.14 RAM 128 3

00H-1FH 32 4 8 8

co

R0-R7 PSW RS1RS0

kh
da
w.

20H-2FH 16 128
1 30H-7FH RAM

2.15

A PC

B RAM

C8031 21

2.16

w.

PC C

ww

A
B
C
D
2.17 PC
PC
2.18 P3

P3.0
P3.1

www.khdaw.com

www.khdaw.com
0
1
0
1

P3.2
P3.3
P3.4
P3.5
P3.6
P3.7

2.19 MCS-51 PC
MCS-51 PC 16 64KB
2.20 MCS----51

2.21

co

APC 1
B

kh
da
w.

C MCS----51 1 1

D SP

2.22 MCS----51

ALE

MCS-51

w.

ww

3.1
1 MOV 28H@R2

(2) DEC DPTR

(5) CPL

R5

(6) MOV R0,R1

F0,Acc.3

(10)MOVX A,@R1

(3) INC

(7) PUSH

DPTR

DPTR

(11) MOV C,30H

(4) CLR R0

(8)

MOV

(12)RLC

R0

F0,C

(9)MOV

381011
3.2
A
B

3.3 ADPTRPC

www.khdaw.com

www.khdaw.com

3.4 MCS-51
7
1
2

DPTR PC

co

A 16

kh
da
w.

rel

PC
3.5 MCS-51

MCS-51 28 24
25 17 17
3.6 SFR

w.

SFR 8 SFR SFR


ABDPTR

ww

3.7
3.8 A 30H
1000HMOVC

A@A+PC

1031H
3.9 MCS----51 PC DPTR PC
DPTR
3.10

3.11
PUSH

www.khdaw.com

www.khdaw.com

PUSH
POP
POP

B
A
B

AB
A=02HSP=52H
51H=FFH
52H=FFH

A=50H

DPH
DPL
DPTR,#4000H
A
B,A
A,@A+DPTR
A
A,B
A
A,@A+DPTR
A

co

POP
POP
MOV
RL
MOV
MOVC
PUSH
MOV
INC
MOVC
PUSH
RET
ORG
DB

kh
da
w.

3.12

4000H
10H,80H,30H,50H,30H,50H

SP=50H

51H=30H

52H=50H

PC=5030H

3.13
A Acc.3Acc.4Acc.5 Acc.6 0
ANL A#87H

w.

B A 4 0
ANL A#C3H

ww

C Acc.2 Acc.3 1
ORL A#0CH

3.14 A=83HR0=17H17H=34H
ANL
ORL
XRL
CPL

A#17H
17HA
A@R0
A

A 0CBH
3.15 A=55HR3=0AAH ANL AR3 A=00H R3=0AAH
3.16 DPTR=507BHSP=32H
30H=50H
31H=5FH
32H=3CH

POP

DPH

www.khdaw.com

www.khdaw.com
POP
POP

DPL
SP

DPH=3CH

DPL=5FH

SP=4FH

3.17 SP=60HA=30HB=70H
PUSH
PUSH

A
B

SP 62H
61H 30H62H 70H
3.18 3-3~ 3-7 16
FF

C0

E0

E5

F0

F0

co

MOV R7A
PUSH 0E0H
MOV A0F0H
MOVX @DPTR, A

kh
da
w.

FF
C0 E0
E5 F0
F0

MCS-51

4.1

w.

2A

ww

MCS----51 B

C
I/O
3

4.3

www.khdaw.com

www.khdaw.com

ROM/EPROM

4.4 1000H
ORG 1000H
TAB1 EQU
1234H
TAB2 EQU
3000H
DB
MAIN
DW
TAB1TAB270H
1000H=M1001H=A1002H=I1003H=N1004H=34H

4.5

co

1005H=12H 1006H=00H 1007H=30H 1008H=70H 1009H=00H

kh
da
w.

1
2
3
RET PC
4 RET
PC

w.

ww

6
4.6 1 RAM 45H 4 0 4 1

MOV
ANL
ORL

A45H
A#0FH
A#0FH

4.7 A=02HSP=42H41H=FFH42H=FFH
POP
POP
MOV
RL
MOV
MOVC

DPH
DPL
DPTR,#3000H
A
B,A
A,@A+DPTR

www.khdaw.com

10

www.khdaw.com
PUSH
MOV
INC
MOVC
PUSH
ORG
DB

A=80H

A
A,B
A
A,@A+DPTR
A
3000H
10H,80H,30H,80H,50H,80H

SP=40H 41H=50H 42H=80H

PC=8050H

MOV
DL1: MOV
DL2: MOV
DJNZ
DJNZ
RET

R3,#15
R4,#255
P1,R3
R4,DL2
R3,DL

kh
da
w.

15.346s

1
1
2
2
2
2

co

7B0F
7CFF
8B90
DC
DB
22

4.8 12MHZ

4.9 A=83HR0=17H17H=34H
ANL
ORL
XRL
CPL

A#17H
17HA
A@R0
A

A 0CBH

4.10 RAM 30H~50H 0AAH

w.

51H 01H
51H 00H

ww

ORG
MOV
MOV
LOOP: MOV
CJNE
MOV
SJMP
NOT:
INC
DJNZ
MOV
DEND: SJMP

0000H
R0,#30H
R2,#21H
A,@R0
A,#0AAH,NOT
51H,#01H
DEND
R0
R2,LOOP
51H,#00H
DEND

4.11 RAM 20H~40H 00H


41H
ORG
MOV
MOV

0000H
R0,#20H
R2,#21H

www.khdaw.com

10

11

www.khdaw.com

LOOP:

NOTE:

4.12

MOV
MOV
CJNE
INC
INC
DJNZ
END

41H,#00H
A,@R0
A,#00H,NOTE
41H
R0
R2,LOOP

SP=60H LABEL 3456HLCALL 2000H

2000H

LCALL

LABEL SP PC

LCALL ACLAA ACALL

co

SP 62H61H=03H
62H=20HPC 3456H,
LCALL ACALL LCALL 64KB ACALL

kh
da
w.

ACALL 2KB ( 16
5 ACALL 2002H-27FFH

MCS-51

5.1

w.

5.3 MCS-51

MCS----51 5
1

ww

0 IE02 1 IE13/
T0 TF0
4/ T1
TF15 TI RI2
3
5.4 1 0013H

5.5 ABC

A MCS-51 IE
B MCS-51 TMOD
C MCS-51 IP
D MCS-51 TCON SCON

www.khdaw.com

11

12

www.khdaw.com

5.6 MCS-51 CPU

3-8 CPU
1CPU
2
3 RETI IE IP
5.7 8031 D

B RETI

co

C DIV

D MOV AR3

kh
da
w.

5.8 8031 LCALLPC


16 PC

5.9 1

ww

w.

ORG
AJMP
ORG
AJMP
ORG
MAIN: SETB
SETB
SETB
HERE: AJMP
PINT1: RETI
END

0000H
MAIN
0013H
PINT1
0100H
IT1
EX1
EA
HERE

5.10 MCS-51 D

A
B
C
D
5.11 MCS-51
/

www.khdaw.com

12

13

www.khdaw.com

5.12 C D
A
B
C

D
5.13 RETI RET

RETI 1 MCS-51

co

5.14 3 123 CPU

kh
da
w.

321 1000H
1100H1200H
0000H
MAIN
0003H
PINT0
0100H
IT0
EX0
EA
HERE
PSW
A
P1.3,IR3
P1.2,IR2
P1.1,IR1
A
PSW

ww

w.

ORG
AJMP
ORG
LJMP
ORG
MAIN:
SETB
SETB
SETB
HERE:
SJMP
PINT0: PUSH
PUSH
JNB
JNB
JNB
PINTIR: POP
POP
RETI
IR3:
LJMP
IR2:
LJMP
IR1:
LJMP
ORG
IR3INT: LJMP
ORG
IR2INT: LJMP
ORG

IR3INT
IR2INT
IR1INT
1000H
PINTIR
1100H
PINTIR
1200H

www.khdaw.com

13

14

www.khdaw.com

IR1INT: LJMP
END

PINTIR

MCS-51 /

6.1 3MHZ/ 012

213*4us=32.768

216*4us=262.144

28*4us=1.024

6.2 /

co

/
1 1/

kh
da
w.

1/2

6.3 /

/ T0 T1
1/24

6.4 / T0 100 T0
1ms MCS---51
6MHZ 1

ww

w.

ORG
0000H
AJMP
MAIN
ORG
000BH
LJMP
PT0J
ORG
0100H
MAIN:
MOV
TMOD,#05H;00000001
MOV
TH0,#0FFH;X=65436
MOV
TL0,#9CH
CLR
F0
SETB
TR0
SETB
ET0
SETB
EA
HERE: AJMP
HERE
PT0J:
JB
F0,PT0D
MOV
TMOD,#01H;00000001
MOV
TH0,#0FEH;X=65036
MOV
TL0,#0CH
SETB
F0

www.khdaw.com

14

15

www.khdaw.com

PT0D:

RETI
CLR
MOV
MOV
MOV
RETI
END

F0
TMOD,#05H
TH0,#0FFH
TL0,#9CH

6.5 / 2
2 8 /TLX
TLX 1 TFX THX

TLX TLX X=01

co

6.6 T0 2 P10 400 1


10

ww

w.

kh
da
w.

ORG
0000H
AJMP
MAIN
ORG
000BH
AJMP
PT0
ORG
0100H
MAIN:
MOV
R2,#00H
MOV
TMOD,#02H
MOV
TH0,#0ECH;X=236
MOV
TL0,#0ECH
SETB
P1.0
SETB
TR0
SETB
ET0
SETB
EA
HERE:
SJMP
HERE
PT0:
CJNE
R2,#09H,PT01
SETB
P1.0
MOV
R2,#00H
RETI
PT01: CLR
P1.0
INC
R2
RETI
END
6.7

6.8 T0 3 T1
C/T M1 M0

www.khdaw.com

15

16

www.khdaw.com

6.9 /
6MHZ
0 Tw=131.072us
6.10 P1.0 P1.1
P1.2 R0R1 R1

LOOP3:
LOOP4:

co

LOOP1:
LOOP2:

0000H
MAIN
0100H
R0,#00H
R1,#00H
TL0,#00H
TH0,#00H
P1.0,LOOP1
P1.0,LOOP2
TR0
P1.2,LOOP3
P1.2,LOOP4
TR0
R1,TH0
R0,TL0

kh
da
w.

MAIN:

ORG
LJMP
ORG
MOV
MOV
MOV
MOV
JB
JNB
SETB
JNB
JB
CLR
MOV
MOV
END

R0

6.11 THX TLXX=01

w.

THX TLXX=01,

ww

6.12

1 SCON/

2 TCON/

3 IE/

4 TMOD/

www.khdaw.com

16

17

www.khdaw.com

MCS-51

7.3

1 8 1 1

7.4

0 1 2 3

0
D0

D1

D2

D3

D4

D5

D6

D7

0 =Fosc/12

D0

D1

D2

D3

D4

SMOD

1 =2

T1 /32

D6

kh
da
w.

2 3

D5

D0

D1

D2

D3

D4

D7

co

D5

D6

D7

D8

2 =2MOD*Fosc/64

3 =2MOD *T1 /32

7.5 1 8 1 1

w.

ww

7.6
(A) 9 T
(B) 9 SCON TB8 T
(C)TB8 SBUFF
D 9 SCON RB8 T
E 1 / T1 T

7.7 C
AMOVC BMOVX CMOV DXCHD

www.khdaw.com

17

18
7.8

www.khdaw.com

/ T1 2

?
T1 2
2
T1 2 X,
T1 =/(256-X)=Fosc/(256-X)*12
2 =2MOD *Fosc/(256-X)*12*32
X=2MOD *Fosc/12*32*

co

kh
da
w.

AFosc/32
BFosc/16
C/ T1
DFosc/64

7.9 1 C

7.10

7.11 11.0592MHZ, 1 4800b/s T1

01000000Fosc=11.0592MHz

SMOD=1

SCON=40H

X=65536-11.0592*2/(384*4800)
=65524=0FFF4H

0000H
SCON,#40H
PCON,#80H
TMOD,#10H
TL1,#0F4H
TH1,#0FFH

ww

w.

ORG
MOV
MOV
MOV
MOV
MOV
END

7.14 8031 3 1200b/s 9


ORG
0000H
LJMP MAIN
ORG
0023H
LJMP
SSEND
ORG
0100H

www.khdaw.com

18

MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
SETB
SETB
SETB
SEND:
MOVX
MOV
MOV
MOV
HERE: AJMP
SSEND: DJNZ
AJMP
SEND1: PUSH
PUSH
PUSH
PUSH
SETB
SETB
CLR
INC
MOVX
MOV
MOV
MOV
POP
POP
POP
POP
CLR
CLR
RETURN: RETI
END

SP,#60H
TMOD,#20H
TH1,#0F3H
TL1,#0F3H
R2,#0FFH
87H,#80H
SCON,#0C0H
DPTR,#2000H
TR1
ES
EA
A,@DPTR
C,P
TB8,C
SBUF,A
HERE
R2,SEND1
RETURN
DPH
DPL
PSW
ACC
0D4H
0D3H
TI
DPTR
A,@DPTR
C,P
TB8,C
SBUF,A
ACC
PSW
DPL
DPH
0D4H
0D3H

ww

w.

kh
da
w.

MAIN:

www.khdaw.com

co

19

ORG
LJMP
ORG
LJMP
ORG

0000H
MAIN
0023H
RRES
0100H

www.khdaw.com

19

MOV
MOV
MOV
MOV
MOV
SETB
MOV
MOV
MOV
SETB
SETB
SJMP
RRES: DJNZ
AJMP
RES:
CLR
MOV
MOV
JNC
JNB
AJMP
L1:
JB
L2:
MOVX
INC
AJMP
ERP:
SETB
CPL
RETURN: RETI
END

SP,#60H
TMOD,#20H
TH1,#0F3H
TL1,#0F3H
R2,#0FFH
TR1
DPTR,#3000H
87H,#80H
SCON,#0D0H
ES
EA
$
R2,RES
RETURN
RI
A,SBUF
C,P
L1
RB8,ERP
L2
RB8,ERP
@DPTR,A
DPTR
RETURN
P1.0
P1.0

w.

kh
da
w.

MAIN:

www.khdaw.com

co

20

ww

ORG
MAIN: MOV
MOV
MOV
MOV
MOV
MOV
MOV
SETB
SEND: MOVX
MOV
MOV

0000H
TMOD,#20H
TH1,#0F3H
TL1,#0F3H
87H,#80H
SCON,#0C0H
DPTR,#2000H
R2,#0FFH
TR1
A,@DPTR
C,P
TB8,C

www.khdaw.com

20

21

www.khdaw.com

STI:

MOV
JNB
CLR
INC
DJNZ
END

SBUF,A
TI,STI
TI
DPTR
R2,SEND

ORG
MOV
MOV
MOV
SETB
MOV
MOV
MOV
MOV
JNB
CLR
MOV
MOV
JNC
JNB
AJMP
JB
MOVX
INC
DJNZ
SETB
CPL
END

0000H
TMOD,#20H
TH1,#0F3H
TL1,#0F3H
TR1
DPTR,#3000H
87H,#80H
SCON,#0D0H
R2,#0FFH
RI,RES
RI
A,SBUF
C,P
L1
RB8,ERP
L2
RB8,ERP
@DPTR,A
DPTR
R2,RES
P1.0
P1.0

L1:
L2:

co

w.

ERP:

kh
da
w.

RES:

ww

7.15 8031 1 07 1 1
1 1800
=1800*1+7+1+1/60=300b/s
7.16 MCS-51 0 01
0 8 1

MCS-51

8.1
8.2 05H 06H 56H
2001H

www.khdaw.com

21

22

www.khdaw.com

2002H 2002H

0000H
B,#10H
DPTR,#2001H
A,@DPTR
A,#0FH
AB
B,A
DPTR,#2002H
A,@DPTR
A,B
@DPTR,A

co

ORG
START: MOV
MOV
MOVX
ANL
MUL
MOV
MOV
MOVX
ADD
MOVX
END

8.3 2000H 80H,

kh
da
w.

MOV
P2,#20H
MOV
R0,#00H
MOVX A,@R0

A80H

8.5 MCS-51 16 8

16 8
/RD(P3.7)/WR(P3.6)/PSEN

w.

8.6 MCS-51 : (4)

2)

MCS-51

3)

ROM RAM

4)

/RD /PSEN

ww

1)

8.7

8.9 0000H---3FFFH16 KB
8.10 MCS-51 PC DPTR PC()
DPTR
8.11 11 204816KB14

www.khdaw.com

22

23

www.khdaw.com

8.12 32KB RAM 2000H,(0FFFF)H


8.14 89C51 1 E2PROM2864 , 2864
8000H
1 2864
2 2864

kh
da
w.

co

MCS-51 I/O

w.

9.1 I/O I/O I/O

ww

I/OI/OI/OI/O
I/O I/O I/O

I/O
9.2 I/O MCS51 I/O

I/O
I/O
I/OI/O
I/O

www.khdaw.com

23

24

www.khdaw.com

I/OMCS-51 I/O
RAM
9.3 I/O

ww

w.

kh
da
w.

co

I/O
1

(3)
MCS-51 I./O I/O

.
9.4 8255A C / PC7 0PC4 1
8255A
7FFCH-7FFFH
ORG
0000H
MOV
DPTR,#7FFFH
MOV
A,#0EH
MOVX
@DPTR,A
MOV
A,#09H
MOVX
@DPTR,A
END
9.7 8155H TIMERIN /TIMEROUT

8155H2 8 PAPB1 6
TIMERIN/TIMEROUTTIMERIN 8155H 14
1/TIMEROUT 14 0

9.8
1 8155H 8031
2 8155H RAM AD7-AD0 /WR
38255A
48255A B 2

9.9 8031 8255A, 8255A B B


A B
A
ORG
0000H
MOV
DPTR,#0003H
MOV
A,#82H

www.khdaw.com

24

25

www.khdaw.com

w.

kh
da
w.

co

MOVX
@DPTR,A
MOV
DPTR,#0001H
MOVX
A,@DPTR
MOV
DPTR,#0000H
MOVX
@DPTR,A
END
9.10 8155H TIMERIN 4MHz 8155H
14
T=2 *1/4MHz=4096 s
9.11MCS-51 8155H
8255A
RAMI/O 8155HI/O 8255H
9.12 8155H TIMERIN 1MHz 8155H /TIMEROU
10ms
8155 7F00H-7F05H

ORG
0000H
MOV
DPTR,#7F04H
MOV
A,#0E8H
MOVX
@DPTR,A
INC
DPTR
MOV
A,#40H
MOVX
@DPTR,A
MOV
DPTR,#7F00H
MOV
A,#0C0H
MOVX
@DPTR,A
END

MCS-51

ww

10.1
CPU

10ms
10ms

10.3 LED
P228-P230
10.5
P234
10.7
P236 -P237

www.khdaw.com

25

26

www.khdaw.com

10.9 10-14 6 LED 123456


.

MOV R2#06H
MOV
R0#79H
MOV
A#01H
LOOP MOV
@ROA
INC A
INC R0
DJNZ
R2LOOP
P239
DIR MOV
R9#79H
MOV
R3#01H

kh
da
w.

co

MCS-51 A/DD/A

w.

11.1 D/A
/
11.2 D/A DAC 12 5V

D/A
12
5V/2 = 1.220703125mv
11.3 DAC
DACP283
11.4 D/A

ww

11.5 MCS-51 DAC0832


?

DAC

11.7 A/D 1 8 A/D 0-5V

=+LSB/2=+1/2*5/28 =+9.77mv
11.12
1A/DD/AF

www.khdaw.com

26

27

www.khdaw.com

2ADC0809 EOC 8031 T

ww

w.

kh
da
w.

co

3A/DF

www.khdaw.com

27