單片機(jī)搶答器設(shè)計(jì)
;=====查詢程序=====
START: MOV R5,#0BH
MOV R4,#0BH
MOV R3,#0BH
ACALL DISPLAY ;未開始搶答時(shí)候顯示FFF
JB P1.0,NEXT ;ddddddd
ACALL DELAY
JB P1.0,NEXT ;去抖動(dòng),如果"開始鍵"按下就向下執(zhí)行,否者跳到非法搶答查詢
ACALL BARK ;按鍵發(fā)聲
MOV A,R1
MOV R6,A ;送R1->R6,因?yàn)镽1中保存了搶答時(shí)間
SETB OK ;搶答標(biāo)志位,用于COUNT只程序中判斷是否查詢搶答
MOV R3,0AH ;搶答只顯示計(jì)時(shí),滅號(hào)數(shù)
AJMP COUNT ;進(jìn)入倒計(jì)時(shí)程序,"查詢有效搶答的程序"在COUNT里面
NEXT: JNB P1.1,FALSE1
JNB P1.2,FALSE2
JNB P1.3,FALSE3
JNB P1.4,FALSE4
JNB P1.5,FALSE5
JNB P1.6,FALSE6
AJMP START
;=====非法搶答處理程序=====
FALSE1: ACALL BARK ;按鍵發(fā)聲
MOV R3,#01H
AJMP ERROR
FALSE2: ACALL BARK
MOV R3,#02H
AJMP ERROR
FALSE3: ACALL BARK
MOV R3,#03H
AJMP ERROR
FALSE4: ACALL BARK
MOV R3,#04H
AJMP ERROR
FALSE5: ACALL BARK
MOV R3,#05H
AJMP ERROR
FALSE6: ACALL BARK
MOV R3,#06H
AJMP ERROR
;=====INT0(搶答時(shí)間R1調(diào)整程序)=====
INT0SUB:MOV A,R1
MOV B,#0AH
DIV AB
MOV R5,A
MOV R4,B
MOV R3,#0AH
ACALL DISPLAY ;先在兩個(gè)時(shí)間LED上顯示R1
JNB P3.4,INC0 ;P3.4為+1s鍵,如按下跳到INCO
JNB P3.5,DEC0 ;P3.5為-1s鍵,如按下跳到DECO
JNB P1.7,BACK0 ;P3.1為確定鍵,如按下跳到BACKO
AJMP INT0SUB
INC0: MOV A,R1
CJNE A,#63H,ADD0 ;如果不是99,R2加1,如果加到99了,R1就置0,重新加起。
MOV R1,#00H
ACALL DELAY1
AJMP INT0SUB
ADD0: INC R1
ACALL DELAY1
AJMP INT0SUB
DEC0: MOV A,R1
JZ SETR1 ;如果R1為0, R1就置99,
DEC R1
ACALL DELAY1
AJMP INT0SUB
SETR1: MOV R1,#63H
ACALL DELAY1
AJMP INT0SUB
BACK0: RETI
;=====INT1(回答時(shí)間R2調(diào)整程序)=====
INT1SUB:
MOV A,R2
MOV B,#0AH
DIV AB
MOV R5,A
MOV R4,B
MOV R3,#0AH
ACALL DISPLAY
JNB P3.4,INC1
JNB P3.5,DEC1
JNB P1.7,BACK1
AJMP INT1SUB
INC1: MOV A,R2
CJNE A,#63H,ADD1
MOV R2,#00H
ACALL DELAY1
AJMP INT1SUB
ADD1: INC R2
ACALL DELAY1
AJMP INT1SUB
DEC1: MOV A,R2
JZ SETR2
DEC R2
ACALL DELAY1
AJMP INT1SUB
SETR2: MOV R2,#63H
ACALL DELAY1
AJMP INT1SUB
BACK1: RETI
;=====倒計(jì)時(shí)程序(搶答倒計(jì)時(shí)和回答倒計(jì)時(shí)都跳到改程序)=====
COUNT: MOV R0,#00H ;重置定時(shí)器中斷次數(shù)
MOV TH1,#3CH
MOV TL1,#0B0H ;重置定時(shí)器
RECOUNT:
MOV A,R6 ;R6保存了倒計(jì)時(shí)的時(shí)間,之前先將搶答時(shí)間或回答時(shí)間給R6
MOV B,#0AH
DIV AB ;除十分出個(gè)位/十位
MOV 30H,A ;十位存于(30H)
MOV 31H,B ;個(gè)位存于(31H)
MOV R5,30H ;取十位
MOV R4,31H ;取個(gè)位
MOV A,R6
SUBB A,#07H
JNC LARGER ;大于5s跳到LARGER,小于等于5s會(huì)提醒
MOV A,R0
CJNE A,#0AH,FULL;1s中0.5s向下運(yùn)行
CLR RING
AJMP CHECK
FULL: CJNE A,#14H,CHECK;下面系1s的情況,響并顯示號(hào)數(shù)并清R0,重新計(jì)
SETB RING
MOV A,R6
JZ QUIT ;計(jì)時(shí)完畢
MOV R0,#00H
DEC R6 ;一秒標(biāo)志減1
AJMP CHECK
LARGER:
MOV A,R0
CJNE A,#14H,CHECK;如果1s向下運(yùn)行,否者跳到查"停/顯示"
DEC R6 ;計(jì)時(shí)一秒R6自動(dòng)減1
MOV R0,#00H
CHECK: JNB P1.7,QUIT ;如按下停止鍵退出
ACALL DISPLAY
JB OK,ACCOUT ;如果是搶答倒計(jì)時(shí),如是則查詢搶答,否者跳過查詢繼續(xù)倒數(shù)(這里起到鎖搶答作用)
AJMP RECOUNT
ACCOUT:JNB P1.1,TRUE1
JNB P1.2,TRUE2
JNB P1.3,TRUE3
JNB P1.4,TRUE4
JNB P1.5,TRUE5
JNB P1.6,TRUE5
AJMP RECOUNT
QUIT: CLR OK ;如果按下了"停止鍵"執(zhí)行的程序
CLR RING
AJMP START
評(píng)論