;******************************************************************************************************
; FileName:Main.asm
;******************************************************************************************************
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
list p = PIC16F873A ; Seleccionar procesador.-
#include "P16F873A.inc" ; Incluir archivo P16F873A.inc
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
ERRORLEVEL -302
ERRORLEVEL -305
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; VARIABLES
;------------------------------------------------------------------------------
CBLOCK 0x20
Cont_Desbordes
ENDC
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; CONSTANTES
;------------------------------------------------------------------------------
BYTE_HIGH equ 0xFF
BYTE_LOW equ 0x44
BYTE_20ms equ 0x64
;------------------------------------------------------------------------------
#DEFINE SERVO_0 PORTB,0
#DEFINE SERVO_1 PORTB,1
#DEFINE SERVO_2 PORTB,2
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
RESET ORG H'00' ; Aqui comienza el micro.-
GOTO Main ; Salto a Inicio de mi programa.-
ORG H'05' ; Origen del codigo de programa.-
;------------------------------------------------------------------------------
; VECTOR DE INTERRUPCION
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
Main ;**** Configuracion de Puertos ****
bsf STATUS, RP0 ; Bank1
clrf PIE1 ; Disable peripheral interrupts
movlw 0x06
movwf ADCON1
clrf TRISB
movlw b'00000110'
movwf OPTION_REG
bcf STATUS, RP0 ; Bank0
clrf T1CON ; Stop Timer1, Internal Clock Source,
clrf INTCON ; Disable interrupts
clrf PORTB
clrf TMR0
clrf TMR1H ; Clear Timer1 High byte register
clrf TMR1L ; Clear Timer1 Low byte register
clrf PIR1 ; Clear peripheral interrupts Flags
movlw 0x30 ; Internal Clock source with 1:8 prescaler
movwf T1CON ; Timer1 is stopped and T1 osc is disabled
SERVO_POS_1
nop
bsf SERVO_0
bsf SERVO_1
bsf SERVO_2
movlw BYTE_20ms
movwf TMR0
movlw BYTE_HIGH
movwf TMR1H
movlw BYTE_LOW
movwf TMR1L
bsf T1CON, TMR1ON ; Timer1 starts to increment
btfss PIR1, TMR1IF
goto $-1
bcf PIR1, TMR1IF
bcf SERVO_0
bcf SERVO_1
bcf SERVO_2
btfss INTCON, T0IF
goto $-1
bcf INTCON, T0IF
incf Cont_Desbordes,1 ; Desbordo, contamos los desbordes
movlw .10 ; Contando 10 cada movimiento tardara 200ms
subwf Cont_Desbordes,0 ; Cuanto menor sea el numero mas rapido ira el servo
btfss STATUS, Z
goto SERVO_POS_1
clrf Cont_Desbordes
SERVO_POS_2
bcf T1CON, TMR1ON
bsf SERVO_0
bsf SERVO_1
bsf SERVO_2
movlw BYTE_20ms
movwf TMR0
movlw 0xFF
movwf TMR1H
movlw 0xB9
movwf TMR1L
bsf T1CON, TMR1ON ; Timer1 starts to increment
btfss PIR1, TMR1IF
goto $-1
bcf PIR1, TMR1IF
bcf SERVO_0
bcf SERVO_1
bcf SERVO_2
btfss INTCON, T0IF
goto $-1
bcf INTCON, T0IF
incf Cont_Desbordes,1 ; Desbordo, contamos los desbordes
movlw .10 ; Contando 10 cada movimiento tardara 200ms
subwf Cont_Desbordes,0 ; Cuanto menor sea el numero mas rapido ira el servo
btfss STATUS, Z
goto SERVO_POS_2
clrf Cont_Desbordes
goto SERVO_POS_1
END ; Fin del codigo.-