有晶振频率为6MHz的MCS-51单片机,使用定时器0以定时方法在P1.0输出周期为400딀s,

占空比10%的方波脉冲,以查询或中断工作方式编程实现
2024-12-29 02:52:02
推荐回答(2个)
回答1:

ORG 00H

AJMP MAIN

ORG 0BH

AJMP T0INT

ORG 30H

MAIN:

ACALL T0INIT

AJMP $

T0INIT:

MOV TMOD,#01H

MOV TH0,#0FFH

MOV TL0,#058H             

SETB EA

SETB ET0

SETB TR0

RET

T0INT:

JB P1.0,SW_1

SETB P1.0

SW_9:

MOV TH0,#0FFH

MOV TL0,#58H             ;358us

AJMP RTI

SW_1:

CLR P1.0

MOV TH0,#0FFH             ;42us

MOV TL0,#0F7H

RTI:

RETI

END

回答2:

;下列程序经过仿真试验,符合题目要求.

ORG 0000H
SJMP START
ORG 000BH
CLR P1.0
DJNZ R2, T0_END
MOV R2, #10
SETB P1.0
T0_END:
RETI
START:
MOV TMOD, #02H
MOV TH0, #(256 - 20) ;定时40us
MOV TL0, #(256 - 20)
SETB TR0
MOV IE, #82H
MOV R2, #10
SJMP $

END