;---------------8255 & sensors-------------------- ctrl55 equ 0x5f pa55 equ 0x5e pb55 equ 0x5d pc55 equ 0x5c pcbit equ 0x5b ; cny70 equ 0x55 ;store sensor's status tdl70 equ 0x54 ;sensor hold delay time ; a0_8255 equ p2.0 a1_8255 equ p2.1 ;============================================================================== org 00h mov p1,#0xff ;if p1=>8 leds ; sensor: mov ctrl55,#0x82 ;pa:output(lcm),pb:input,pc:output call wr_ctrl scan_y70: mov cny70,#0 ;initial sensor=0 ;front ;74139=>q0=0 mov pcbit,#6 ;pc6=0 call cl_pc mov pcbit,#7 ;pc7=0 call cl_pc call y70_dl call rd_pb ;read pb,data store at pb55 call data_pro ;data processing ;back ;74139=>q1=0 mov pcbit,#6 ;pc6=1 call st_pc mov pcbit,#7 ;pc7=0 call cl_pc call y70_dl call rd_pb ;read pb,data store at pb55 call data_pro ;data processing ;left ;74139=>q2=0 mov pcbit,#6 ;pc6=0 call cl_pc mov pcbit,#7 ;pc7=1 call st_pc call y70_dl call rd_pb ;read pb,data store to pb55 call data_pro ;data processing ;right ;74139=>q3=0 mov pcbit,#6 ;pc6=1 call st_pc mov pcbit,#7 ;pc7=1 call st_pc call y70_dl call rd_pb ;read pb,data store to pb55 call data_pro ;data processing ; jmp scan_y70 ;---------------data processing data_pro: anl pb55,#0f0h ;pb4-pb7 mov cny70,pb55 ;store to cny70 mov p1,cny70 ;display sensors status ret ;---------------sensor hold delay time y70_dl: mov tdl70,#20 djnz tdl70,$ ret ;================================================================================= ;***************write data to control register wr_ctrl: ;ctrl register select=11 setb a0_8255 setb a1_8255 mov a,ctrl55 movx @r0,a ;wr signal ret ;***************output data to 8255@pa wr_pa: ;pa register select=00 clr a0_8255 clr a1_8255 mov a,pa55 movx @r0,a ;wr signal ret ;***************input data from 8255@pb rd_pb: ;pb register select=01 setb a0_8255 clr a1_8255 movx a,@r0 ;rd signal mov pb55,a ret ;**************output data to 8255@pc by single-bit model st_pc: ;pc register select=10 setb a0_8255 ;ctrl register select=11 setb a1_8255 mov a,pcbit setb c rlc a movx @r0,a ;wr signal ret ; cl_pc: setb a0_8255 ;ctrl register select=11 setb a1_8255 mov a,pcbit clr c rlc a movx @r0,a ;wr signal ret ; end