LIST p=16f628A
include "p16f628A.inc"
__CONFIG _CP_OFF & _DATA_CP_OFF &_LVP_OFF & _BOREN_OFF &_MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT
ERRORLEVEL -302
cblock 0x20
d0
d1
d2
count
endc
ORG 0x0000
movlw 0x07 ;like 16f84
movwf CMCON
Initialization
banksel TRISB ;select bank 1
movlw b'00000000'
movwf TRISB ;Make TRISB all outputs
movwf TRISA ;Make TRISA all outputs
banksel PORTB ;Select Bank 0
clrf PORTA
clrf PORTB
Start
;--------------------------------------------------------------------
movlw 0x64
Movwf Count ;allow travel time and hold
Zero
bsf PORTB,2
call Delay1.25 ;Pulse on for 1.25mS, 0 position
bcf PORTB,2
call Delay20 ;Pause for 20mS (servo's expect it)
decfsz count
goto Zero
movlw 0x64
Movwf Count ;allow travel time and hold
Ninety
bsf PORTB,2
call Delay1.5 ;Pulse on for 1.5mS, 90 position
bcf PORTB,2
call Delay20 ;Pause for 20mS (servo's expect it)
decfsz count
goto Ninety
movlw 0x64
Movwf Count ;allow travel time and hold
One_eighty
bsf PORTB,2
call Delay1.75 ;Pulse on for 1.75mS, 180 position
bcf PORTB,2
call Delay20 ;Pause for 20mS (servo's expect it)
decfsz count
goto One_eighty
goto Start
;--------------------------------------------------------------------
Delay1.5 ;0.0015 seconds
movlw 0xF1
movwf d0
movlw 0x02
movwf d1
loop1.5
decfsz d0, f
goto loop1.5
decfsz d1, f
goto loop1.5
; Rest = 2 Cycles
goto $+1
RETLW 0x00
;---------------------
Delay20 ;0.02 seconds
movlw 0xF8
movwf d0
movlw 0x1A
movwf d1
loop20
decfsz d0, f
goto loop20
decfsz d1, f
goto loop20
; Rest = 1 Cycles
nop
RETLW 0x00
;---------------------
Delay1.25 ;0.00125 seconds
movlw 0x9E
movwf d0
movlw 0x02
movwf d1
loop1.25
decfsz d0, f
goto loop1.25
decfsz d1, f
goto loop1.25
; Rest = 1 Cycles
nop
RETLW 0x00
;---------------------
Delay1.75 ;0.00175 seconds
movlw 0x44
movwf d0
movlw 0x03
movwf d1
loop1.75
decfsz d0, f
goto loop1.75
decfsz d1, f
goto loop1.75
; Rest = 1 Cycles
nop
RETLW 0x00
;-----------------------------------------------
END