; STEP_1.ASM
;
; Controls a stepping motor driver on lower four bits of Port B.  
;
; (Typical drivers might include a ULN2803 Octal Driver, 2N2222 or TIP122
; transistors or power FETs.  See Parallel Port Manual - Vol 1).
; 
; INDEX is incremented from 0 to 7 and then back to 0.  INDEX is mapped
; into a stepping motor pattern using the RETLW lookup technique and the
; pattern is output.  This is followed by a delay.  The duration of the 
; delay controls the speed of the stepper.
;
; copyright, LaQuiesia Smith, MSU, March '97
;

	LIST P=PIC16C84

	__CONFIG 11h
#include <c:\mplab\P16C84.INC>

INDEX	EQU 0CH

LOOP1	EQU 10H
LOOP2	EQU 11H

	ORG 000H

	BCF STATUS, RP1		; bank 1
	BSF STATUS, RP0
	CLRF TRISB		; all bits on PORTB outputs
	BCF STATUS, RP0

INIT_INDEX
	CLRF INDEX		; start INDEX at zero
	
GEN_PATT:
     	MOVF INDEX, W		; copy count into w
	CALL PATT		; returns the correct pattern in w
	MOVWF PORTB		; output PATT to PORTB
	
	CALL DELAY		; 25 msecs between patterns
	INCF INDEX, F		; increment INDEX to next pattern
	
	MOVF INDEX, W
	SUBLW 	.8		; INDEX - 8
	BTFSC	STATUS, Z	; if Z = 0, not zero and skip next
	GOTO	INIT_INDEX	; if Z=1
	GOTO	GEN_PATT

PATT:
	ADDWF	PCL, F		; add w to the program counter
	
	RETLW	01H		; stepping motor patterns
	RETLW	03H
	RETLW	02H

	RETLW	06H
	RETLW	04H
	RETLW	0CH
	RETLW	08H	
	
DELAY:				; provides nominal 25 msec delay
	MOVLW	.25
	MOVWF 	LOOP1
OUTTER:
	MOVLW	.110
	MOVWF 	LOOP2
INNER:
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	DECFSZ	LOOP2, F
	GOTO INNER
	DECFSZ 	LOOP1, F
	GOTO OUTTER
	RETURN

	END