15路搶答器程序
BeepBITP2.3
LED1EQU08H
LED2EQU09H
LED3EQU0AH
LED4EQU0BH
LedT0EQU0CH;0-3輪流點亮4個數(shù)據(jù)管
ORG0000H
LJMPSTART;轉(zhuǎn)入主程序
ORG000BH
;=================================================
;定時器0中斷入口
INT_TO:
PUSHACC
PUSHPSW
CLRTF0;清定時0中斷標志
MOVTH0,#0F6H;2.5MS
MOVTL0,#03DH;
MOVA,#11110000B;關(guān)數(shù)碼管
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