Skip to content

Instantly share code, notes, and snippets.

@skydevht
Last active September 23, 2019 20:20
Show Gist options
  • Save skydevht/7728144079ab0ed0ba23f641ddb0878e to your computer and use it in GitHub Desktop.
Save skydevht/7728144079ab0ed0ba23f641ddb0878e to your computer and use it in GitHub Desktop.
mov tmod, #10h ; set timer 1 to 16bit
verif:
mov p2, #0ffh ; set p2 as input
mov acc, p2; read p2 into the acc
jb 0e4h, ll; jump if first bit of sensor 1 is not set (empty)
anl acc, #41h; isolate s and sensor 1 bits
xrl acc, #41h ; acc will clear if s and sensor 1 first bit is set
jz lm1 ; jump if acc is zero
jmp verif; loop verification
ll:
clr p1.0 ; light warning led
jmp verif ; loop verification
lm1:
clr p1.4 ; launch motor 1
jnb p2.5, f1 ; jump if clapet is not on
jnb p2.2, $; loop until sensor 2 says it's at least 1/4
clr p1.5 ;launch motor 2 if clapet is on
f1:
jb p2.0, $ ; loop until sensor 1 says empty
setb p1.4 ; stop motor 1
mov r0, #10 ; 5 seconds (5 * 20)
call secondsDelay ; delaying
setb p1.5 ; stop motor 2
jnb p2.7, $ ; loop until a is set
mov r7, #2; 2 cycle
clean:
clr p1.7 ; open pump
checkEmpty:
mov acc, p2 ; load port 2
anl acc, #0fh ; isolate sensor 1 & 2
xrl acc, #0fh ; clear if all is set
jnz checkEmpty; loop until full
setb p1.7 ; close pump
clr p1.4; start motor 1
clr p1.5 ; start motor 2
mov r0, #10 ; 3 seconds (3 * 20)
call secondsDelay
setb p1.4 ; stop motor 1
setb p1.4 ; stop motor 2
djnz r7, clean
jmp finish
; Setup Timer
fiftyMsDelay:
clr tr1 ; stop timer
; set up a 50 000 seconds delay by loading 65 536 - 50 000 = 15 536 (3CB0)
mov th1, #3ch
mov tl1, #0b0h
setb tr1 ; start timer
jnb tf1, $ ; loop until timer oveflow
clr tf1 ; clear overflow
clr tr1 ; stop timer
ret
secondsDelay:
; save processor state
push psw
loopTimer:
call fiftyMsDelay ; 50 ms
djnz r0, loopTimer ; loop until r0 equal zero
; restore processor state
pop psw
ret
finish:
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment