单片机定时器的汇编语言程序编程

2024-11-18 18:21:39
推荐回答(3个)
回答1:

1、
ORG 0000H
AJMP MAIN
ORG 0100H
MAIN: MOV R2,#00H
MOV TMOD,#20H
MOV TH1,#231
MOV TL1,#231
SETB P1.2
SETB TR1
HERE: JNB TF1,HERE
PT_1: CJNE R2,#07H,PT11
SETB P1.2
MOV R2,#00H
CLR TF1
AJMP HERE
PT11: CLR P1.2
INC R2
CLR TF1
AJMP HERE
END
2、
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP IT_0
ORG 001BH
AJMP IT_1
ORG 0100H
MAIN: MOV TMOD,#51H
MOV TH1,#0FCH
MOV TL1,#18H
MOV IE,#10001010B
SETB TR1
SJMP $
IT_1: CLR TR1
MOV TH0,#0FCH
MOV TL0,#18H
SETB TR0
RETI
IT_0: CLR TR0
MOV TH1,#0FCH
MOV TL1,#18H
SETB TR1
RETI
END

回答2:

ORG 0000H
SJMP START
ORG 001BH
AJMP INT_TIMER1
ORG 0040H
START:
MOV TMOD,#20H
MOV TH1,#231
MOV TL1,#231
SETB ET1
SETB TR1
SETB EA
MOV P1,#00H
CLR A
SJMP $

INT_TIMER1:
JZ OUTOUT_HIGH
CLR P1.2
SJMP INC_A
OUTOUT_HIGH:
SETB P1.2
INC_A: INC A
CJNE A,#08H,SKIP_SET0
CLR A
SKIP_SET0:
RETI
END

回答3:

1、
ORG
0000H
AJMP
MAIN
ORG
0100H
MAIN:
MOV
R2,#00H
MOV
TMOD,#20H
MOV
TH1,#231
MOV
TL1,#231
SETB
P1.2
SETB
TR1
HERE:
JNB
TF1,HERE
PT_1:
CJNE
R2,#07H,PT11
SETB
P1.2
MOV
R2,#00H
CLR
TF1
AJMP
HERE
PT11:
CLR
P1.2
INC
R2
CLR
TF1
AJMP
HERE
END
2、
ORG
0000H
AJMP
MAIN
ORG
000BH
AJMP
IT_0
ORG
001BH
AJMP
IT_1
ORG
0100H
MAIN:
MOV
TMOD,#51H
MOV
TH1,#0FCH
MOV
TL1,#18H
MOV
IE,#10001010B
SETB
TR1
SJMP
$
IT_1:
CLR
TR1
MOV
TH0,#0FCH
MOV
TL0,#18H
SETB
TR0
RETI
IT_0:
CLR
TR0
MOV
TH1,#0FCH
MOV
TL1,#18H
SETB
TR1
RETI
END