list p=16f877a
#include <p16f877a.inc>
radix dec
; Compiled with: PIC Simulator IDE v6.85
; Microcontroller model: PIC16F877A
; Clock frequency: 4.0 MHz
;
; The address of 'leg1servo1' (bit) (global) is 0x6,7
; The address of 'leg1servo2' (bit) (global) is 0x6,6
; The address of 'leg1servo3' (bit) (global) is 0x6,5
; The value of 'midposition' (global) is 128
; The address of 'i' (byte) (global) is 0x2C
i EQU 0x2C
; Begin
R0L EQU 0x20
R0H EQU 0x21
R1L EQU 0x22
R1H EQU 0x23
R2L EQU 0x24
R2H EQU 0x25
R3L EQU 0x26
R3H EQU 0x27
R4L EQU 0x28
R4H EQU 0x29
R5L EQU 0x2A
R5H EQU 0x2B
ORG 0x0000
BCF PCLATH,3
BCF PCLATH,4
GOTO L0002
ORG 0x0004
RETFIE
; Begin of program
L0002:
; 1: Symbol leg1servo1 = PORTB.7 'J3 - Pin 28'
; 2: Symbol leg1servo2 = PORTB.6 'J4 - Pin 27'
; 3: Symbol leg1servo3 = PORTB.5 'J5 - Pin 26'
; 4:
; 5: Const midposition = 128 'Set mid position for servos'
; 6:
; 7:
; 8: AllDigital
BSF STATUS,RP0
MOVLW 0x06
MOVWF 0x1F
MOVLW 0x07
MOVWF 0x1C
; 9:
; 10: Config RA0 = Input
BSF TRISA,0
; 11: Config RA1 = Input
BSF TRISA,1
; 12: Config RA2 = Input
BSF TRISA,2
; 13: Config RA3 = Input
BSF TRISA,3
; 14: Config RA4 = Output
BCF TRISA,4
; 15: Config RA5 = Output
BCF TRISA,5
; 16:
; 17: Config PORTB = Output
CLRF TRISB
; 18:
; 19: Config PORTC = Output
CLRF TRISC
BCF STATUS,RP0
; 20:
; 21: Dim i As Byte
; 22:
; 23:
; 24:
; 25: Gosub centerservos
CALL L0001
; 26:
; 27: End
L0003: GOTO L0003
; 28:
; 29:
; 30:
; 31: 'Routine to centre all the servos'
; 32: centerservos:
L0001:
; 33: For i = 1 To 10
MOVLW 0x01
MOVWF 0x2C
L0004:
MOVF 0x2C,W
SUBLW 0x0A
BTFSS STATUS,C
GOTO L0005
; 34: ServoOut leg1servo1, midposition
MOVLW 0x80
MOVWF R4H
MOVF R4H,F
BTFSC STATUS,Z
GOTO L0007
BSF PORTB,7
L0006:
NOP
NOP
NOP
NOP
NOP
NOP
DECF R4H,F
BTFSS STATUS,Z
GOTO L0006
BCF PORTB,7
L0007:
; 35: ServoOut leg1servo2, midposition
MOVLW 0x80
MOVWF R4H
MOVF R4H,F
BTFSC STATUS,Z
GOTO L0009
BSF PORTB,6
L0008:
NOP
NOP
NOP
NOP
NOP
NOP
DECF R4H,F
BTFSS STATUS,Z
GOTO L0008
BCF PORTB,6
L0009:
; 36: ServoOut leg1servo3, midposition
MOVLW 0x80
MOVWF R4H
MOVF R4H,F
BTFSC STATUS,Z
GOTO L0011
BSF PORTB,5
L0010:
NOP
NOP
NOP
NOP
NOP
NOP
DECF R4H,F
BTFSS STATUS,Z
GOTO L0010
BCF PORTB,5
L0011:
; 37: Next i
MOVLW 0x01
ADDWF 0x2C,F
BTFSS STATUS,C
GOTO L0004
L0005:
; 38:
; 39: For i = 1 To 10
MOVLW 0x01
MOVWF 0x2C
L0012:
MOVF 0x2C,W
SUBLW 0x0A
BTFSS STATUS,C
GOTO L0013
[B]; 40: ASM: bsf PORTB,7
bsf PORTB,7
; 41: ASM: bsf PORTB,6
bsf PORTB,6
; 42: ASM: bsf PORTB,5
bsf PORTB,5
; 43: WaitMs 10
MOVLW 0x0A
MOVWF R0L
CLRF R0H
CALL W001
; 44: ASM: bcf PORTB,7
bcf PORTB,7
; 45: ASM: bcf PORTB,6
bcf PORTB,6
; 46: ASM: bcf PORTB,5
bcf PORTB,5
; 47: Next i
MOVLW 0x01
ADDWF 0x2C,F
BTFSS STATUS,C
GOTO L0012
L0013:
; 48: Return
RETURN
[/B]; End of program
L0014: GOTO L0014
; Waitms Routine
W001: MOVF R0L,F
BTFSC STATUS,Z
GOTO W002
CALL W003
DECF R0L,F
NOP
NOP
NOP
NOP
NOP
GOTO W001
W002: MOVF R0H,F
BTFSC STATUS,Z
RETURN
CALL W003
DECF R0H,F
DECF R0L,F
GOTO W001
W003: MOVLW 0x0C
MOVWF R2H
W004: DECFSZ R2H,F
GOTO W004
NOP
NOP
MOVLW 0x12
MOVWF R1L
W005: DECFSZ R1L,F
GOTO W006
CALL W007
CALL W007
NOP
NOP
RETURN
W006: CALL W007
GOTO W005
W007: MOVLW 0x0D
MOVWF R2L
W008: DECFSZ R2L,F
GOTO W008
NOP
RETURN
; End of listing
END