Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Here is a general question> Suppose now I want to turn a servo motor first 45 degree and stay there for 2 second then come back to zero?
is it possible?
Yes, easily possible, and simple to do.
Of course. Or without. Whatever works for what you want to do.Is it possible using interrupt?
list p=16F877 ; list directive to define processor
#include <p16F877.inc> ; processor specific variable definitions
errorlevel -302
cblock 20h
d1
d2
endc
org 0h
nop
bsf STATUS,RP0
bcf STATUS,RP1
movlw 0x0
movwf TRISB
movlw 0x0
movwf TRISC
movlw 0x0
movwf TRISD
bcf STATUS,RP0
bcf STATUS,RP1
nop
start
movlw b'11111111'
movwf PORTB
movlw b'11111111'
movwf PORTC
movlw b'11111111'
movwf PORTD
call Delay1ms200us
movlw b'11111000'
movwf PORTB
call Delay450us
movlw b'00000000'
movwf PORTB
movlw b'10000000'
movwf PORTC
call Delay250us
movlw 0x0
movwf PORTC
movlw 0x0
movwf PORTD
call Delay18ms100us
goto start
Delay450us
;2243 cycles
movlw 0xC0
movwf d1
movlw 0x02
movwf d2
Delay450us_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay450us_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
Delay1ms200us
;5993 cycles
movlw 0xAE
movwf d1
movlw 0x05
movwf d2
Delay1ms200us_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay1ms200us_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
Delay250us
;1243 cycles
movlw 0xF8
movwf d1
movlw 0x01
movwf d2
Delay250us_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay250us_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
Delay18ms100us
;90493 cycles
movlw 0xB2
movwf d1
movlw 0x47
movwf d2
Delay18ms100us_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay18ms100us_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
END
How are your servos wired? Can you post a simple schematic of even just one servo and how you have it all connected.When I test the code in real life nothing happen to the servo? Any idea why?
#include <p16F877.inc>
errorlevel -302
cblock 0x20
d1,d2
endc
org 0x000
banksel TRISB ;bank 1
clrf TRISB
clrf TRISC
clrf TRISD
banksel PORTB ;bank 0
start movlw b'11111111'
movwf PORTB
movwf PORTC
movwf PORTD
call Delay1ms200us
movlw b'11111000'
movwf PORTB
call Delay450us
crf PORTB
movlw b'10000000'
movwf PORTC
call Delay250us
clrf PORTC
clrf PORTD
call Delay18ms100us
goto start
Delay450us
movlw 0xC0
movwf d1
movlw 0x02
movwf d2
Delay450us_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay450us_0
goto $+1
nop
return
Delay1ms200us
movlw 0xAE
movwf d1
movlw 0x05
movwf d2
Delay1ms200us_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay1ms200us_0
goto $+1
nop
return
Delay250us
movlw 0xF8
movwf d1
movlw 0x01
movwf d2
Delay250us_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay250us_0
goto $+1
nop
return
Delay18ms100us
movlw 0xB2
movwf d1
movlw 0x47
movwf d2
Delay18ms100us_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay18ms100us_0
goto $+1
nop
return
END
i need programming in pic 16f877