If you are using a single phase (single winding) DC motor, then connect it across pins 3 and 6 of the L293D (as in the DATASHEET for the L293D).
Then all you have to do is drive pin 2 HIGH and pin 7 LOW for the motor to turn one way, and reverse it with pin 2 LOW and pin 7 HIGH for the motor to turn the other way (subject of course to you turning pin 1 ENABLE HIGH).
For Fast Motor Stop, Drive both Inputs LOW, or Drive both Inputs HIGH or Drive ENABLE pin LOW.
It's all in the DATASHEET.
Done, dusted, simple. So what's all this playing with PICs Registers for?
...it needs to run in one direction for 3 seconds, then stop for 1 second and then run in the opposite direction for 3 seconds again.
Enable var PortB.0 ' Enable Pin 1
DriveA var PortB.1 ' Drive Pin 2
DriveB var PortB.2 ' Drive pin 7
TRISB=%11111000
Loop:
Gosub AllStop
Pause 1000
Gosub RunOneWay
Pause 3000
Gosub AllStop
Pause 1000
Gosub RunOtherWay
Pause 3000
Goto Loop
AllStop:
Low Enable
Low DriveA
Low DriveB
Return
RunOneWay:
High DriveA
Low DriveB
High Enable
Return
RunOtherWay:
Low DriveA
High DriveB
High Enable
Return
End
Bookmarks