Hi, Glenn
This one Should run
Code:
@ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_ON,PROTECT_OFF
DEFINE OSC 4
CMCON = 7 ' Disable comparators
PORTA = %00000011
PORTB = 0
TRISA = %00000011
TRISB = 0
'Use b1 to hold pulse width variable for servo 1
b1 var byte
'initialize variables
b1 = 150
low portb.0 ' put the servoport low.
main:
low portb.0
pulsout portb.0, b1 'send current servo 1 position out
if porta.0 = 0 then left1 'check for pressed switch 0
if porta.1 = 0 then right1 'check for pressed switch 1
bugtrap:
if b1 > 150 then
b1 = b1 - 1
else
if b1 < 150 then b1 = b1 + 1
endif
pause 18 : goto main
left1:
IF porta.1 = 0 Then bugtrap
b1 = b1 + 1
if b1 > 199 then max1
Pause 8 : goto main
right1:
IF Porta.0 = 0 Then bugtrap
b1 = b1 - 1
if b1 < 100 then min1
Pause 8 : goto main
max1: b1 = 100 : goto main ; jump to other side
min1: b1 = 200 : goto main ; jump to other side
END
and do not forget : courtesy SKI !!!
Alain
Bookmarks