Turn off analog comparators so your pins can be used for digital I/O.
CMCON = 7
PULSOUT toggles the pin twice, so the initial state of the pin determines
the logic of the pulse.
LOW 0 ' We want a high-going pulse or low-high-low with pulsout.
Code:
@ DEVICE MCLR_OFF,INTRC_OSC,WDT_OFF,PROTECT_OFF
Define OSCCAL_1K 1 ' Load factory value into OSCCAL
CMCON = 7 ' Turn analog comparators off
X VAR BYTE
LOW 0 ' Setup GPIO,0 to output a high-going pulse with pulsout
Main:
FOR X = 1 to 50
pulsout 0, 100
pause 15
NEXT X
pause 1000
FOR X = 1 to 50
pulsout 0, 200
pause 15
NEXT X
pause 1000
goto Main
end
You may want to tweak the pulsout periods, but that should get you started.
Make sure you use a separate power supply for your servo. Using the same PS as the PIC will cause problems.
Bookmarks