设8051的定时器T0作定时作用,已知时钟频率为6MHz,试编程由P1.0和P1.1分别输出周期为2ms和500ms的方波。

2024-12-17 10:50:41
推荐回答(1个)
回答1:

ORG 0000H
LJMP START
ORG 000BH
LJMP Timer0Interrupt

START:
MOV SP,#60H
LCALL InitTimer0

LOOP:
;add your code here!
LJMP LOOP

InitTimer0:
MOV TMOD,#00H
MOV TH0,#1CH
MOV TL0,#18H
SETB EA
SETB ET0
SETB TR0
RET

Timer0Interrupt:
PUSH DPH
PUSH DPL
PUSH ACC
MOV TH0,#1CH
MOV TL0,#18H
setb rs0
setb rs1
;========================
cpl p1.0
inc r6
cjne r6,#250,T0_EXIT
cpl p1.1
mov r6,#0
;========================
T0_EXIT:
POP ACC
POP DPL
POP DPH
RETI

END