|
源程序: ORG 0000H AJMP MAIN ORG 0003H AJMP DET1 ;远探测器 ORG 0013H AJMP DET0 ;近探测器 ORG 0050HMAIN: MOV P0, #00000001B ;置初始值DET0,DET1可重复触发,灯灭 MOV TMOD, #00000010B ;方式2,8位自动重装计数器 MOV TCON, #00010000B ;开启计数器T0 MOV IE, #10000111B ;开启所有中断 SJMP $;灯慢慢变亮DET1: MOV P0, #00000001B CALL TIME0 ;灯亮度延时10ms MOV P0, #00000011B CALL TIME0 MOV P0, #00000101B CALL TIME0 MOV P0, #00000111B CALL TIME0 MOV P0, #00001001B CALL TIME0 MOV P0, #00001011B CALL TIME0 MOV P0, #00001101B CALL TIME0 MOV P0, #00001111B CALL TIME1 RETI;灯慢慢熄灭DET0: CALL TIME1 ;延时1分钟 MOV TCON, A ANL A, #1 JZ LOOP MOV P0, #00001111B CALL TIME0 MOV P0, #00001101B CALL TIME0 MOV P0, #00001011B CALL TIME0 MOV P0, #00001001B CALL TIME0 MOV P0, #00000111B CALL TIME0 MOV P0, #00000101B CALL TIME0 MOV P0, #00000011B CALL TIME0 MOV P0, #00000001B RETILOOP: ret;延时10msTIME0: SETB TR0 MOV R0, #250 MOV R1, #20D_1: DJNZ R0, D_1 MOV R0, #250 DJNZ R1, D_1 CLR TR0 RET;延时1分钟TIME1: SETB TR0 MOV R0, #250 MOV R1, #200 MOV R2, #60D_2 : DJNZ R0, D_2 MOV R1, #200 DJNZ R1, D_2 MOV R2, #60 DJNZ R2, D_2 CLR TR0 RET END |
|