Paso 8: El código del programa del microcontrolador
;***************FINAL********************************lista p = 16f877
incluyen < P16F877. INC >
base dic
idlocs "V" << 8 | "1" ; Versión no.
config _CP_OFF & _PWRTE_OFF & _WDT_OFF & _XT_OSC
; *** variable principal ***
cblock 0 x 20; inicio de zona de ram del banco 0
INPUT_VAR
L1
L2
X
SPEED11
SPEED12
SPEED21
SPEED22
MSTOP
LDET
LR1
LR2
CDDN
; *** Inicio de programa principal ***
Inicio
BSF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 40
MOVWF ADCON1
MOVLW 0XFF; UN PUERTO ES
MOVWF TRISA
MOVLW 0 X 00; PUERTO B ES O
MOVWF TRISB
MOVLW 0XF0; PUERTO C ES ENTRADA-SALIDA
MOVWF TRISC
MOVLW 0XF0; PUERTO D ES ENTRADA-SALIDA
MOVWF TRISD
MOVLW 0X07; PUERTO E ES I
MOVWF TRISE
BANKSEL OPTION_REG
BCF OPTION_REG, T0CS
BCF STATUS, RP1
BCF STATUS, RP0
;*******************************************
;*******************************************
ESPERAR
BCF PORTB, 1
BCF PORTB, 2
BCF PORTB, 6
LLAMAR AL PWM1OFF
LLAMAR AL PWM2OFF
BCF PORTD, 0
BCF PORTD, 1
BCF PORTD, 2
BCF PORTD, 3
BTFSS LDET, 0
BCF PORTB, 7
MOVLW 0 X 00
MOVF MSTOP
MOVF LDET
BANKSEL INTCON
BCF INTCON, GIE
BANKSEL TXSTA
BSF TXSTA, BRGH
MOVLW 0 X 40
MOVWF SPBRG
BCF TXSTA, SYNC
BANKSEL RCSTA
BSF RCSTA, SPEN
BTFSC RCSTA, OERR
GOTO CLROE
BANKSEL PIE1
BSF PIE1, RCIE
BANKSEL RCSTA
BCF RCSTA, RX9
BSF RCSTA, CREN
WAIT1
BANKSEL PORTB
BSF PORTB, 3
BSF PORTB, 4
BANKSEL PIR1
BTFSS PIR1, RCIF
GOTO WAIT1
MILLONES DE PIES CÚBICOS MSTOP, 0
BCF PORTB, 3
BCF PORTB, 4
LLAMAR AL PWM1OFF
LLAMAR AL PWM2OFF
LLAMADA DARKLIGHT
BTFSC LDET, 0
BSF PORTB, 7
RXDATA
; BANKSEL RCSTA
; BTFSC RCSTA, OERR
; GOTO PARADAS
LLAMAR AL PWM1OFF
LLAMAR AL PWM2OFF
LLAMADA DARKLIGHT
BTFSC LDET, 0
BSF PORTB, 7
BANKSEL PIR1
BCF PIR1, RCIF
BANKSEL RCREG
MOVF RCREG, 0
;*******************************************
;*******************************************
MOVWF INPUT_VAR
MOVLW 0 X 00
RCREG MOVWF
BCF STATUS, RP0
BCF STATUS, RP1
MOVF INPUT_VAR, 0; PARADA
SUBLW 0X53
BTFSC STATUS, Z
GOTO PARADAS
MOVF INPUT_VAR, 0; LUZ EN
SUBLW 0X4E
BTFSC STATUS, Z
GOTO LON
MOVF INPUT_VAR, 0; LUZ ESTÁ APAGADA
SUBLW 0X51
BTFSC STATUS, Z
GOTO LOFF
MOVF INPUT_VAR, 0; AVANCE LENTO
SUBLW 0X66
BTFSC STATUS, Z
GOTO FSLOW
MOVF INPUT_VAR, 0; MOVER A LA DERECHA LENTA
SUBLW 0X72
BTFSC STATUS, Z
GOTO RSLOW
MOVF INPUT_VAR, 0; MOVERSE A LA IZQUIERDA LENTA
SUBLW 0X6C
BTFSC STATUS, Z
GOTO ALTA
MOVF INPUT_VAR, 0; MOVERSE HACIA ATRÁS LENTA
SUBLW 0X62
BTFSC STATUS, Z
GOTO ALENTO
MOVF INPUT_VAR, 0; MUEVA HACIA ADELANTE MEDIO
SUBLW 0X46
BTFSC STATUS, Z
GOTO FMEDIO
MOVF INPUT_VAR, 0; MOVIMIENTO MEDIO DERECHA
SUBLW 0X52
BTFSC STATUS, Z
GOTO RMARON
MOVF INPUT_VAR, 0; MOVIMIENTO MEDIO IZQUIERDO
SUBLW 0X4C
BTFSC STATUS, Z
GOTO LMADOS
MOVF INPUT_VAR, 0; MUEVA HACIA ATRÁS MEDIO
SUBLW 0X42
BTFSC STATUS, Z
BMED GOTO
MOVF INPUT_VAR, 0; AVANZAR RÁPIDO
SUBLW 0X55
BTFSC STATUS, Z
FFAST GOTO
MOVF INPUT_VAR, 0; MOVER RÁPIDO DERECHA
SUBLW 0X57
BTFSC STATUS, Z
GOTO RFAST
MOVF INPUT_VAR, 0; MOVERSE A LA IZQUIERDA RÁPIDA
SUBLW 0X56
BTFSC STATUS, Z
GOTO LFAST
MOVF INPUT_VAR, 0; RETROCEDER RÁPIDAMENTE
SUBLW 0X58
BTFSC STATUS, Z
GOTO BFAST
MOVF INPUT_VAR, 0; CERCA DE LA MANO
SUBLW 0X43
BTFSC STATUS, Z
GOTO HCLOSE
MOVF INPUT_VAR, 0; MANO ABIERTA
SUBLW 0X4F
BTFSC STATUS, Z
GOTO HOPEN
MOVF INPUT_VAR, 0; MANO HACIA ARRIBA
SUBLW 0 X 75
BTFSC STATUS, Z
GOTO HUP
MOVF INPUT_VAR, 0; DE LA MANO HACIA ABAJO
SUBLW 0X64
BTFSC STATUS, Z
GOTO HDOWN
MOVF INPUT_VAR, 0; LUZ FOLOWER
SUBLW 0X54
BTFSC STATUS, Z
GOTO LFOLLOW
;*******************************************
;*******************************************
GOTO CLROE
FSLOW
; BANKSEL RCSTA
; BCF RCSTA, OERR
; BCF RCSTA, CREN
; NOP
; BSF RCSTA, CREN
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
; MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
NORMALSLOW
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X66
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X66
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BSF PORTB, 2
REP3
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP3
GOTO CLROE
;*******************************************
ALTA
BCF STATUS, RP0
BCF STATUS, RP1
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X99
MOVWF SPEED12
MOVLW 0XCF
MOVWF SPEED21
MOVLW 0X66
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BCF PORTB, 2
REP4
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP4
GOTO CLROE
;*******************************************
RSLOW
BCF STATUS, RP0
BCF STATUS, RP1
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XCF
MOVWF SPEED11
MOVLW 0X66
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X99
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BSF PORTD, 1
BCF PORTB, 1
BSF PORTB, 2
REP35
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP35
GOTO CLROE
;*****************************
ALENTO
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XCF
MOVWF SPEED11
MOVLW 0X99
MOVWF SPEED12
MOVLW 0XCF
MOVWF SPEED21
MOVLW 0X99
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BSF PORTD, 1
BCF PORTB, 1
BCF PORTB, 2
REP5
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP5
GOTO CLROE
;*******************************************
FMEDIO
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
NORMALMED
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X99
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X99
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BSF PORTB, 2
LLAMAR AL SDELAY
REP6
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
NOP
BTFSS PORTD, 7
GOTO REP6
PLUSEMED
MOVLW 0XCF
MOVWF SPEED11
MOVLW 0XCC
MOVWF SPEED12
MOVLW 0XCF
MOVWF SPEED21
MOVLW 0XCC
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BSF PORTB, 2
LLAMAR AL SDELAY
REP7
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
BTFSS PORTD, 7
GOTO NORMALMED
GOTO REP7
GOTO CLROE
;*******************************************
RMARON
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X99
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X66
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BSF PORTD, 1
BCF PORTB, 1
BSF PORTB, 2
REP8
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP8
GOTO CLROE
;*******************************************
LMADOS
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X66
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X99
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BCF PORTB, 2
REP9
; LLAMAR AL STALL1
; BTFSC MSTOP, 0
; GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP9
GOTO CLROE
;*******************************************
BMED
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X7F
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X7F
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BSF PORTD, 1
BCF PORTB, 1
BCF PORTB, 2
REP10
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP10
GOTO CLROE
;*******************************************
FFAST
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
BSF MSTOP, 4
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XEF
MOVWF SPEED11
MOVLW 0X7F
MOVWF SPEED12
MOVLW 0XEF
MOVWF SPEED21
MOVLW 0X7F
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BSF PORTB, 2
LLAMAR AL SDELAY
NORMALFAST
MOVLW 0XCF
MOVWF SPEED11
MOVLW 0XCC
MOVWF SPEED12
MOVLW 0XCF
MOVWF SPEED21
MOVLW 0XCC
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BCF PORTD, 1
BTFSC LDET, 0
BSF PORTB, 7
BSF PORTB, 1
BSF PORTB, 2
REP11
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
NOP
BTFSS PORTD, 7
GOTO REP11
PLUSEFAST
MOVLW 0XCF
MOVWF SPEED11
MOVLW 0XFF
MOVWF SPEED12
MOVLW 0XCF
MOVWF SPEED21
MOVLW 0XFF
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BSF PORTB, 2
REP12
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
BTFSS PORTD, 7
GOTO NORMALFAST
GOTO REP12
GOTO CLROE
;*******************************************
RFAST
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X99
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X66
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BSF PORTD, 1
BCF PORTB, 1
BSF PORTB, 2
REP13
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP13
GOTO CLROE
;*******************************************
LFAST
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X66
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X99
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BCF PORTB, 2
LLAMAR AL SDELAY
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X4C
MOVWF SPEED12
MOVLW 0XEF
MOVWF SPEED21
MOVLW 0XB3
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BCF PORTB, 2
REP14
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP14
GOTO CLROE
;*******************************************
BFAST
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
MOVLW 0XDF
MOVWF SPEED11
MOVLW 0X99
MOVWF SPEED12
MOVLW 0XDF
MOVWF SPEED21
MOVLW 0X99
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BSF PORTD, 1
BCF PORTB, 1
BCF PORTB, 2
LLAMAR AL SDELAY
MOVLW 0XEF
MOVWF SPEED11
MOVLW 0X66
MOVWF SPEED12
MOVLW 0XEF
MOVWF SPEED21
MOVLW 0X66
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BSF PORTD, 1
BCF PORTB, 1
BCF PORTB, 2
REP15
LLAMAR AL STALL1
BTFSC MSTOP, 0
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP15
GOTO CLROE
;*******************************************
HCLOSE
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
BTFSC PORTD, 5
GOTO PARADAS
BTFSC PORTD, 6
GOTO PARADAS
BSF PORTD, 2
BCF PORTD, 3
REP16
BTFSC PORTD, 5
GOTO PARADAS
BTFSC PORTD, 6
GOTO PARADAS
LLAMAR AL SDELAY
LLAMAR AL STALL2
BTFSC MSTOP, 2
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP16
GOTO CLROE
;*******************************************
HOPEN
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
BTFSC PORTD, 4
GOTO PARADAS
BCF PORTD, 2
BSF PORTD, 3
REP17
BTFSC PORTD, 4
GOTO PARADAS
LLAMAR AL SDELAY
LLAMAR AL STALL2
BTFSC MSTOP, 2
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP17
GOTO CLROE
;*******************************************
HUP
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
BTFSC PORTC, 4
GOTO PARADAS
BCF PORTC, 0
BSF PORTC, 3
REP18
BTFSC PORTC, 4
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP18
GOTO CLROE
;*******************************************
HDOWN
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
MILLONES DE PIES CÚBICOS LDET, 0
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
LLAMADA DARKLIGHT
BTFSC LDET, 0
; BSF PORTB, 7
BTFSC PORTC, 5
GOTO PARADAS
BSF PORTC, 0
BCF PORTC, 3
REP19
BTFSC PORTC, 5
GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
GOTO REP19
GOTO CLROE
;*******************************************
LON
BSF PORTB, 7
BSF LDET, 0
GOTO CLROE
;*******************************************
LOFF
BCF PORTB, 7
MILLONES DE PIES CÚBICOS LDET, 0
GOTO CLROE
;*******************************************
LFOLLOW
BCF STATUS, RP0
BCF STATUS, RP1
BCF PORTB, 1
BCF PORTB, 2
BCF PORTB, 6
BCF PORTB, 7
LLAMAR AL PWM1OFF
LLAMAR AL PWM2OFF
BCF PORTD, 0
BCF PORTD, 1
BCF PORTD, 2
BCF PORTD, 3
BSF MSTOP, 6
REPLF
; BANKSEL OPTION_REG
; BSF OPTION_REG, 3
; BSF OPTION_REG, 3
; BSF OPTION_REG, 3
; BSF OPTION_REG, 3
; CLRFWDT
BCF STATUS, RP0
BCF STATUS, RP1
; BANKSEL INTCON
; BCF INTCON, T0IE
; BCF INTCON, T0IF
; BANKSEL PIE1
; PIE1 MILLONES DE PIES CÚBICOS, 6
; MILLONES DE PIES CÚBICOS PIE1, 0
; BANKSEL INTCON
; BCF INTCON, GIE
BANKSEL PCON
PCON MILLONES DE PIES CÚBICOS, 0
PCON MILLONES DE PIES CÚBICOS, 1
NOP
BSF PCON, 0
BSF PCON, 1
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
LLAMAR AL SDELAY
LFC1 LLAMADA
NOP
LLAMADA LFC2
NOP
MOVF LR2, 0
SUBWF LR1, 0
BTFSC STATUS, Z
GOTO FRENTE
LLAMAR AL SDELAY
LFC1 LLAMADA
NOP
LLAMADA LFC2
NOP
MOVF LR2, 0
SUBWF LR1, 0
BTFSC STATUS, C
GOTO LR2G
LR1G
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X66
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X99
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BSF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BCF PORTB, 2
LR1GREP
; LLAMAR AL STALL1
; BTFSC MSTOP, 0
; GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
LFC1 LLAMADA
NOP
LLAMADA LFC2
NOP
MOVF LR2, 0
SUBWF LR1, 0
BTFSC STATUS, Z
GOTO REPLF
LFC1 LLAMADA
NOP
LLAMADA LFC2
NOP
MOVF LR2, 0
SUBWF LR1, 0
BTFSS STATUS, C
GOTO LR1GREP
GOTO REPLF
LR2G
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X99
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X66
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BSF PORTD, 1
BCF PORTB, 1
BSF PORTB, 2
LR2GREP
; LLAMAR AL STALL1
; BTFSC MSTOP, 0
; GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
LFC1 LLAMADA
NOP
LLAMADA LFC2
NOP
MOVF LR2, 0
SUBWF LR1, 0
BTFSC STATUS, Z
GOTO REPLF
LFC1 LLAMADA
NOP
LLAMADA LFC2
NOP
MOVF LR2, 0
SUBWF LR1, 0
BTFSC STATUS, C
GOTO LR2GREP
GOTO REPLF
FRENTE
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
; LLAMAR AL BUTTLEVEL
; BTFSC MSTOP, 1
; GOTO PARADAS
MOVLW 0XFF
MOVWF SPEED11
MOVLW 0X99
MOVWF SPEED12
MOVLW 0XFF
MOVWF SPEED21
MOVLW 0X99
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BCF PORTD, 1
BSF PORTB, 1
BSF PORTB, 2
LLAMAR AL SDELAY
FROREP
; LLAMAR AL STALL1
; BTFSC MSTOP, 0
; GOTO PARADAS
BANKSEL PIR1
BTFSC PIR1, RCIF
GOTO RXDATA
; LDIN LLAMADA
; BTFSC MSTOP, 3
; GOTO PARADAS
LFC1 LLAMADA
NOP
LLAMADA LFC2
NOP
MOVF LR2, 0
SUBWF LR1, 0
BTFSC STATUS, Z
GOTO FROREP
GOTO REPLF
GOTO CLROE
;*******************************************
PARADAS
BTFSS MSTOP, 4
GOTO STOPA
MOVLW 0XCF
MOVWF SPEED11
MOVLW 0XB3
MOVWF SPEED12
MOVLW 0XCF
MOVWF SPEED21
MOVLW 0XB3
MOVWF SPEED22
LLAMAR AL PWM1ON
LLAMAR AL PWM2ON
BCF PORTD, 0
BCF PORTD, 1
LLAMAR AL SDELAY
STOPA
BCF STATUS, RP0
BCF STATUS, RP1
BCF PORTB, 1
BCF PORTB, 2
BCF PORTB, 6
BTFSS LDET, 0
; BCF PORTB, 7
BCF PORTC, 0
BCF PORTC, 3
LLAMAR AL PWM1OFF
LLAMAR AL PWM2OFF
BCF PORTD, 0
BCF PORTD, 1
BCF PORTD, 2
BCF PORTD, 3
MOVLW 0 X 00
MOVWF MSTOP
;*******************************************
CLROE
BANKSEL RCSTA
BCF RCSTA, CREN
BCF RCSTA, FERR
BCF RCSTA, OERR
BSF RCSTA, CREN
BSF INTCON, GIE
BSF INTCON, PEIE
GOTO WAIT1
;*******************************************
;*******************************************
;*******************************************
STALL1
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
BANKSEL ADCON0
ADCON0 MILLONES DE PIES CÚBICOS, 3
MILLONES DE PIES CÚBICOS ADCON0, 4
ADCON0 MILLONES DE PIES CÚBICOS, 5
BCF STATUS, RP0
BCF STATUS, RP1
LLAME A CONVERTIR
MOVF ADRESH, 0
SUBLW 0X70
BTFSS STATUS, C
BSF MSTOP, 0
BCF STATUS, RP0
BCF STATUS, RP1
VOLVER
STALL2
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
BANKSEL ADCON0
BSF ADCON0, 3
MILLONES DE PIES CÚBICOS ADCON0, 4
ADCON0 MILLONES DE PIES CÚBICOS, 5
BCF STATUS, RP0
BCF STATUS, RP1
LLAME A CONVERTIR
MOVF ADRESH, 0
SUBLW 0 X 40
BTFSS STATUS, C
BSF MSTOP, 2
BCF STATUS, RP0
BCF STATUS, RP1
VOLVER
BUTTLEVEL
BCF STATUS, RP0
BCF STATUS, RP1
MOVLW 0 X 00
MOVWF MSTOP
BANKSEL ADCON0
ADCON0 MILLONES DE PIES CÚBICOS, 3
MILLONES DE PIES CÚBICOS ADCON0, 4
BSF ADCON0, 5
BCF STATUS, RP0
BCF STATUS, RP1
LLAME A CONVERTIR
MOVF ADRESH, 0
SUBLW 0X7F
BTFSS STATUS, C
GOTO BL1
GOTO BL2
ALR
BSF MSTOP, 1
BSF PORTB, 6
BL2
VOLVER
DARKLIGHT
BCF STATUS, RP0
BCF STATUS, RP1
BTFSC LDET, 0
GOTO RETFDL
BANKSEL ADCON0
ADCON0 MILLONES DE PIES CÚBICOS, 3
BSF ADCON0, 4
ADCON0 MILLONES DE PIES CÚBICOS, 5
BCF STATUS, RP0
BCF STATUS, RP1
LLAME A CONVERTIR
MOVF ADRESH, 0
SUBLW 0XEE
BTFSS STATUS, C
BSF PORTB, 7
RETFDL
VOLVER
CONVERTIR
MOVLW 0X49
BANKSEL ADCON1
MOVWF ADCON1
BANKSEL ADCON0
ADCON0 MILLONES DE PIES CÚBICOS, 7
BSF ADCON0, 6
BSF ADCON0, 0
BSF ADCON0, GO
WAITADC
BTFSC ADCON0, GO
GOTO WAITADC
BCF STATUS, RP1
BCF STATUS, RP0
VOLVER
PWM1ON
BANKSEL PR2
MOVLW 0XFF
MOVWF PR2
BCF STATUS, RP0
BCF STATUS, RP1
MOVF SPEED11, 0
MOVWF CCP1CON
MOVF SPEED12, 0
MOVWF CCPR1L
BSF STATUS, RP0
BCF STATUS, RP1
MOVLW 0XF0
MOVWF TRISC
BCF STATUS, RP0
BCF STATUS, RP1
MILLONES DE PIES CÚBICOS T2CON, T2CKPS1
MILLONES DE PIES CÚBICOS T2CON, T2CKPS0
BSF T2CON, TMR2ON
BSF CCP1CON, 2
BSF CCP1CON, 3
VOLVER
PWM2ON
BANKSEL PR2
MOVLW 0XFF
MOVWF PR2
BCF STATUS, RP0
BCF STATUS, RP1
MOVF SPEED21, 0
MOVWF CCP2CON
MOVF SPEED22, 0
MOVWF CCPR2L
BSF STATUS, RP0
BCF STATUS, RP1
MOVLW 0XF0
MOVWF TRISC
BCF STATUS, RP0
BCF STATUS, RP1
MILLONES DE PIES CÚBICOS T2CON, T2CKPS1
MILLONES DE PIES CÚBICOS T2CON, T2CKPS0
BSF T2CON, TMR2ON
BSF CCP2CON, 2
BSF CCP2CON, 3
VOLVER
PWM1OFF
BCF CCP1CON, 2
BCF CCP1CON, 3
BSF T2CON, T2CKPS1
BSF T2CON, T2CKPS0
MILLONES DE PIES CÚBICOS T2CON, TMR2ON
MOVLW 0 X 00
MOVWF CCP1CON
MOVLW 0 X 00
MOVWF CCPR1L
BANKSEL PR2
MOVLW 0 X 00
MOVWF PR2
BCF STATUS, RP1
BCF STATUS, RP0
VOLVER
PWM2OFF
CCP2CON MILLONES DE PIES CÚBICOS, 2
CCP2CON MILLONES DE PIES CÚBICOS, 3
BSF T2CON, T2CKPS1
BSF T2CON, T2CKPS0
MILLONES DE PIES CÚBICOS T2CON, TMR2ON
MOVLW 0 X 00
MOVWF CCP2CON
MOVLW 0 X 00
MOVWF CCPR2L
BANKSEL PR2
MOVLW 0 X 00
MOVWF PR2
BCF STATUS, RP1
BCF STATUS, RP0
VOLVER
LFC1
BANKSEL ADCON0
BSF ADCON0, 3
MILLONES DE PIES CÚBICOS ADCON0, 4
BSF ADCON0, 5
BCF STATUS, RP0
BCF STATUS, RP1
LLAME A CONVERTIR
MOVF ADRESH, W
ANDLW 0XF0
MOVWF LR1
BCF STATUS, RP0
BCF STATUS, RP1
VOLVER
LFC2
BANKSEL ADCON0
ADCON0 MILLONES DE PIES CÚBICOS, 3
BSF ADCON0, 4
BSF ADCON0, 5
BCF STATUS, RP0
BCF STATUS, RP1
LLAME A CONVERTIR
MOVF ADRESH, 0
ANDLW 0XF0
MOVWF LR2
BCF STATUS, RP0
BCF STATUS, RP1
VOLVER
LDIN
BANKSEL ADCON0
ADCON0 MILLONES DE PIES CÚBICOS, 3
BSF ADCON0, 4
ADCON0 MILLONES DE PIES CÚBICOS, 5
BCF STATUS, RP0
BCF STATUS, RP1
LLAME A CONVERTIR
MOVF ADRESH, 0
SUBLW 0X4C
BTFSC STATUS, C
COMP4 GOTO
BSF MSTOP, 3
COMP4
BCF STATUS, RP0
BCF STATUS, RP1
VOLVER
SDELAY
CLRF L2
XL3
CLRF L1
XL2
CLRF TMR0
XL1
MOVLW 0XFF
SUBWF TMR0, W
BTFSS STATUS, C
GOTO XL1
MOVLW 0 X 20
INCF L1
SUBWF L1, W
BTFSS STATUS, C
GOTO XL2
MOVLW 0 X 10
INCF L2
SUBWF L2, W
BTFSS STATUS, C
GOTO XL3
VOLVER
NOP
NOP
FINAL