;move a servo with ADC on a 12f675
list P=12f675
#include <p12f675.inc>
__config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF
ERRORLEVEL -302
cblock 20h
servotime, servotime2, pulse, pulse2, pulseb, timer1, timer2, timer3
endc
bsf STATUS,RP0 ;bank 1
movlw 0x38
movwf ANSEL
movlw 0x1c
movwf TRISIO ;set I/O
bcf STATUS,RP0
movlw 0x07 ;turn off comparitors
movwf CMCON
start
movlw 0x09
movwf ADCON0
bsf ADCON0,1
waiting2
btfsc ADCON0,1
goto waiting2
movf ADRESH,0
movwf pulseb
movlw 0x0d
movwf ADCON0
bsf ADCON0,1
waiting
btfsc ADCON0,1
goto waiting
movf ADRESH,0
movwf pulse
movlw 0xfa
movwf pulse2
servo
bsf GPIO,5
decfsz pulse2,1 ;turn first on and wait for 1ms
goto servo
servo2
nop
nop
nop
nop
nop
decfsz pulse,1 ;count down to make value
goto servo2 ;between 1 and 2 ms
bcf GPIO,5
movlw 0xfa
movwf pulse2
servob
bsf GPIO,1 ;turn second on and wait for 1ms
decfsz pulse2,1
goto servob
servo3
nop
nop
nop
nop
nop
decfsz pulseb,1 ;leave on for between 1-3ms
goto servo3
bcf GPIO,1
call pause
goto start
pause
movlw 0xff ;wait for the rest of the 18k to pass
movwf timer2
movlw 0x12
movwf timer1
decfsz timer1,1
goto $-1
decfsz timer2,1
goto $-5
return
end