Yes, exactly!
By the way, you seem to have your TRIS settings backwards, a set bit makes the pin an input, a cleared bit makes it an output.
I haven't actually tested the following so please see it as an overall idea and not verified/working code:
Code:
DEFINE OSC 4
StepCount VAR WORD ' Distance to move
Delay VAR WORD ' Time, in us, between each step-pulse
i VAR WORD ' General purpose index/counter variable
But VAR PortB.2
Dir_Pin VAR PortB.4
Step_Pin VAR PortB.5
CW CON 0
CCW CON 1
CMCON = 7
ANSEL = 0
TRISB = %11001111 ' PortB4-5 outputs, rest are inputs.
Main:
If But = 0 THEN
StepCount = 200 ' Distance to move motor
Delay = 2000 ' 2000us between each step
Dir_Pin = CCW
Gosub MoveMotor
ENDIF
Goto Main
END
MoveMotor:
For i = 0 to (StepCount - 1)
Gosub StepIt
PauseUs Delay
NEXT
RETURN
StepIt:
Step_Pin = 1 ' Generate a 10us wide pulse on the step pin.
PauseUs 10
Step_Pin = 0
RETURN
/Henrik.
Bookmarks