Autor Tema: ayuda con una libreria  (Leído 3293 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re: ayuda con una libreria
« Respuesta #15 en: 25 de Agosto de 2015, 14:57:26 »
Bueno te dejo el codigo que deberia funcionar. La salida nuevamente esta en PORTC,3, PERO ANTES DE PROBARLO LEE LO DE ABAJO

Código: ASM
  1. #INCLUDE<P16F73.INC>
  2.        
  3.         CBLOCK       0x20
  4.         R_ContA                
  5.         R_ContB
  6.         ENDC
  7.  
  8.         ORG 0x00                 ;vectores de reset e interrupcion
  9.         GOTO    PUERTOS
  10.         ORG 0X04
  11.         RETURN
  12.  
  13.         PUERTOS
  14.         BANKSEL TRISB
  15.         CLRF    TRISB           ; Todos como salidas
  16.         CLRF    TRISC
  17.         MOVLW   0x07            ; Dejo PORTA como entradas.
  18.         MOVWF   ADCON1
  19.         BANKSEL PORTA
  20.         CLRF    PORTA
  21.         CLRF    PORTC
  22.         CLRF    PORTB           ; A pesar que inician todos en 0 los pongo en 0 por las dudas
  23.  
  24.         BTFSC   PORTA,4
  25.         CALL    RUT
  26.         BTFSS   PORTA,4
  27.         CALL    RUT_2
  28.        
  29.         GOTO    ENVIO
  30.                
  31.  
  32.         RUT
  33.         BCF     PORTB,0
  34.         BCF     PORTB,1
  35.         BCF     PORTB,2
  36.         BCF     PORTB,3
  37.         RETURN
  38.        
  39.         RUT_2
  40.         BSF     PORTB,0
  41.         BSF     PORTB,1
  42.         BSF     PORTB,2
  43.         BSF     PORTB,3
  44.         RETURN
  45.  
  46. ENVIO
  47.         BSF PORTC,3          
  48.         CALL Retardo_1ms   ;1
  49.         CALL Retardo_1ms   ;1   --- 11
  50.         BCF PORTC,3          
  51.         CALL Retardo_1ms   ;0
  52.         BSF PORTC,3
  53.         CALL Retardo_1ms   ;1   --- 01
  54.         BCF PORTC,3
  55.         CALL Retardo_1ms   ;0
  56.         BSF PORTC,3
  57.         CALL Retardo_1ms   ;1   --- 01
  58.         CALL Retardo_1ms
  59.         BCF PORTC,3
  60.         CALL Retardo_1ms   ;0   --- 10
  61.         BSF PORTC,3
  62.         CALL Retardo_1ms   ;1
  63.         BCF PORTC,3
  64.         CALL Retardo_1ms   ;0   --- 10
  65.         BSF PORTC,3
  66.         CALL Retardo_1ms   ;1
  67.         BCF PORTC,3
  68.         CALL Retardo_1ms   ;0   --- 10
  69.         CALL Retardo_1ms   ;0
  70.         BSF PORTC,3
  71.         CALL Retardo_1ms   ;1   --- 01
  72.         BSF PORTC,3
  73.         CALL Retardo_1ms   ;1
  74.         BCF PORTC,3
  75.         CALL Retardo_1ms   ;0   --- 10
  76.         GOTO ENVIO
  77.  
  78.  
  79. Retardo_1ms
  80.                         ;993 cycles
  81.         movlw   0xC6
  82.         movwf   R_ContA
  83.         movlw   0x01
  84.         movwf   R_ContB
  85. Retardo_1ms_0
  86.         decfsz  R_ContA, f
  87.         goto    $+2
  88.         decfsz  R_ContB, f
  89.         goto    Retardo_1ms_0
  90.  
  91.                         ;3 cycles
  92.         goto    $+1
  93.         nop
  94.  
  95.                         ;4 cycles (including call)
  96.         return
  97.          
  98.         end

Si se te quemo el micro es por que algo hiciste mal, estaria bueno que dijeras cuales son las entradas y cuales son las salidas. Sino yo estoy adivinando.
El codigo que te pase ahora deje PORTA como entradas digitales, esto por que me parece que al leer PORTA,4 es que tenes un boton o una llave ahi.

Nuevamente en tus codigos tenes errores

Por ejemplo aca:
Código: ASM
  1. CALL    Delay_0  ;0   --- 10
  2.         RETURN
  3.  
  4.  
  5.  
  6.  
  7.                         ;499994 cycles
  8.         movlw   0x03
  9.         movwf   R_ContA
  10.         movlw   0x18
  11.         movwf   R_ContB
  12.         movlw   0x02
  13.         movwf   R_ContC
  14. Delay_0
  15.         decfsz  R_ContA, f
  16.         goto    $+2
  17.         decfsz  R_ContB , f
  18.         goto    $+2
  19.         decfsz  R_ContC, f
  20. ;       goto    Delay_0
  21.         return
  22.                         ;6 cycles
  23.         goto    $+1
  24.         goto    $+1
  25.         goto    $+1

No deberias llamar a Delay_0 sino un poco antes, si observas se cargan los 3 valores a decrementar y eso se tendria que hacer cada ves que lo llamas.
Algo asi como hiciste con tu proximo codigo..
PERO volves a tener el mismo problema de antes. en el que se ejecuta 1 sola ves el envio de los datos y luego lo encerras en LED_1 y no sale mas de ahi, asi que no envia mas datos. Por lo cual vas a ver algo muy rapido.

En fin. la ejecucion del programa es secuencial, primero 1 luego el otro y asi, los saltos hacen que se rompa esa cadena y sigan en otro lado, pero si vos haces:

Código: ASM
  1. LED_1
  2.         BSF   PORTA,0
  3.         GOTO LED_1

Entonces cuando llegue a Led_1 pone a 1 PORTA,0 y luego vuelve a LED_1 repitiendo todo, es un loop infinito que nunca va a terminar y haciendo nada. Muy distinto si es que hago algo asi:
Usando tu codigo. fijate el loop infinito, ahora siempre llama a envio y esta continuamente ejecutandose eso.
Código: ASM
  1. #INCLUDE<P16F73.INC>
  2.        
  3.         CBLOCK       0x20
  4.         R_ContA                
  5.         R_ContB
  6.         R_ContC
  7.         ENDC
  8.    
  9.  
  10. PUERTOS
  11.         BSF             STATUS,5
  12.         BCF             STATUS,6
  13.         BSF             ADCON1,0
  14.         BSF             ADCON1,1
  15.         BSF             ADCON1,2
  16.         CLRF    TRISB
  17.         CLRF    TRISA
  18.         CLRF    TRISC
  19.         BCF             STATUS,5
  20.         BCF             STATUS,6
  21.         CLRF    PORTA
  22.         CLRF    PORTC
  23.         CLRF    PORTB  
  24.         CLRW
  25.        
  26.  
  27.         BTFSC   PORTA,4
  28.         CALL    RUT
  29.         BTFSS   PORTA,4
  30.         CALL    RUT_2
  31.        
  32.         CALL    MINIENVIO
  33.  
  34.         GOTO LED_1
  35.                
  36.  
  37. RUT
  38.         BCF     PORTB,0
  39.         BCF     PORTB,1
  40.         BCF     PORTB,2
  41.         BCF     PORTB,3
  42.         RETURN
  43.        
  44. RUT_2
  45.         BSF     PORTB,0
  46.         BSF     PORTB,1
  47.         BSF     PORTB,2
  48.         BSF     PORTB,3
  49.         RETURN
  50.  
  51.        
  52.        
  53. LED_1
  54.         CALL    ENVIO
  55.         GOTO    LED_1
  56.  
  57.  
  58.         ENVIO
  59.         BSF     PORTA,2        
  60.         CALL    Retardo_05s        ;1
  61.         CALL    Retardo_05s        ;1   --- 11
  62.         BCF     PORTA,2          
  63.         CALL    Retardo_05s       ;0
  64.         BSF     PORTA,2
  65.         CALL    Retardo_05s       ;1   --- 01
  66.         BCF     PORTA,2
  67.         CALL    Retardo_05s        ;0
  68.         BSF     PORTA,2
  69.         CALL    Retardo_05s        ;1   --- 01
  70.         CALL    Retardo_05s    
  71.         BCF     PORTA,2
  72.         CALL    Retardo_05s        ;0   --- 10
  73.         BSF     PORTA,2
  74.         CALL    Retardo_05s        ;1
  75.         BCF     PORTA,2
  76.         CALL    Retardo_05s        ;0   --- 10
  77.         BSF     PORTA,2
  78.         CALL    Retardo_05s        ;1
  79.         BCF     PORTA,2
  80.         CALL    Retardo_05s        ;0   --- 10
  81.         CALL    Retardo_05s        ;0
  82.         BSF     PORTA,2
  83.         CALL    Retardo_05s        ;1   --- 01
  84.         BSF     PORTA,2
  85.         CALL    Retardo_05s        ;1
  86.         BCF     PORTA,2
  87.         CALL    Retardo_05s       ;0   --- 10
  88.         RETURN
  89.  
  90. MINIENVIO
  91.         BSF     PORTA,2
  92.         BCF     PORTA,2
  93.         BSF     PORTA,2
  94.         BCF     PORTA,2        
  95.         RETURN        
  96.  
  97. Retardo_05s             ;499994 cycles
  98.         movlw   0x08
  99.         movwf   R_ContA
  100.         movlw   0x2F
  101.         movwf   R_ContB
  102.         movlw   0x03
  103.         movwf   R_ContC
  104.         goto    Delay_0
  105. Delay_0
  106.         decfsz  R_ContA, f
  107.         goto    $+2
  108.         decfsz  R_ContB , f
  109.         goto    $+2
  110.         decfsz  R_ContC, f
  111.         goto    Delay_0
  112.         return
  113.                         ;6 cycles
  114.         goto    $+1
  115.         nop
  116.        
  117.         end
« Última modificación: 25 de Agosto de 2015, 15:02:07 por KILLERJC »

Desconectado yair_xiox

  • PIC16
  • ***
  • Mensajes: 210
Re: ayuda con una libreria
« Respuesta #16 en: 25 de Agosto de 2015, 17:51:33 »
gracias, ya funciona al menos en simulacion ya el programa llama al retardo que yo hice, KILLERJC, lo puedes comprobar en proteus haber si funciona y si sale la forma correcta de la señal por el pin A1, es que yo no tengo proteus
 
este es el codigo
Código: [Seleccionar]
#INCLUDE<P16F73.INC>

CBLOCK       0x20
R_ContA
R_ContB
R_ContC
ENDC
   








PUERTOS
BSF STATUS,5
BCF STATUS,6
BSF ADCON1,0
BSF ADCON1,1
BSF ADCON1,2
CLRF TRISB
CLRF TRISA
CLRF  TRISC
BCF STATUS,5
BCF STATUS,6
CLRF PORTA
CLRF PORTC
CLRF PORTB
CLRW
 







BTFSC PORTA,4
CALL RUT
BTFSS PORTA,4
CALL RUT_2



CALL LED_1
; CALL MINIENVIO
GOTO ENVIO




RUT
BCF PORTB,0
BCF PORTB,1
BCF PORTB,2
BCF PORTB,3
RETURN

RUT_2
BSF PORTB,0
BSF PORTB,1
BSF PORTB,2
BSF PORTB,3
RETURN



LED_1
BSF   PORTA,0
RETURN


ENVIO
BSF PORTA,2         
CALL Retardo_05s    ;1
CALL Retardo_05s    ;1   --- 11
BCF PORTA,2         
CALL Retardo_05s   ;0
BSF PORTA,2
CALL Retardo_05s   ;1   --- 01
BCF PORTA,2
CALL Retardo_05s    ;0
BSF PORTA,2
CALL Retardo_05s    ;1   --- 01
CALL Retardo_05s
BCF PORTA,2
CALL Retardo_05s    ;0   --- 10
BSF PORTA,2
CALL Retardo_05s    ;1
BCF PORTA,2
CALL Retardo_05s    ;0   --- 10
BSF PORTA,2
CALL Retardo_05s    ;1
BCF PORTA,2
CALL Retardo_05s    ;0   --- 10
CALL Retardo_05s    ;0
BSF PORTA,2
CALL Retardo_05s    ;1   --- 01
BSF PORTA,2
CALL Retardo_05s    ;1
BCF PORTA,2
CALL Retardo_05s   ;0   --- 10
GOTO ENVIO

MINIENVIO
BSF PORTA,2
BCF PORTA,2
BSF PORTA,2
BCF PORTA,2         
RETURN         

Retardo_05s ;499994 cycles
movlw 0x08
movwf R_ContA
movlw 0x2F
movwf R_ContB
movlw 0x03
movwf R_ContC
goto Delay_0
Delay_0
decfsz R_ContA, f
goto $+2
decfsz R_ContB , f
goto $+2
decfsz R_ContC, f
; goto Delay_0
return
;6 cycles
goto $+1
nop


end

Desconectado yair_xiox

  • PIC16
  • ***
  • Mensajes: 210
Re: ayuda con una libreria
« Respuesta #17 en: 25 de Agosto de 2015, 18:22:43 »
GRACIAS ya funciono era por el pin tenia que enviar la señal por el pin c3 y la estaba enviando por otro pin por eso no funcionaba muchas gracias


 

anything