;**************************************************** ;Nano Driver Stepper Motor Demo Code ;Authors: Dale Kubin & Nathan Scherdin ;Code demos how to control a stepper motor with ;direction change based on the state of a pin. ;**************************************************** Speed Var Word Pot Var Word ENABLE1 CON P12 ENABLE2 CON P11 OUTA = 0 DIRA = 0 ; Sets Pin P0-P3 to outputs and low High Enable1 ;Turn L293 On High Enable2 Pot = 0 ;Clear the variable POT Speed = 3 ;Set Stepper Motor Speed Main If IN8 = 1 Then ;If P8 high goto ForwardMtr, if P8 low ReverseMtr Gosub ForwardMtr Else Gosub ReverseMtr Endif Goto Main ;In ForwardMtr and ReverseMtr loops we set all 4 control pins at the same time. ;This makes the stepper motor run smoother. Using the OUTA command which addresses ;the first Nib (P3,P2,P1,P0). ForwardMtr OUTA = %0101 ; OUTA address P3,P2,P1,P0 as nibble. Pause Speed OUTA = %0110 Pause Speed OUTA = %1010 Pause Speed OUTA = %1001 Pause Speed Return ReverseMtr OUTA = %1010 Pause Speed OUTA = %0110 Pause Speed OUTA = %0101 Pause Speed OUTA = %1001 Pause Speed Return