'**************************************************************** '* Name : servo test.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 10/2/2005 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** 'the servo is on portc.3 DEFINE OSC 4 angleVar var word output PORTC.3 OUTPUT PORTd.2 output portd.3 OUTPUT PORTD.6 INPUT PORTB.7 ' set up constants with the min and max pulse widths minAngle con 110 maxAngle con 200 'set up a constant with the time between pulses refreshPeriod con 10 'set delay to keep servo in "open" state delayPeriod CON 2000 'set an initial pulsewidth: angleVar=minAngle LOW PORTC.3 toggleVar var bit main: ' listen for the switch IF PORTB.7=1 THEN toggleVar = 1 goto openGate ENDIF Goto main openGate: PulsOut portc.3, maxAngle HIGH PORTd.2 LOW PORTd.3 freqout PORTD.6, 10,10000 'pause for as long as needed: pause delayPeriod toggleVar=0 GOTO closeGate closeGate: PULSOUT PORTC.3, minAngle LOW PORTD.2 HIGH PORTd.3 'freqout PORTD.6, 500,250,400 pause refreshPeriod GOTO main