Autor Tema: Duda con programa  (Leído 2356 veces)

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

Desconectado ToRtUgOxX

  • PIC10
  • *
  • Mensajes: 10
Duda con programa
« en: 07 de Noviembre de 2008, 20:14:01 »
el programa anda bien. pero cuando cambio el lugar de la tabla y lo pongo abajo de todo no ( no abajo del end -_- )
alguien sabe xq? ( mi primer post supongo q estoy en el lugar correcto gracias :$ ).


Código: ASM
  1. LIST    p=16f628a
  2.         #include        <p16f628a.inc>
  3. SEG1    equ     0x4a
  4. SEG2    equ     0x4d
  5. MIN1    equ     0x4f
  6. MIN2    equ     0x20
  7. HOR1    equ     0x24
  8. HOR2    equ     0x28
  9. SAVE    equ     0x5a
  10. EVENTO  equ     0x5d
  11. reg1    equ     0x5f
  12. reg2    equ     0x3f
  13. reg3    equ     0x3A
  14. DATOLCD equ     0x3d
  15.         org     0x00
  16.         goto    inicio
  17.         org     0x05
  18. inicio  movlw   0x07
  19.         movwf   CMCON
  20.         call    bancouno
  21.         clrf    TRISB
  22.         clrf    TRISA
  23.         call    bancocero
  24.         call    LCD_INITIALIZATION
  25.         call    relojRESET
  26.         goto    seg1
  27. again   clrf    SEG1
  28.         clrf    SEG2
  29.         clrf    MIN1
  30.         clrf    MIN2
  31.         clrf    HOR1
  32.         clrf    HOR2
  33.         clrf    EVENTO
  34.         clrf    SAVE   
  35.         call    q                      
  36. seg1    call    ubicoLCDseg1
  37.         call    ret1segconLCD           ;me ubico
  38.         incf    SEG1,f
  39.         movf    SEG1,w
  40.         call    tabla
  41.         movwf   SAVE
  42.         movf    SAVE,w
  43.         xorlw   0x00
  44.         btfss   STATUS,Z
  45.         goto    $+2
  46.         goto    seg2
  47.         movf    SAVE,w
  48.         call    escribe
  49.         call    retardo
  50.         goto    seg1
  51.        
  52. seg2    clrf    SEG1
  53.         call    y
  54.         incf    SEG2,f
  55.         movf    SEG2,w
  56.         call    tabla
  57.         movwf   SAVE
  58.         xorlw   '6'
  59.         btfss   STATUS,Z
  60.         goto    $+2
  61.         goto    min1
  62.         call    ubicoLCDseg2
  63.         movf    SAVE,w
  64.         call    escribe
  65.         call    retardo
  66.         goto    seg1
  67.        
  68. min1
  69.         clrf    SEG2
  70.         call    t
  71.         incf    MIN1,f
  72.         movf    MIN1,w
  73.         call    tabla
  74.         movwf   SAVE
  75.         xorlw   0x00
  76.         btfss   STATUS,Z
  77.         goto    $+2    
  78.         goto    min2
  79.         call    ubicoLCDmin1
  80.         movf    SAVE,w
  81.         call    escribe
  82.         call    retardo
  83.         goto    seg1
  84.        
  85. min2   
  86.         clrf    MIN1
  87.         call    r
  88.         incf    MIN2,f
  89.         movf    MIN2,w
  90.         call    tabla
  91.         movwf   SAVE
  92.         xorlw   '6'
  93.         btfss   STATUS,Z
  94.         goto    $+2
  95.         goto    hor1
  96.         call    ubicoLCDmin2
  97.         movf    SAVE,w
  98.         call    escribe
  99.         call    retardo
  100.         goto    seg1
  101.  
  102. hor1    clrf    MIN2
  103.         call    e      
  104.         incf    HOR1,f
  105.         movf    HOR1,w
  106.         call    tabla
  107.         movwf   SAVE
  108.         xorlw   '4'
  109.         btfss   STATUS,Z
  110.         goto    d
  111.         movf    SAVE,w
  112.         btfss   EVENTO,0
  113.         goto    d
  114.         goto    again
  115. d       movf    SAVE,w
  116.         xorlw   0x00
  117.         btfss   STATUS,Z
  118.         goto    $+2
  119.         goto    hor2
  120.         call    ubicoLCDhor1
  121.         movf    SAVE,w
  122.         call    escribe
  123.         call    retardo
  124.         goto    seg1
  125.        
  126. hor2    clrf    HOR1
  127.         call    w
  128.         incf    HOR2,f
  129.         movf    HOR2,w
  130.         call    tabla
  131.         movwf   SAVE
  132.         xorlw   '2'
  133.         btfss   STATUS,Z
  134.         goto    $+2
  135.         bsf     EVENTO,0
  136.         call    ubicoLCDhor2
  137.         movf    SAVE,w
  138.         call    escribe
  139.         call    retardo
  140.         goto    seg1
  141.  
  142. tabla   addwf   PCL,f
  143.         retlw   '0'
  144.         retlw   '1'
  145.         retlw   '2'
  146.         retlw   '3'
  147.         retlw   '4'
  148.         retlw   '5'
  149.         retlw   '6'
  150.         retlw   '7'
  151.         retlw   '8'
  152.         retlw   '9'
  153.         retlw   0x00
  154.  
  155. bancocero       bcf     STATUS,RP0
  156.         bcf     STATUS,RP1
  157.         return
  158. bancouno        bsf     STATUS,RP0
  159.         bcf     STATUS,RP1
  160.         return 
  161.  
  162. q       call    ubicoLCDhor2
  163.         movlw   '0'
  164.         call    escribe
  165.         call    retardo
  166. w       call    ubicoLCDhor1
  167.         movlw   '0'
  168.         call    escribe
  169.         call    retardo
  170. e       call    ubicoLCDmin2
  171.         movlw   '0'
  172.         call    escribe
  173.         call    retardo
  174. r       call    ubicoLCDmin1
  175.         movlw   '0'
  176.         call    escribe
  177.         call    retardo
  178. t       call    ubicoLCDseg2
  179.         movlw   '0'
  180.         call    escribe
  181.         call    retardo
  182. y       call    ubicoLCDseg1
  183.         movlw   '0'
  184.         call    escribe
  185.         call    retardo
  186.         return
  187.  
  188. ubicoLCDhor2
  189.         movlw   b'10000000'
  190.         call    LCD_REGSWAP
  191.         call    retardo
  192.         return
  193. ubicoLCDhor1
  194.         movlw   b'10000001'
  195.         call    LCD_REGSWAP
  196.         call    retardo
  197.         return
  198.  
  199. ubicoLCDmin2
  200.         movlw   b'10000011'
  201.         call    LCD_REGSWAP
  202.         call    retardo
  203.         return
  204. ubicoLCDmin1
  205.         movlw   b'10000100'
  206.         call    LCD_REGSWAP
  207.         call    retardo
  208.         return
  209.  
  210. ubicoLCDseg2
  211.         movlw   b'10000110'
  212.         call    LCD_REGSWAP
  213.         call    retardo
  214.         return
  215. ubicoLCDseg1
  216.         movlw   b'10000111'
  217.         call    LCD_REGSWAP
  218.         call    retardo
  219.         return 
  220.  
  221. relojRESET
  222.         movlw   '0'
  223.         call    escribe
  224.         call    retardo
  225.         movlw   '0'
  226.         call    escribe
  227.         call    retardo
  228.         movlw   ':'    
  229.         call    escribe
  230.         call    retardo
  231.         movlw   '0'
  232.         call    escribe
  233.         call    retardo
  234.         movlw   '0'
  235.         call    escribe
  236.         call    retardo
  237.         movlw   ':'
  238.         call    escribe
  239.         call    retardo
  240.         movlw   '0'    
  241.         call    escribe
  242.         call    retardo
  243.         movlw   '0'
  244.         call    escribe
  245.         call    retardo
  246.         return
  247.  
  248. LCD_INITIALIZATION     
  249.         call    retardo
  250.         movlw   b'00110000'
  251.         call    LCD_REG
  252.         call    retardo
  253.         movlw   b'00110000'
  254.         call    LCD_REG
  255.         call    retardo
  256.         movlw   b'00110000'
  257.         call    LCD_REG
  258.         call    retardo
  259.         movlw   b'00100000'
  260.         call    LCD_REG
  261.         call    retardo
  262.         MOVLW   b'00101000'
  263.         call    LCD_REGSWAP
  264.         call    retardo
  265.         MOVLW    b'00000001'   ;Borrar LCD y Home
  266.         CALL    LCD_REGSWAP
  267.         call    retardo
  268.         MOVLW    b'00000110'  
  269.         CALL    LCD_REGSWAP
  270.         call    retardo
  271.         MOVLW    b'00001100'   ;LCD On, cursor Off,Parpadeo Off
  272.         CALL    LCD_REGSWAP
  273.         call    retardo
  274.         MOVLW   b'10000000'               ;Direccion caracter
  275.         CALL    LCD_REGSWAP
  276.         call    retardo    
  277.         return  
  278.                                
  279.        
  280. LCD_REG bcf     PORTA,0
  281.         movwf   PORTB
  282.         goto    ENABLE
  283.        
  284. ENABLE  bsf     PORTA,1
  285.         nop
  286.         bcf     PORTA,1
  287.         return
  288.  
  289. LCD_REGSWAP     bcf     PORTA,0
  290.         movwf   DATOLCD
  291.         movf    DATOLCD,w
  292.         andlw   b'11110000'
  293.         movwf   PORTB
  294.         bsf     PORTA,1
  295.         nop
  296.         bcf     PORTA,1
  297.         swapf   DATOLCD,w
  298.         andlw   b'11110000'
  299.         movwf   PORTB
  300.         goto    ENABLE
  301.        
  302. escribe bsf     PORTA,0
  303.         movwf   DATOLCD
  304.         movf    DATOLCD,w
  305.         andlw   b'11110000'
  306.         movwf   PORTB
  307.         bsf     PORTA,1
  308.         nop
  309.         bcf     PORTA,1
  310.         swapf   DATOLCD,w
  311.         andlw   b'11110000'
  312.         movwf   PORTB
  313.         goto    ENABLE         
  314.        
  315. retardo movlw   0x10        
  316.         movwf   reg2
  317.         movlw   0xff
  318.         movwf   reg1
  319.         decfsz  reg1,f
  320.         goto    $-1
  321.         decfsz  reg2,f
  322.         goto    $-5
  323.         return         
  324.  
  325. retardogosu
  326.         movlw   0x10
  327.         movwf   reg3
  328.         movlw   0xff
  329.         movwf   reg2
  330.         movlw   0xff
  331.         movwf   reg1
  332.         decfsz  reg1,f
  333.         goto    $-1
  334.         decfsz  reg2,
  335.         goto    $-5
  336.         decfsz  reg3,f
  337.         goto    $-9
  338.         return
  339.  
  340. ret1segconLCD   nop             ; para la simulacion.
  341.         return
  342.        
  343. ; x ejemplo aca la tabla y no anda :(
  344.        
  345.         end




jacrmr

  • Visitante
Re: Duda con programa
« Respuesta #1 en: 07 de Noviembre de 2008, 22:28:48 »
Tienes que precargar el PCLATH con la dirección de la tabla, y la otra es que las tablas no pueden cruzar fronteras de 256 bytes. Siempre deben permanecer entre los límites de bloques de 256 bytes (0xXX00 ~ 0xXXFF). Checa en la hoja de datos en la sección donde explican el funcionamiento del PC, llamadas CALL y GOTO, etc.

Desconectado ToRtUgOxX

  • PIC10
  • *
  • Mensajes: 10
Re: Duda con programa
« Respuesta #2 en: 07 de Noviembre de 2008, 22:35:52 »
no es un problema de PCLATH ya que es un 628 ( tengo 2K )
lo unico q hago es cambiar de lugar una subrutina y no anda :(  ( la subrutina de la tabla :((( )

Desconectado migsantiago

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8257
    • Sitio de MigSantiago
Re: Duda con programa
« Respuesta #3 en: 07 de Noviembre de 2008, 23:05:20 »
Si pones la etiqueta 'tabla' en la línea 343, eso aproximadamente será grabado en la dirección 0x0148 de memoria de programa, donde tienes el noveno bit activado y según la hoja de características de los pic16...



... cuando se hace una operación que involucra a PCL, se concatena el valor de PCL + 5 bits de PCLATH.

Entonces si PCL vale 0x48 (porque se trunca el noveno bit) y luego le concatenas 5 bits de PCLATH (todos en cero), se obtiene la dirección de memoria 0x0048, la cual apunta a un lugar no esperado por ti.

Debes poner a pclath igual a 0x01 antes de hacer ADDWF PCL,F para que cuando llames a la subrutina el valor regrese a donde debe. Puedes poner PCLATH igual a 0x01 cuando configuras puertos.
« Última modificación: 07 de Noviembre de 2008, 23:07:47 por migsantiago »

jacrmr

  • Visitante
Re: Duda con programa
« Respuesta #4 en: 07 de Noviembre de 2008, 23:47:45 »
Citar
no es un problema de PCLATH ya que es un 628 ( tengo 2K )

Aún así es un problema si manejas tablas. El PCLATH sigue involucrado aunque tengas 2K si usas tablas.

Desconectado ToRtUgOxX

  • PIC10
  • *
  • Mensajes: 10
Re: Duda con programa
« Respuesta #5 en: 08 de Noviembre de 2008, 00:06:08 »
ahi ta gracias  :-/