;Progam STEP_1.BAS

;This program continuosly turns a stepper motor in one direction. 

;copyright Locksley Haynes, Morgan State University, Oct. 5, 1997


;****************** Circuit Diagram *************************
;TICKit ------------------>  DRIVER (ULN 2803A)
;DATA_0 (term 31) --------> D0 (term 1) 
;DATA_1 (term 32) --------> D1 (term 2)
;DATA_2 (term 33) --------> D2 (term 3)
;DATA_3 (term 34) --------> D3 (term 4)

;DRIVER ------------------> MOTOR
;Q0 (term 18) ------------> PHI_0 
;Q1 (term 17) ------------> PHI_1 
;Q2 (term 16) ------------> PHI_2 
;Q3 (term 15) ------------> PHI_3 

;***************************************************************

DEF tic62_b       ;define TICkit device
LIB fbasic.lib    ;library for FBASIC  functions
LIB constrin.lib  ;library for console writing functions

;Initialize step pattern values
GLOBAL byte step_pattern [8]  1b 3b 2b 6b 4b 12b 8b 9b

;********************Main function****************************
FUNC none main
  LOCAL byte step_index 0b
BEGIN

   dtris_set(0b)   ;set data port direction register for output.

   REP
     dport_set(step_pattern[step_index])   ;output pattern to stepper
motor

     ++(step_index)                    ;increment to next pattern
     
     IF ==(step_index, 8b)              ;start over at first pattern
        =(step_index, 0b)
     ENDIF
   
     delay(50)
   LOOP
ENDFUN