方波频率为12KHz,则周期为1/12ms,高电平时长0.75/12ms=62.5us,约63us,低电平时长0.25/12ms,约21us
假设晶振频率为12MHz
COUNT_INT EQU 30H
ORG 0000H
LJMP START
ORG 000BH
LJMP Timer0Interrupt
START:
MOV SP,#60H
LCALL InitTimer0
SETB P1.0 ;初始化 高电平输出
MOV COUNT_INT,#0
LOOP:
LJMP LOOP
InitTimer0:
MOV TMOD,#01H
MOV TH0,#0FFH;定时21us
MOV TL0,#0EBH
SETB EA
SETB ET0
SETB TR0
RET
Timer0Interrupt:
PUSH DPH
PUSH DPL
PUSH ACC
MOV TH0,#0FFH
MOV TL0,#0EBH
INC COUNT_INT
MOV A,COUNT_INT
CJNE A,#3,T0INT_NOTEQU3
CLR P1.0 ;开始低电平输出
AJMP T0INT_EXIT
T0INT_NOTEQU3:
CJNE A,#4,T0INT_EXIT
MOV COUNT_INT,#0
SETB P1.0;开始高电平输出
; AJMP T0INT_EXIT
T0INT_EXIT:
POP ACC
POP DPL
POP DPH
RETI
END