
motor_up:	bit p1.0  ;M1 and M2 is motor polarity
motor_down:	bit p1.1
top_limit:	bit p1.2  ;TLS=top limit switch
bottom_limit:	bit p1.3  ;BLS=bottom limit switch
start_Button:	bit p1.4


cycle_motor:

        clr Motor_up ;make sure motor is off
	clr Motor_down

$check_position
        jb bottom_limit,$set_position  ;make sure motor in pos.
$start	
	jb start_button,$up  ;wait for start button to be pushed
	jmp $start

$up	setb motor_up ;motor is at bottom
	jb top_limit,$up ;wait until reach top limit    
	clr motor_up ;stop motor from moving up
	setb motor_down ;start motor moving down

$down	jb bottom_limit,$down ;wait untill reach bottom limit
	clr motor_down
        ret ;operation is complete

;if motor not at bottom limit, set to be bottom limit and 
; jump to wait for start button
        
$set_position
        setb motor_down
$wait   jb bottom_limit,$wait ;wait untill reach bottom limit
	clr motor_down
        jmp $start	
end


