;; lab 7 ;; step motor controller ;; anders pearson and jason bessette ;; initialization org 1800h ld a,90h ; clear ports out (0c3h), a ; ld (1950h),88h ; use 1950h as delay in a,(0fc0h) ; read input bit into a ld (1951h),a ; this corresponds to "too slow" ;; do this for each revolution rev: ld f,00h ; clear our flag ;; do this for each sequence seq: ld b,32h ; 50 sequences of 4 half-steps call doseq ; output our bits dec b ; decrement our counter jp nz seq ; repeat sequence cmp f,01h ; check if the flag is set jp nz, nodec ; dec (1950h) ; decrease delay jp nz, rev ; infinite loop jp error ; delay's made it down to 0 nodec: inc (1950h) ; increase delay jp nz, rev ; infinite loop jp error ; went past FFh ;; subrouting that does a sequence of four half steps doseq: push bc ; push d ; ld b,11h ; 00010001 ld c,33h ; 00110011 ld d,04h ; do this four times hs: ld a,b ; b -> a and a,0fh ; mask out the high four out (0fc1h), a ; send it to the motor ld a,c ; c -> a and a,0fh ; mask out high four bits out (0fc1h), a ; send it to the motor in a, (0fc0h) ; read in speed bit cmp a,(1951h) ; compare to our slow bit jp nz pass ; if != skip ld f,01h ; set our flag pass: rl b ; rotate b left rl c ; rotate c left ld a,(1950h) ; delay call 0ffdh ; call delay function dec d ; decrement counter jp nz hs ; loop again pop d ; pop d off stack pop bc ; pop bc off stack ret ; return error: halt ; halt the system