'jleblanc 10.29.05: from tigoe basic servo control
'this just turns a servo in one direction and then resets it
'written to work with a 20mhz clock

DEFINE OSC 20

start:
    pulseWidth VAR BYTE
    ' set up constants with the minimum and maximum pulsewidths
    'NOTE: change these according to your servo. trial and error works
    minPulse CON 20
    maxPulse CON 230
    ' set up a constant with the time between pulses:
    refreshPeriod CON 20
    'this adjusts our pulse out period depending on what speed clock
    'we use. The code is default for 4mHZ in which case clkadj should
    'be 1. Since a 20mhZ runs 5 times as fast when using a 20mhz clock
    'clkadj must be set to 5
    clkadjust CON 5
    
    ' set an initial pulsewidth:
    pulseWidth = minPulse

main:
    'take the output pin low so we can pulse it high
    LOW PORTD.2
    ' pulse the pin Here we multiply by 
    PULSOUT PORTD.2, pulseWidth*clkadjust
    ' pause for as long as needed:
    PAUSE refreshPeriod
    
    ' change the angle for the next time around:
    IF pulseWidth > maxPulse THEN
        pulseWidth = minPulse
    ELSE    
        pulseWidth = pulseWidth + 1
    ENDIF
    
GOTO main