基于单片机的8路抢答器的设计

MOV R5,30H ; 取十位 MOV R4,31H ; 取个位 MOV A,R6 CLR C SUBB A,#07H

JNC LARGER ;大于5s跳到LARGER,小于等于5s会提醒 MOV A,R0

CJNE A,#0AH,FULL;1s CLR RING AJMP CHECK

FULL: CJNE A,#14H,CHECK ; 1s SETB RING MOV A,R6

JZ QUIT ; MOV R0,#00H

DEC R6 ; AJMP CHECK LARGER: MOV A,R0

CJNE A,#14H,CHECK ; DEC R6; MOV R0,#00H

CHECK: JNB P3.1,QUIT; ACALL DISPLAY JNB P1.0,TRUE1

JNB P1.2,TRUE3 JNB P1.3,TRUE4 JNB P1.4,TRUE5 JNB P1.5,TRUE6 JNB P1.6,TRUE7

中0.5s向下运行 时,响并显示号数并清R0,重新计时 计时完毕 一秒标志减1 如果1s向下运行,否者跳到查\停/显示\计时一秒R6自动减1 如按下停止键退出 JNB P1.1,TRUE2

- 12 -

JNB P1.7,TRUE8 AJMP RECOUNT

QUIT: CLR OK ; 如果按下了\停止键\重新回到开始 CLR RING ACALL BARK AJMP START 正常抢答处理程序:

TRUE1: ACALL BARK; 按键发声 MOV A,R2

MOV R6,A; 抢答时间R2送R6 MOV R3,#01H CLR OK; AJMP LOOP2 TRUE2:ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#02H CLR OK AJMP LOOP2 TRUE3:ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#03H CLR OK AJMP LOOP2 TRUE4:ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#04H CLR OK

- 13 -

AJMP LOOP2 TRUE5: ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#05H CLR OK AJMP LOOP2 TRUE6: ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#06H CLR OK AJMP LOOP2 TRUE7: ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#07H CLR OK AJMP LOOP2 TRUE8: ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#08H CLR OK

LOOP2: AJMP DISPLAY ;SETB RING

JNB P3.1 QUIT AJMP LOOP2 犯规抢答程序:

ERROR: SETB RING ;

抢答后停止计时,等待返回犯规响铃

- 14 -

MOV R5,#0BH

MOV R4,#0BH; 显示FF和犯规号数 LOOP3: ACALL DISPLAY

JNB P3.1 QUIT1; 等待“停止”键按下 AJMP LOOP3 QUIT1: CLR RING CLR OK AJMP START 显示程序:

DISPLAY:MOV DPTR,#DAT1; 查表显示程序,利用P0口做段选码口输出/P2低三位

做位选码输出

MOV A,R5 MOVC A,@A+DPTR MOV P2,#01H MOV P0,A ACALL DELAY MOV DPTR,#DAT2 MOV A,R4 MOVC A,@A+DPTR MOV P2,#02H

MOV P0,A ACALL DELAY MOV A,R3 MOVC A,@A+DPTR MOV P2,#04H

MOV P0,A ACALL DELAY RET

DAT1:DB 00H,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,00H,71H ;\灭\灭\

- 15 -

联系客服:779662525#qq.com(#替换为@)