; STEP_2.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
;
; Updated to include calls to LCD_CTRL.ASM to display INDEX and PATT on
; serial LCD.  Note #include  at bottom of program.
; Uses PORTA, Bit 1 to interface to serial LCD.
;
; Peter H. Anderson, MSU, June 14, '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:
	CALL LCD_CLR		; clear the LCD	
     	MOVF INDEX, W		; copy count into w

	CALL LCD_LINE1
	CALL LCD_VAL		; display INDEX on line1

	CALL PATT		; returns the correct pattern in w

	CALL LCD_LINE2		
	CALL LCD_VAL		; display PATT on line 2

	MOVWF PORTB		; output PATT to PORTB
	
	CALL DELAY		; 250 msecs to see the LCD
	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 250 msec delay
	MOVLW	.250
	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

#include <A:\LCD_CTRL.ASM>

	END