qb_0007:
单片机六人抢答器定时器0定时50ms循环20次完成定时一秒;用串行口做显示输出外部抢答按钮用防抖开关用中断做的键盘扫描.P1.0做灯光报警P1.1做声音报警ORG 0000HAJMP MAINORG 0003H 定义外部0中断AJMP INT0SEVORG 000BH 定义定时器0中断AJMP T0SEV ORG 0030HMAIN:MOV SP, #60HMOV TMOD,#01H定义定时器T0的工作模式MOV TH0,,#3CH 给定时器赋初值MOV TL0 ,#0B0HMOV R2 , #20循环次数MOV R3 , #0个位显示MOV R4 , #3十位显示SETB EA开总中断SETB ET0开定时器中断SETB P0.0给p0.0赋初值LCALL XIANSHI调用显示子程序CLR P1.0JB P0.0 , $LCAII K3SETB P1.0开始按钮SETB IT0边沿触发方式SETB TR0开启定时器SETB EX0开启外部中断JB P0.1 , $AJMP MAIN定时中断T0SEV:MOV th0 , #3CHMOV TL0 , #0B0HDJNZ R2 , LOOPMOV R2 , #20CJNE R3 , #0 , K1CJNE R4 , #0 , K2CLR TR0CLR EACLR ET0CLR EX0AJMP LOOPK2:MOV R3 , #9DEC R4AJMP LOOPK1:DEC R3LOOP:LCALL XIANSHIRETI外部中断服务INT0SEV:CLR EACLR TR0JNB P0.2, KEY1JNB P0.3, KEY2JNB P0.4, KEY3JNB P0.5, KEY4JNB P0.6, KEY5JNB P0.7, KEY6KEY1:MOV R3 , #1MOV R4 , #0LCALL XIANSHIRETIKEY2:MOV R3 , #2MOV R4 , #0LCALL XIANSHIRETIKEY3:MOV R3 , #3MOV R4 , #0LCALL XIANSHIRETIKEY4:MOV R3 , #4MOV R4 , #0LCALL XIANSHIRETIKEY5:MOV R3 , #5MOV R4 , #0LCALL XIANSHIRETIKEY6:MOV R3 , #6MOV R4 , #0LCALL XIANSHIRETI显示子程序:XIANSHI:MOV SCON , #00HMOV DPTR ,#TABMOV A ,R3MOVC A , @A+DPTRMOV SBUF ,AJNB TI , $CLR TIMOV A ,R4MOVC A , @A+DPTRMOV SBUF ,AJNB TI , $CLR TIRET声音报警K3:MOV R5 ,#50K4:MOV R6 ,#FFHK5:DJNZ R6 , K5CPL P1.1DJNZ R5 , K4RETEND