;****************************************** http://www.x-robotics.com ******* ; PROGRAMA : ServoCrt.ASM Autor:ionitron Fecha: 25/10/2001 ; Funcion : Prueba de control de servo FUTABA S3003 conectado en RB0, el servo ; se movera a dos posiciones (0º-180º) dependiendo del estado del interruptor ; colocado en RA0. ; ; Revision : 1.0 Programa para : PIC16F84 ; Velocidad del reloj : 4 MHz Reloj instrucci¢n: 1 MHz = 1 us ; Perro Guardian : Deshabilitado Tipo de reloj : XT ; Proteccion del codigo : OFF ;****************************************** http://www.x-robotics.com ******* ; ;****************************** Igualdades ********************************** ; LIST P=PIC16F84 w EQU 0 ;Destino W f EQU 1 ;Destino registro RA EQU 05h ;Puerta A RB EQU 06h ;Puerta B PORTA EQU 05h ;Puerta A PORTB EQU 06h ;Puerta B TRISA EQU 5h ;Registro triestado de Puerta A TRISB EQU 6h ;Registro triestado de Puerta B STATUS EQU 03h ;Registro STATUS OPCION EQU 1h ;Registro OPCION RBPU EQU 7h ;Bit R de polarizaci¢n RP0 EQU 05h ;Bit 5 registro STATUS PDel0 EQU 0Ch PDel1 EQU 0Dh ; ;************************* Seccion Codigo de RESET ************************** ; ORG 00h ;Direccion del Vector de RESET GOTO Inicializa ;Comienza el programa ORG 05h ;Una posicion detras del Vector Interrupcion ; ;**************************** Seccion Inicializa **************************** ; Inicializa BSF STATUS,5 ;Seleccion Banco 1 MOVLW b'00000000' ;Carga W MOVWF TRISB ;Bit0 Puerta B salida MOVLW b'00000001' ;Carga W MOVWF TRISA ;Bit0 Puerta A entrada BCF STATUS,5 ;Seleccion Banco 1 CLRF RB LeerEntrada BTFSC RA,0 ;Comprueba estado interruptor en RA0 GOTO Servo_pos_1 ;Si ra0 = 0 salta y pone el servo en pos. 2 GOTO Servo_pos_2 ;Si ra0 = 1 no salta y pone el servo en pos. 1 GOTO LeerEntrada ; Bucle infinito ;************* Pulso de 0,2 ms para poner el servo en 0º ******************** Servo_pos_1 BSF RB,0 ;Pone a 1 la salida Rb0 ;------------------Bucle retardo duracion pulso a 1-------------- PDelay movlw .48 ; 1 set number of repetitions movwf PDel0 ; 1 | PLoop0 clrwdt ; 1 clear watchdog decfsz PDel0, 1 ; 1 + (1) is the time over? goto PLoop0 ; 2 no, loop PDelL1 goto PDelL2 ; 2 cycles delay PDelL2 clrwdt ; 1 cycle delay ;---------------------------------------------------------------- BCF RB,0 ;Pone a 0 la salida Rb0 ;-------------Bucle retardo duracion resto onda hasta 20 ms-------------- PDelayR movlw .86 ; 1 set number of repetitions (B) movwf PDel0 ; 1 | PLoop1R movlw .45 ; 1 set number of repetitions (A) movwf PDel1 ; 1 | PLoop2R clrwdt ; 1 clear watchdog PDelL1R goto PDelL2R ; 2 cycles delay PDelL2R clrwdt ; 1 cycle delay decfsz PDel1, 1 ; 1 + (1) is the time over? (A) goto PLoop2R ; 2 no, loop decfsz PDel0, 1 ; 1 + (1) is the time over? (B) goto PLoop1R ; 2 no, loop ;---------------------------------------------------------------- GOTO LeerEntrada ;************* Pulso de 2,2 ms para poner el servo en 180º ******************** Servo_pos_2 BSF RB,0 ;Pone a 1 la salida Rb0 ;------------------Bucle retardo duracion pulso a 1-------------- PDelay_2 movlw .4 ; 1 set number of repetitions (B) movwf PDel0 ; 1 | PLoop1_2 movlw .136 ; 1 set number of repetitions (A) movwf PDel1 ; 1 | PLoop2_2 clrwdt ; 1 clear watchdog decfsz PDel1, 1 ; 1 + (1) is the time over? (A) goto PLoop2_2 ; 2 no, loop decfsz PDel0, 1 ; 1 + (1) is the time over? (B) goto PLoop1_2 ; 2 no, loop PDelL1_2 goto PDelL2_2 ; 2 cycles delay PDelL2_2 clrwdt ; 1 cycle delay ;---------------------------------------------------------------- BCF RB,0 ;Pone a 0 la salida Rb0 ;-------------Bucle retardo duracion resto onda hasta 20 ms-------------- PDelayS movlw .17 ; 1 set number of repetitions (B) movwf PDel0 ; 1 | PLoop1S movlw .205 ; 1 set number of repetitions (A) movwf PDel1 ; 1 | PLoop2S clrwdt ; 1 clear watchdog clrwdt ; 1 cycle delay decfsz PDel1, 1 ; 1 + (1) is the time over? (A) goto PLoop2S ; 2 no, loop decfsz PDel0, 1 ; 1 + (1) is the time over? (B) goto PLoop1S ; 2 no, loop PDelL1S goto PDelL2S ; 2 cycles delay PDelL2S ;return ; 2+2 Done ;---------------------------------------------------------------- GOTO LeerEntrada END