DAT2:DB 3FH, 06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,00H,71H DELAY1: MOV 35H,#08H LOOP0: ACALL DISPLAY DJNZ 35H,LOOP0 RET
延时(显示和去抖动用到): DELAY: MOV 32H,#12H LOOP: MOV 33H,#0AFH LOOP1: DJNZ 33H,LOOP1 DJNZ 32H,LOOP RET 发声程序:
BARK: SETB RING ACALL DELAY1 ACALL DELAY1 CLR RING; 按键发声 RET
INT0(抢答时间R1调整程序): INT0SUB:MOV A,R1 MOV B,#0AH DIV AB MOV R5,A MOV R4,B MOV R3,#0AH
ACALL DISPLAY;先在两个时间LED上显示R1 JNB P3.2,INC0; P3.2为+1s键,如按下跳到INCO JNB P3.3,DEC0; P3.3为-1s键,如按下跳到DECO JNB P3.4,BACK0; P3.4为确定键,如按下跳到BACKO AJMP INT0SUB INC0: MOV A,R1
- 16 -
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
TO溢出中断(响铃程序): T0INT:MOV TH0,#0ECH MOV TL0,#0FFH JNB RING,OUT
CPL P3.6 ; RING标志位为1时候P3.6口不短取反使喇叭
发出一定频率的声音
OUT: RETI
T1溢出中断(计时程序): T1INT: MOV TH1,#3CH MOV TL1,#0B0H INC R0 RETI END
- 17 -