You are on page 1of 43

89Cxx Microcontroller

2009

89C
- ABU robocon
. . micro book
. AT89C51and AT89C2051 Microcontrollers document
COPY .


AT89 Series Hardware Description
Atmel 89Cxx
. .
0 2-
, (Timer/Counters)
, (Serial Interface)
(Interrupt System)
Reset
Reduced Power Modes and Low Power Idle
1- microcontroller- .
1- AT89 .
1

AT89S8252


1k flash
2k Flash
4k Flash
8k Flash
20k Flash
8k Flash

AT89S53

12k Flash

AT89C1051
AT89C2051
AT89C51
AT89C52
AT89C55

Data Memory
Bytes

64 RAM
128 RAM
128 RAM
256 RAM
256 RAM
256 RAM 2K
EEPROM
256 RAM

16-
timer
1
2
2
3
3
3

CMOS

CMOS
CMOS
CMOS
CMOS
CMOS
CMOS


(Special Function Registers) /SFR/
2-
(Special Function Registers) /SFR/ .
.

8952- 89
. .
Accumulator: . 1
. A
.
. RESET-
00 .
register: .
. RESET- 00 .
PSW Program Status Word:

. RESET- 00
.
SP Stack Pointer: PUSH
. CALL
.
RESET- SP- 07 Stack- 08
.
DPTR Data Pointer: DPH ( ), DPL ( ) 2
16 . 892051-
000-7FFH 2 11 . 8
2 . RESET-
0000 .

1, 3 Ports: 1 3 .
.
.
1 . 0
. RESET- FF . 1
.
SBUF Serial Data Buffer: .
.
. RESET-
.
TH0, TL0 Timer 0 registers: 16 0 /
. ,
. 16
0- 65535 . 65535
. RESET- 0000 .
TH1, TL1 Timer 1 registers: 16 1 /
. 0-
(baud rate) . RESET-
0000 .
IP Interrupt Priority:
. RESET- 00000
. .
.
IE Interrupt Enable: ,
. ,
. RESET- 000000 .
TMOD Timer Mode: / . /
8 16
. / 8 0-
. 255 0
. TL
. RESET- 00 .
TCON Timer Control: / . /
, .
RESET- 00 .
SCON Serial Control: .

. RESET- 00 .
PCON Power Control: Power
Down, Power Idle . RESET-
00000 .

SFR .
.
.
80h 0: 0. 0 . ,
0 , 0
.
81h - S: Stk itr. .
( rst ) 07h . Y
.
S- .

82h - DL: Dt itr Lw. 16


DR (Dt itr) .
8h - D: Dt itr igh. DR .
87h - N: wr trl. .
3 .
1.
2. Idle
3. Power Down
N .

PCON.7

PCON.6

PCON.5

PCON.4

PCON.3

PCON.2

PCON.1

PCON.0

SMOD

GF1

GF2

PD

IDL

N.7 = SD - .
N. = GF1 - .
N.2 = GF0 - .
N.1 = D - wr Dw . "1" 8951 wr Dw
.
N.0 = IDL - Idl . "1" 8951 Idl .
88h - N: imr trl. . 1, 0 -
, .
TCON.7

TCON.6

TCON.5

TCON.4

TCON.3

TCON.2

TCON.1

TCON.0

TF1

TR1

TF0

TR0

IE1

IT1

IE0

IT0

N.7 = 1 - 1 - .
N.6 = R1 - 1 - .
N.5 = F0 - 0 - .
N.4 = R0 - 0 - .
N. = IE1 - 1- .
N.2 = I1 - 1- .
N.1 = IE0 - 0- .
N.0 = I0 - 0- .
89h - D: imr d. , 4 1-, 4
0- .
TMOD.7

TMOD.6

TMOD.5

TMOD.4

TMOD.3

TMOD.2

TMOD.1

TMOD.0

GATE1

C/T1

M1.1

M0.1

GATE0

C/T0

M1.0

M0.0

D.7 = G1 - G1 = 1, R1 = 1 1 IN1 = 1 .
, . G1 = 0 1
R1 = 1 .
D.6 = /1- 1 - .
"1" 12 .
"" 1 .
D.5 = 1.1 - 1 - r 1.
D.4 = M0.1 - 1 - r 0
D. = G0 - G0 = 1, R0 = 1 0 IN0 = 1 .
, . G0 = 0 1
R0 = 1 .
D.2 = /T0- 0 -
"1" 12 .
"0" 0 .
D.1 = 1.0 - 0 - r 1.
D.0 = 0.0 - 0 - r 0.
8h - L: 0 - . 0 -
r 8 .
8h - L1: 1 - . 1 -
r 8 .
8h - : 0 - . 0 -
r 8 .
8Dh - 1: 1 - . 1 -
r 8 .
90h - 1: 1. 1 .
98h-SCON: Serial Port Control Register

SM0 SCON.7 0 bit.


SM1 SCON.6. 1 bit
SM2 SCON.5 Enables the multiprocessor communication feature in Modes 2 and 3. In Mode 2 or 3, if
SM2 is set to 1,
then RI will not be activated if the received 9th data bit (RB8) is 0. In Mode 1, if SM2 = 1, then RI will not
be activated if a valid stop bit was not received. In Mode 0, SM2 should be 0.
REN SCON.4 Enables serial reception. Set by software to enable reception. Clear by software to disable
reception.
TB8 SCON.3 The 9th data bit that will be transmitted in Modes 2 and 3. Set or clear by software.
RB8 SCON.2 In Modes 2 and 3, the 9th data bit that was received. In Mode 1, if SM2 = 0, RB8 is the
stop bit that was
received. In Mode 0, RB8 is not used.
TI SCON.1 Transmit interrupt flag. Set by hardware at the end of the 8th bit time in Mode 0, or at the
beginning of the
stop bit in the other modes, in any serial transmission. Must be cleared by software.
RI SCON.0 Receive interrupt flag. Set by hardware at the end of the 8th bit time in Mode 0, or halfway
through the
stop bit time in the other modes, in any serial reception (except see SM2). Must be cleared by software.

99h - SUF: Sril uffr. . SUF-


SUF- .
0 - 2: 2.


Microcontroller Instruction Set
8951- .
() .
.
( ) 8 .
. SFR, 128
.
: V 80h, 80h
, 0-
.
.
.


.
.
8 .
16 . 16
DR (Dt itr) .
.

,

. Y
R0-R7 . 8
3
1
5 3
( R-R7 ).
SW RS, RS1
.
: DD ,R7 1
1 (R7
).
.
.
.
.

.
.
.

: V ,#100 100
. 100
. 64h
.
.
.
. 16 (DR
rgrm utr )
. ,

.
"s jum" .
"jum"
.

.

.
1. .
2. .
3. .
4. .
5. .
. .
<bt>
.

: DD ,<bt> 4
. .
DD ,7Fh ( )
DD ,@R ( )
DD ,R6 ( )
DD ,#29h ( )

12 z- .
1 . IN DR 2,
4 .
-
, .
Dt itr 16
.
UL (16
) .
DIV r
, .
D D .
D DD DD D
. D D
. D 2 D
D , DD
DD .

. .

. : 00110101, <bt> 01010011
NL ,<bt> ( )
? 00010001 .
rr .

.
.
.

r
rv v r v
.

2A

2B

2C

2D

2E

ACC

MOV A,2Eh

00

12

34

56

78

78

MOV 2Eh,2Dh

00

12

34

56

56

78

MOV 2Dh,2Ch

00

12

34

34

56

78

MOV 2Ch,2Bh

00

12

12

34

56

78

MOV 2Bh,#00h

00

00

12

34

56

78

2A

2B

2C

2D

2E

ACC

CLR A

00

12

34

56

78

00

XCH A,2Bh

00

00

34

56

78

12

XCH A,2Ch

00

00

12

56

78

34

XCH A,2Dh

00

00

12

34

78

56

XCH A,2Eh

00

00

12

34

56

78

14 , 9 .

9 , 5 .

.
.
. @Ri
R R1 . 16
DR , @DR . 16

2 .
8 . 2
,
.
12z- 2
.

.

V .

()

MOVX A,@Ri

@Ri-
.

MOVX @Ri,A

@Ri- .

16

MOVX A,@DPTR

@DPTR-
.

16

MOVX @DPTR,A

@DPTR-
.


( 3- ).
.
( ) .
128
.
. ,
. .

()

ANL

C,bit

C = C .AND. bit

ANL

C,/bit

C = C .AND. .NOT. bit

ORL

C,bit

C = C .OR. bit

ORL

C,/bit

C = C .OR. .NOT. bit

MOV C,bit

C = bit

MOV bit,C

bit = C

CLR

C=0

CLR

bit

bit = 0

SETB C

C=1

SETB bit

bit = 1

CPL

C = .NOT. C

CPL

bit

bit = .NOT. bit

JC

rel

C = 1 .

JNC

rel

C = 0 .

JB

bit,rel

bit = 1 .

JNB

bit,rel

bit = 0 .

JBC

bit,rel

bit = 1 bit = 0 .

. J .
SJ, J, LJ 3 .
J 3
.
r .

()

JMP

addr

addr .

JMP

@A+DPTR

A+DPTR .

CALL addr

addr
.

RET

RETI


.
. 8 128-aac +127 .


()

JZ

rel

=0 .

JNZ

rel

0 .

DJNZ <byte>,rel

<byte>-
0-
.

CJNE A,<byte>,rel

<byte>-
.

CJNE <byte>,#data,rel

<byte> #data-
.



3.1.
1.7- D7
,
. 1.7- 0 ,
1 . CLR P1.7 ( 0 )
SETB P1.7 ( 1 ) 1
0 , 0 1 complement
.
;
ORG 0H
.
ON_RST:
CPL P1.7
.

;
;. . RESET

;1.7-

..

; .
ACALL DELAYHS ;
.
; 11.0592MHz

; uC - 153600

;
;.

AJMP ON_RST
;ON_RST .
DELAYHS:
; .
MOV R6,#00H
;R6- 00 .
MOV R7,#02H
;R7- 02 .
LOOPB:ACALL DELAYMS ;1mS

;.2562 512 .
DJNZ R6,LOOPB ;R6- 00

DJNZ R7,LOOPB

;LOOPB .00
;R7- 00

RET
.
DELAYMS:
MOV R5,#00H
LOOPA:NOP
.
DJNZ R5,LOOPA

RET
END

;LOOPB .00
; .
; RET
;1mS
;R6- 00 .
; 1
;R5- 00
;LOOPA .00
; .
; END-

.
00
FFH . .
256 .

3.2.
1-
. .
;
ORG 0H
ON_RST:
MOV A,#0FEH
.
LOOP:
MOV P1,A
.
RL A

;ACC- FEH 11111110B ()

;- 1- 1.0 0 D0
;- 11111101B
; 0 . 7-

; 0- P1.0 1
.
; .
ACALL DELAYHS ;
.
AJMP LOOP
; - 1-
LOOP
; .

. -
FEH 01 00000001 D0 ,
. .
.
. ,
.
3.3
ORG 0H
ON_RST:
MOV A,#0FEH
.
DO_NEXT:
MOV R4,#8H
.
LOOP:
MOV P1,A
.
RL A

;ACC- FEH 11111110B ()

;R4- 8

;- 1- 1.0 0 D0

;-
;
ACALL DELAYHS ;
.
DJNZ R4,LOOP
;R4- 1- 0
LOOP
; .
CPL A
;- ,
; .
AJMP DO_NEXT ; -

.
16- , B, C, D, E, F
0 . 0FEH
. FEH
.
. .

ORG 0H
ON_RST:
MOV A,#0FFH
CLR C
DO_NEXT:
MOV R4,#8H
LOOP:
MOV P1,A
RLC A
.7

;Carry flag 0 .

;- Carry flag-

; C flag- C- .0- .
CPL C
;C flag- .
ACALL DELAYHS ;
.
DJNZ R4,LOOP
;R4- 1- 0
LOOP
; .
CPL C
;C flag- .
AJMP DO_NEXT ; .

.


.
.

+5V

R1- R7
JP1

P3.3
P3.4
P3.5
PB1

A
B
C
D
E
F
G

A
B
C
D
E
F
G

CA

1
3
5
7
9
11
13
15
17
19

D2 LED7SEG

CA

PB2

2
4
6
8
10
12
14
16
18
20

D1 LED7SEG

220
P1.7
P1.6
P1.5
P1.4
P1.3
P1.2
P1.1
P1.0
P3.7

HEADER M

R8

10K

R9
Q1
PNP

10K

Q2
PNP

+5V

3.2. 7

3.2- 7 2 uC-
. 7
Common Anode . +5V
PNP ABCDEFG
220 uC- .
0 .
7 -
3.4, 3.5 0
. D1 4
1- 10011000B 98 3.4- 0 .
3.5 1 . D2
1- 3.5 1 .


.
.

3.4 0-F 16-


16- 0-F
.
CA1
CA2

EQU P3.4
EQU P3.5

;3.4- 1 .
;3.5- 2 .

ORG 0H
ON_RST:
MOV DPTR, #TABLE
DPTR
CLR CA1
.
SETB CA2
MOV A,#0H
NEXT_D:
PUSH ACC
MOVC A,@A+DPTR
-

MOV P1,A
POP ACC

; .
;
; .
;0 .
;- .
;DPTR-

; -

; 7

; .
;
; .
;-

ACALL DELAYHS
INC A
CJNE A,#10H,NEXT_D
NEXT_D
AJMP ON_RST
TABLE:

; .
;
;.
;-
; .
;- 10-

; .
; .
;0-FH 16- 7
;

;.

DB
2H,9EH,24H,0CH,98H,48H,40H,1EH,0H,08H,10H,0C0H,62H,84H,60H,70H
uC-
.
.
.

3.5 00-FFH 256



. 2 .

org 0h
;RESET .
ajmp on_rst
;On_rst .
;0BH /

; . (Timer Interrupt vector address)


org 0bh
clr ie.1
;
; .
acall disp
;

; disp .
setb ie.1
;

;
.
reti
; .
on_rst:
;RST
.
clr p3.5
; .
setb p3.4
; .
mov ie,#82h
;

;.
mov tmod,#01h
; 16 .
; -
; .
mov th0,#0dch
;0- DC00 10000HDC00H=2400H
mov tl0,#00h ; 9216 INT
;. - 100 .
; - 50

;.
setb tcon.4
;
;.
mov r0,#0h
;R0- .

next:
acall delayhs ;
inc r0
;R0- .
ajmp next
; .
; - 100

disp: mov dptr, #table


;DPTR- .
mov a,r0
;- R0- .
jb p3.5,scnd_d
; 3.5=1 .
swap a
; -

; .
scnd_d:
anl a,#0fh
;
.
movc a,@a+dptr
; - .
mov p1,#0ffh ;1- .
cpl p3.4
; .
cpl p3.5
mov p1,a
; 1- .
ret
; .
table:db 2h,9eh,24h,0ch,98h,48h,40h,1eh,0h,08h,10h,0c0h,62h,84h,60h,70h
3.6 2:
(RAM) 0 3
1
.
org 0h
main:
mov r1,#20h
;r1 20h
mov @r1,#2h
;r1
2h
;
inc r1
;r1

mov @r1,#9eh
inc r1
;r1 1
mov @r1,#24h
inc r1
mov @r1,#0ch
U1

6
7
8
9
11

XTAL1

XTAL2

RST

P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.7

AT89C2051

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7

P3.0/RXD
P3.1/TXD

12
13
14
15
16
17
18
19

2
3

mov r1,#20h ;r1 20h 20h

loop:
mov p1,@r1 ; 1
inc r1
acall delayhs ;
cjne r1,#24h,loop
;r1 24 loop
mov r1,#20h ; r1 20h
ajmp loop
;loop

3:
0 3
.
org 0h
mov r1,#00h ;r1 00h
mov dptr,#30h ; 30h dptr
main:
mov a,r1
;r1 a
movc a,@a+dptr ; a 0 30h 2h
a
; a 1 31h 9eh
a
mov p1,a
;a 1
acall delayhs
inc r1
cjne r1,#24h,main
mov r1,#00h
ajmp main
org 30h
;
db 2h,9eh,24h,0ch
;
(FLASH ROM) .



serial .
1
Mov

,
D1

1
6
7
8
9
11

XTAL1

XTAL2

RST
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.7
AT89C2051

D2

D3

D4

D5

D6

D7

D8

LED-GREEN
LED-GREEN
LED-GREEN
LED-GREEN
LED-GREEN
LED-GREEN
LED-GREEN
LED-GREEN

U1

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7

P3.0/RXD
P3.1/TXD

12
13
14
15
16
17
18
19

2
3

2
jb , 1. mov
mov a,p1 ; 1 a
mov r1,p2 ; 2 r1

4:
org 0h
main:
mov a,p3 ; 3
mov p1,a ; a 3 1
ajmp main
;
end
3 led
.
at89c2051 3 7 3.6 .
3.6 1.6 .
. 1. jb
.
. jb p3.2,loop
3.2 loop .
jnb p3.2,loop 3.2 loop
.
. Jnb acc.3 ,loop ;
3 .
111110111 loop .
0 7 .
5:
p3.2 1.7 led .
.
Org 0h
Main:
Jb p3.2,loop
Clr p1.7

;
;main
; ( ) loop
; ( a) Clr p1.7 led

.
Ajm main
Loop:
Setb p1.7
Ajmp main
End

;main
;
; led
;main
;

6:
p3.2 p3.3


.
org 0h
;
on_rst:
;on_rst
mov dptr, #table
; dptr
;
mov a,#0h
;a 0h
next_d:
push acc
;a
movc a,@a+dptr
;a a+dptr

mov p1,a
; 1
pop acc
;
acall delayhs
;
jb p3.2,no_bit
; ( ) no_bit
inc a
; ( a) a
;.
ajmp buttom
; buttom
no_bit:
jb p3.3,no_bit1
; ( ) no_bit1
dec a
; ( a) a
;
no_bit1:
buttom:
cjne a,#0ffh,loop1 ; 00h
0ffh
;a 0ffh loop1

mov a,#09h
;09h
ajmp next_d
; next_d .
loop1:
cjne a,#0ah,next_d ; 0h next_d

ajmp on_rst
; on_rst .
End
; .
U1

6
7
8
9
11

XTAL1

XTAL2

RST

P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.7

AT89C2051

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7

P3.0/RXD
P3.1/TXD

12
13
14
15
16
17
18
19

2
3


AT89C51,AT89C2051 3 HZ 24 MHZ
.
11.0592 MHZ .
1/12 clock .
11.0592 MHZ
. clock 11.0592 MHZ /12 =
921600 HZ 1/921600 MHZ=1.085069
.
AT89C51,AT89C2051 16 0 1 .
0 TH0 TL0 .
1 TH1 TL1 .

.
p3.4 (T0) p3.5(T1)
.
.
(TMOD)
0 1
. 3. 4
1
4 0 .
- GATE 1 p3.3(/INT1) SETB TR1 1
. 0
p3.3(/INT1) .
- 1 1 p3.5(T1)
. 0
.
-
-
- GATE 1 p3.2(/INT0) SETB TR0 0
. 0
p3.2(/INT0) .
- 1 0 p3.4(T0)
. 0
.
-
-

3
1 0

M1 M0

0
0
0
13
1
0
1
16
2
1
0
8
3
1
1
split
3
1
1
/ 1
16 0 65535

4
. .
7:
0 16 0,07111s
.
(1/921600HZ)*65536=0.07111s

Org 0h
Main:

;
Mov tmod,#00000001b

; 0 16

Setb tr0

Wait:
Jnb tf0,$
;
tf0 1.
Clr tf0
;tf0 0
.
Cpl p1.7
; p1.7 1 0 0 1
Ajmp wait
;wait
End
;
:
p1.7 .
Org 0h
;

Main:
mov r0,#100
; 0.01 100
; r0 100
;
mov tmod,#00000001b
; 0 16
;
mov th0,#0dch
; 0 16 dc00h ( 56320)

mov tl0,#00h
; 56320 65536
9216
;
0,01 .
Setb tr0
;
Wait:
Jnb tf0,$
;
tf0 1.
Clr tf0
;tf0 0
.
mov th0,#0dch
;
mov tl0,#00h
djnz r0,wait
; r0 0

mov r0,#100
;r0 100
Cpl p1.7
; p1.7 1 0 0 1
Ajmp wait
;wait
End
;

:
p3.2 (/INT0) 0
.
Org 0h
;
Main:
Mov tmod,#00001001b
; 0 16

;GATE 0

;
Setb tr0
;
Wait:
Jnb tf0,$
;
tf0 1.

Clr tf0
;tf0 0
.
Cpl p1.7
; p1.7 1 0 0 1
Ajmp wait
;wait
End
;

.
10:
p3.4 (T0) 16 p1.7
led .
Org 0h
U1
Main:
R1
mov tmod,#00000101b ; 0 16
D1
C^T
; 1

;
5

6
7
8
9
11

XTAL1

XTAL2

RST

P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.7

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7

P3.0/RXD
P3.1/TXD

12
13
14
15
16
17
18
19

150R

LED-YELLOW

2
3

AT89C2051

mov th0,#0ffh ;0fff0h ( 65520 ) 0


mov tl0,#0f0h
; .
Setb tr0
;
Wait:
Jnb tf0,$
1.
Clr tf0
mov th0,#0ffh
mov tl0,#0f0h
Cpl p1.7
Ajmp wait
End

; tf0

; p1.7 1 0 0 1
;wait
;

/ (TCON)


.

- 1 0 1
1 .
- 1 1
1 0 .
- 0 0 0
1 .
- 0 1
0 0 .
- 1 .
- 0 1 (1 0
) IE1 .
- 1 .
- 0 1 (1 0
) IE0 .
5
:
p3.2(INT0)
p1.7 0 .
Org 0h
Main:
clr it0
;
clr ie0
;
setb ie.7
;
setb ie.0
; 0
Wait:
Jnb ie0,$
;
clr p1.7
; p1.7 0
Ajmp wait
;
End




reti
.

.
AT89C51 AT89C2051

, ,
.

AT89C51
AT89C52 .
1- p3.2(INT0)
it0
ie0 1
ex0
(External interrupt 0) .
2- 0 tf0
et0
(timr 0) .
5- TI RI es
(serial port)
.
(IE)
.
- 0
.
1

-
- 2 (AT89C52) .
-
- 1
- 1
- 0
- 0


0 ie0
0003h
.

11 p3.2(INT0)
p1.7 0 .
Org 0h
Main:
clr it0
;
clr ie0
;
;-------------------------------setb ie.7
;
setb ie.0
; 0
;-------------------------------Wait:
Jnb ie0,$
;
clr p1.7
; p1.7 0
Ajmp wait
;
End
13:
p3.2(INT0) 0003h
p1.7 0 .
LED equ P1.7
; p1.7 led
org 0h
;
ajmp on_rst
;on_rst
org 0003h
;
clr LED
reti
org 20h
on_rst:
MOV IE,#81H

wait:
nop
ajmp wait
end

;p1.7 0
;
;
;on_rst
;ea 0

;
;wait
;

:
60 ,

.

org 0000h
ajmp on_rst
org 000bh

mov th0,#0dch
mov tl0,#00h
56320)

;
;on_rst
; 0

U1
19

18

XTAL1

XTAL2

RST

P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15

; 0 16
;dc00h
(
;
; 56320

;
U2:B
U2:A
65536 9216
;
; 0,01 .
Clr tf0
; 0
acall disp
;disp
reti
;
on_rst:
clr p3.4
; .
setb p3.5
;
mov tmod,#00000001b
; 0 16
mov ie,#10000010b ; 0
mov th0,#0dch
mov tl0,#00h
mov tcon,#00010000b; 0
mov r0,#100
;0,01 100 1
100
mov r1,#00h
;
00
mov r2,#00h
;
00
mov dptr,#table
;table dptr
Wait:
Jnb tf0,$
;0,01
djnz r0,wait
;r0 0 wait

mov r0,#100
; 1
inc r1
;1 r1

;
Ajmp wait
disp:
29
30
31

7404

7404

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7

AT89C51

1
2
3
4
5
6
7
8

PSEN
ALE
EA

P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD

39
38
37
36
35
34
33
32
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17

mov a,r1

;4 a

jb p3.5,led_4
;3.5 4
mov a,r2
;p3.5 3

;
a
led_4:
movc a,@a+dptr
; @a+dptr
a
cjne r1,#0ah,loop
; 0-9 9

mov r1,#00h
; 0
inc r2
; 3
cjne r2,#06h,loop
;5
mov r2,#00h
; 0
loop:
mov p1,#0ffh
;1
cpl p3.4
;


cpl p3.5
mov p1,a
;
ret
;
table: db 2h,9eh,24h,0ch,98h,48h,40h,1eh,0h,08h ;
end
;
15:



U1

19

18

org 0000h
ajmp on_rst
org 000bh
mov th0,#0dch
mov tl0,#00h
clr tf0
return:
mov p3,a
rl a
mov r7,a
acall disp
mov a,r7

7404

7404

XTAL2

RST

PSEN
ALE
EA

U2:B

7404

U2:C

7404

U2:D

29
30
31
U2:A

13

12

XTAL1

1
2
3
4
5
6
7
8

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
AT89C51

P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7

P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15

P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD

39
38
37
36
35
34
33
32

21
22
23
24
25
26
27
28

10
11
12
13
14
15
16
17

D2

LED-RED

D1

LED-RED

reti
on_rst:
mov a,#0feh
mov ie,#82h
mov tmod,#01h
mov th0,#0dch
mov tl0,#00h
setb tcon.4
mov r0,#00h
mov r1,#00h
mov r2,#10
mov r3,#60
mov r4,#100
mov r5,#00h
mov r6,#00h
wait:
jnb p3.7,buttom_1
jnb p3.6,buttom_2
;-------------------------------jnb tf0,$
djnz r4,wait
mov r4,#100
djnz r3,wait
mov r3,#60
;--------------------------------;------------inc r0
cjne r0,#0ah,wait
mov r0,#00h
;------------inc r1
cjne r1,#06h,wait
mov r1,#00h
;------------cjne r5,#02h,loop2
inc r6
;------------cjne r6,#04h,wait
ajmp loop1
loop2:
inc r6
cjne r6,#0ah,wait
mov r6,#00h
inc r5
cjne r5,#02h,wait
ajmp wait
loop1:
mov r6,#00h
mov r5,#00h

ajmp wait
;----------------------disp:
cjne r4,#50,halfs
cpl p2.7
halfs:
cjne r4,#100,halfs1
cpl p2.7
halfs1:
jnb p3.5,label4
jnb p3.4,label3
jnb p3.3,label2
jnb p3.2,label1
ajmp return
label4:
mov dptr,#table
mov a,r0
movc a,@a+dptr
mov p1,a
ret
label3:
mov dptr,#table
mov a,r1
movc a,@a+dptr
mov p1,a
ret
label2:
mov dptr,#table
mov a,r6
movc a,@a+dptr
mov p1,a
ret
label1:
mov dptr,#table
mov a,r5
movc a,@a+dptr
mov p1,a
ret
buttom_2:
acall delay
inc r0
cjne r0,#0ah,wait
mov r0,#00h
inc r1
cjne r1,#06h,wait
mov r1,#00h
ajmp buttom_2
buttom_1:
acall delay

cjne r5,#02h,loop2
inc r6
cjne r6,#04h,buttom_jmp
ajmp loop1
buttom_jmp:
ljmp wait
;-------------------------delay:
Jnb tf0,$
Clr tf0
djnz r2,delay
mov r2,#10
ret
table:
db 2h,9eh,24h,0ch,98h,48h,40h,1eh,0h,08h
end


pc pc
. .
, TV, PC
.
C,C++,JAVA,LABWIVE ,PASCAL
.
PC COM1 COM2 .
6 PC
.
3- TXD (transmitted data) . 2- RXD(received
data) . 5- .
DTE(data
terminal equipment) PC,SERVER,MAIN
PRAME,WORKSTASION DCE(data communication equipment)
MODEM
.
6

1. DCE Received line signal detector

2. DCE Received data


3. DTE Transmitted data
4. DTE DTE ready
5. - Ground
6. DCE DCE ready
7. DTE Request to send
8. DCE Clear to send
9. DCE Ring indicator

7 UART


.
8

1 1
1 (parity bit)
10
1 . TTL +5v
1 0v 0 RS232 -3v
1 +3v 0 . 8
TTL RS232
(Level converter) max232
. 01000010 .


start >accessories>communications>HyperTerminal
HyperTerminal file
icon ok connect
using COM1 COM2
ok bit per second
. Data bits
. Parity
none .stop bit
. Flow control ok
.
.
PC
.



SBUF .

SBUF
.
41H TXD

MOV A,#41H ;a
MOV SBUF,A ;a SBUF TXD
PC
SBUF . PC
a .
MOV A,SBUF

;RXT a

You might also like