15路抢答器程序
扫描二维码
随时随地手机看文章
BeepBITP2.3
LED1EQU08H
LED2EQU09H
LED3EQU0AH
LED4EQU0BH
LedT0EQU0CH;0-3轮流点亮4个数据管
ORG0000H
LJMPSTART;转入主程序
ORG000BH
;=================================================
;定时器0中断入口
INT_TO:
PUSHACC
PUSHPSW
CLRTF0;清定时0中断标志
MOVTH0,#0F6H;2.5MS
MOVTL0,#03DH;
MOVA,#11110000B;关数码管
ORLP2,A
MOVA,LedT0
CJNEA,#0,INT_T0_1
MOVA,LED1
MOVCA,@A+DPTR
MOVP0,A
CLRP2.7
MOVLedT0,#1
LJMPINT_T0_END
INT_T0_1:
MOVA,LedT0
CJNEA,#1,INT_T0_2
MOVA,LED2
MOVCA,@A+DPTR
MOVP0,A
CLRP2.6
MOVLedT0,#2
LJMPINT_T0_END
INT_T0_2:
MOVA,LedT0
CJNEA,#2,INT_T0_3
MOVA,LED3
MOVCA,@A+DPTR
MOVP0,A
CLRP2.5
MOVLedT0,#3
LJMPINT_T0_END
INT_T0_3:
MOVA,LED4
MOVCA,@A+DPTR
MOVP0,A
CLRP2.4
MOVLedT0,#0
LJMPINT_T0_END
INT_T0_END:
POPPSW
POPACC
RETI
;=============================================
START:
MOVSP,#60H
MOVTMOD,#01H;设定T0为十六位定时模式。
MOVTH0,#0F6H;2.5MS
MOVTL0,#03DH;
SETBTR0;开定时器0
SETBET0;致能定时0中断
CLRTF0;清定时0中断标志
SETBEA;开总中断
MOVLedT0,#00H
MOVDPTR,#TABLE
MOVLED1,#10H
MOVLED2,#10H
MOVLED3,#10H
MOVLED4,#10H
;=============================================
SCAN:
;按键扫描
JNBP3.2,KEY_SW1
JNBP3.3,KEY_SW2
JNBP3.4,KEY_SW3
JNBP3.5,KEY_SW4
LJMPSCAN
;=============================================
KEY_SW1:
LCALLDELAY_10MS;去抖动
JBP3.2,SCAN
MOVLED3,#0H
MOVLED4,#01
CLRP1.0;点亮LED
CLRBeep
CALLDELAY_100MS
SETBBeep
CALLDELAY_2S
MOVLED3,#10H
MOVLED4,#10H
SETBP1.0
JMPSCAN
;=============================================
KEY_SW2:
LCALLDELAY_10MS;去抖动
JBP3.3,SCAN
MOVLED3,#0H
MOVLED4,#02
CLRP1.1;点亮LED
CLRBeep
CALLDELAY_100MS
SETBBeep
CALLDELAY_2S
MOVLED3,#10H
MOVLED4,#10H
SETBP1.1
JMPSCAN
;=============================================
KEY_SW3:
LCALLDELAY_10MS;去抖动
JBP3.4,SCAN
MOVLED3,#0H
MOVLED4,#03
CLRP1.2;点亮LED
CLRBeep
CALLDELAY_100MS
SETBBeep
CALLDELAY_2S
MOVLED3,#10H
MOVLED4,#10H
SETBP1.2
JMPSCAN
;=============================================
KEY_SW4:
LCALLDELAY_10MS;去抖动
JBP3.5,SCAN
MOVLED3,#0H
MOVLED4,#04
CLRP1.3;点亮LED
CLRBeep
CALLDELAY_100MS
SETBBeep
CALLDELAY_2S
MOVLED3,#10H
MOVLED4,#10H
SETBP1.3
JMPSCAN
;=============================================
DELAY_2S:
MOVR3,#200
JMPDELAY10MS
DELAY_100MS:
MOVR3,#10
JMPDELAY10MS
DELAY_10MS:
MOVR3,#1
;=============================
DELAY10MS:
MOVR4,#20
DELAY10MSA:
MOVR5,#247
DJNZR5,$
DJNZR4,DELAY10MSA
DJNZR3,DELAY10MS
RET
;=============================================
TABLE:
DB00101000B;0
DB11101011B;1
DB00110010B;2
DB10100010B;3
DB11100001B;4
DB10100100B;5
DB00100100B;6
DB11101010B;7
DB00100000B;8
DB10100000B;9
DB01100000B;A
DB00100101B;b
DB00111100B;C
DB00100011B;d
DB00110100B;E
DB01110100B;F
DB11110111B;-
DB11111111B;
END