XinHao EQU P1.0 Light EQU P2.0 ORG 0000H AJMP MAIN ------------------MAIN----------------- MAIN: CLR light ;初始时灯泡熄灭 Check: SETB XinHao JNB XinHao,yanshi ;检测是否有信号 LJMP Check yanshi: LCALLdelay ;延时防信号抖动 SETB XinHao JNB XinHao,dianliang ;有,点亮灯泡 LJMP Check -------------------dianliang-------------------- dianliang: SETB light ;点亮灯泡 LOOP: SETB XinHao JB XinHao,yanshi1 ;判断是否无信号 LJMP LOOP yanshi1: LCALLdelay ;延时防抖动 SETB XinHao JB XinHao,yanshi8 ;再次确定无信号 LJMP LOOP yanshi2: LCALL delay1 ;利用定时器延时两分钟 CLR light ;熄灭灯泡 RET --------------------delay------------------- Delay: MOV R0, #100 D1: MOV R1, #100 D2: DJNZ R1, D2 DJNZ R0, D1 RET ----------定时器延时两分钟---------- delay1: MOV R2, #180 MOV IE, #00H MOV TMOD, #01H SETB TR0 CLR TF0 LOOP0: MOV TL0, #0FH MOV TH0, #00H LOOP1: JBC TF0,LOOP2 ;定时是否溢出 JMP LOOP1 LOOP2: DJNZ R2, LOOP0 MOV TMOD, #00H CLR TR0 CLR TF0 RET ---------------------END--------------------- END
|