买作品:51单片机盒制作简易门铃控制系统
TIME EQU 30H
FREQH EQU 31H
FREQL EQU 32H
HIBIT BIT 00H
LIBIT BIT 01H
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR
ORG 001BH
LJMP T1ISR
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#11H
MOV TH1,#3CH ;T1定时器50ms
MOV TL1,#0B0H
MOV TIME,#0
CLR HIBIT
CLR LIBIT
SETB ET1
SETB ET0
SETB EA
LOOP:
JB P22.2,LOOP ;等待按键
LCALL DELAY ;延时去抖
JB P2.2,LOOP ;再次判键
LOOP0:
MOV FREQH,#0FEH ;1K频率初值
MOV FREQL,#0CH
SETB TR0 ;开定时器0
SETB TR1 ;开定时器1
JNB HIBIT,$ ;等待100ms结束
MOV FREQH,#0FCH ;500Hz频率初值
MOV FREQL,#18H
SETB TR0
SETB TR1
JNB LIBIT,$ ;等待200ms结束
MOV TIME,#0
JNB P2.2,LOOP0 ;键如果未抬起则继续
CLR TR0 ;键抬起则关闭定时器
CLR TR1
CLR HIBIT
CLR LIBIT
MOV TIME,#0
SJMP LOOP
;-----------------------------
T1ISR:
CLR TR1
MOV TH1,#3CH
MOV TL1,#0B0H
SETB TR1
INC TIME
CJNE A,#2,T1ISR1
SETB HIBIT
SJMP T1ISRE
T1ISR1:
CJNE A,#6,T1ISRE
SETB LIBIT
T1ISRE:
RETI
;-----------------------------
T0ISR:
CLR TR0
MOV TH0,FREQH
MOV TL0,FREQL
SETB TR0
CPL P2.0
RETI
;-----------------------------
DELAY: ;10ms延时
MOV R3,#40
DELAY1:
MOV R4,#125
DJNZ R4,$
DJNZ R3,DELAY1
RET
;-----------------------------
END
2024-11-14 广告