Autor Tema: Display 7 Segmentos (SOLUCIONADO)  (Leído 2144 veces)

0 Usuarios y 3 Visitantes están viendo este tema.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Display 7 Segmentos (SOLUCIONADO)
« en: 30 de Abril de 2013, 15:23:35 »
Hola, tengo un codigo para un display el cual creo que deberia de funcionar, pero no es asi ni en simulacion y en la vida real. Alguien seria tan amable de mirar el codigo y darme un empujoncito, el problema es que no entra en la tabla o eso creo.
Código: ASM
  1. list            p=16f873A       ; list directive to define processor
  2.         #include        <p16f873A.inc; processor specific variable definitions
  3.        
  4.         __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF & _DEBUG_OFF
  5.  
  6. ; '__CONFIG' directive is used to embed configuration data within .asm file.
  7. ; The lables following the directive are located in the respective .inc file.
  8. ; See respective data sheet for additional information on configuration word.
  9.  
  10.  
  11.         ERRORLEVEL -205
  12.  
  13.  
  14. ;***** VARIABLE DEFINITIONS
  15. w_temp          EQU     0x20            ; variable used for context saving
  16. w_temp1         EQU     0xA0            ; reserve bank1 equivalent of w_temp
  17. status_temp     EQU     0x21            ; variable used for context saving
  18. pclath_temp     EQU     0x22            ; variable used for context saving
  19. Pulsador        EQU     0                       ; Definimos Pulsador como el bit 0, en este caso PORTA
  20.  
  21. CBLOCK          0x23
  22. Contador
  23. PDel0
  24. PDel1
  25. ENDC
  26.  
  27.  
  28.  
  29. ;**********************************************************************
  30.         ORG     0x000             ; processor reset vector
  31.  
  32. ;       nop                                               ; nop required for icd
  33.         goto    main              ; go to beginning of program
  34.  
  35.  
  36.         ORG     0x004             ; interrupt vector location
  37.  
  38.         movwf   w_temp            ; save off current W register contents
  39.         movf    STATUS,w          ; move status register into W register
  40.         bcf     STATUS,RP0        ; ensure file register bank set to 0
  41.         movwf   status_temp       ; save off contents of STATUS register
  42.         movf    PCLATH,w              ; move pclath register into w register
  43.         movwf   pclath_temp           ; save off contents of PCLATH register
  44.  
  45.  
  46. ; isr code can go here or be located as a call subroutine elsewhere
  47.  
  48.         bcf     STATUS,RP0        ; ensure file register bank set to 0
  49.         movf    pclath_temp,w     ; retrieve copy of PCLATH register
  50.         movwf   PCLATH                ; restore pre-isr PCLATH register contents
  51.         movf    status_temp,w     ; retrieve copy of STATUS register
  52.         movwf   STATUS            ; restore pre-isr STATUS register contents
  53.         swapf   w_temp,f
  54.         swapf   w_temp,w          ; restore pre-isr W register contents
  55.         retfie                    ; return from interrupt
  56.  
  57. BCD7SEG:
  58.         addwf   PCL,1                           ; Se incrementa el contador del programa
  59.         retlw   b'0111111'                      ; 0
  60.         retlw   b'0000110'                      ; 1
  61.         retlw   b'1011011'                      ; 2
  62.         retlw   b'1001111'                      ; 3
  63.         retlw   b'1100110'                      ; 4
  64.         retlw   b'1101101'                      ; 5
  65.         retlw   b'1111101'                      ; 6
  66.         retlw   b'0000111'                      ; 7
  67.         retlw   b'1111111'                      ; 8
  68.         retlw   b'1101111'                      ; 9
  69.         clrf    Contador                        ; Si llega a 10, se resetea contador
  70.         retlw   b'0111111'                      ; 0
  71.  
  72. main
  73.         bcf             STATUS,RP0
  74.         bcf             STATUS,RP1                      ; Bank0
  75.         clrf    PORTA                           ; Initialize PORTA by clearing output data latches
  76.         clrf    PORTB                           ; Initialize PORTB by clearing output data latches
  77.         bsf             STATUS,RP0                      ; Bank1
  78.         movlw   0x06                            ; Configure all pins as digital inputs
  79.         movwf   ADCON1
  80.         movlw   b'00000001'                     ; Value used to initialize data direction
  81.         movwf   TRISA                           ; Set RA<0> as input, RA<5:1> as outputs
  82.                                                                 ; TRISA<7:6> are always read as '0'
  83.         clrf    TRISB
  84.         bcf             STATUS,RP0                      ; Bank0
  85.         movlw   B'0111111'                      ; Comienza en '0'
  86.         movwf   PORTB
  87.         clrf    Contador
  88.        
  89. ; Testeo del pulsador
  90. Testeo
  91.         btfss   PORTA,Pulsador          ; Testeamos si esta a '1' logico
  92.         goto    Testeo                          ; No, seguimos testeando               
  93.         call    Demora15                        ; Eliminamos efecto rebote
  94.         btfss   PORTA,Pulsador          ; Testeamos nuevamente
  95.         goto    Testeo                          ; Falsa alarma, seguimos testeando
  96.         incf    Contador,1                      ; Se ha pulsado, incrementamos contador
  97.         movwf   Contador                        ; Pasamos contador a W
  98.         call    BCD7SEG                         ; Llamamos tabla
  99.         movwf   PORTB                           ; Cargamos valor recibido  por Tabla en PORTB
  100.         btfsc   PORTA,Pulsador          ; Esperamos a que se suelte el pulsador
  101.         goto    $-1                                     ; No, PLC - 1, --> btfss
  102.         call    Demora15                        ; Eliminamos efecto rebote
  103.         btfsc   PORTA,Pulsador          ; Testeamos nuevamente
  104.         goto    $-4                                     ; No, falsa alarma, volvemos a testear a que se suelte
  105.         goto    Testeo                          ; Si, testeamos nuevamente
  106.        
  107. ;-------------------------------------------------------------
  108. ; Demora 15ms
  109. ; Generado con PDEL ver SP  r 1.0  el 04/03/2013 Hs 21:26:04
  110. ; Descripcion: Delay 15000 ciclos
  111. ;-------------------------------------------------------------
  112. Demora15
  113.             movlw     .21       ; 1 set numero de repeticion  (B)
  114.         movwf     PDel0     ; 1 |
  115. PLoop1  movlw     .142      ; 1 set numero de repeticion  (A)
  116.         movwf     PDel1     ; 1 |
  117. PLoop2  clrwdt              ; 1 clear watchdog
  118.         clrwdt              ; 1 ciclo delay
  119.         decfsz    PDel1,1   ; 1 + (1) es el tiempo 0  ? (A)
  120.         goto      PLoop2    ; 2 no, loop
  121.         decfsz    PDel0,1   ; 1 + (1) es el tiempo 0  ? (B)
  122.         goto      PLoop1    ; 2 no, loop
  123.         clrwdt              ; 1 ciclo delay
  124.         return              ; 2+2 Fin.
  125. ;-------------------------------------------------------------
  126.        
  127.        
  128.         END                       ; directive 'end of program'

Saludos y Gracias

Edit: Encontre el error, en la instruccion incf Contador,1 deberia ser incf Contador,0
« Última modificación: 30 de Abril de 2013, 18:49:05 por Miquel_S »
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado AleSergi

  • PIC16
  • ***
  • Mensajes: 209
Re: Display 7 Segmentos (SOLUCIONADO)
« Respuesta #1 en: 30 de Abril de 2013, 21:51:50 »
Hola Miguel, que bueno que encontraste el error solo. Consejo, reemplaza los 0 & 1 de esas instrucciones por sus nemónicos W & F, están en el archivo 16f873A.inc
Ayuda a minimizar estas distracciones.
en tu código donde dice:
    ;***** VARIABLE DEFINITIONS
    w_temp EQU   0x20 ; variable used for context saving
    w_temp1 EQU   0xA0 ; reserve bank1 equivalent of w_temp
    status_temp EQU   0x21 ; variable used for context saving
    pclath_temp EQU   0x22 ; variable used for context saving

si realmente es funcional por el empleo de interrupciones, las direcciones deben empezar en 0x70, que es la zona común y presente en todos los bancos, es la única forma que realmente funcione de manera correcta el 'servicio' de interrupciones.
Suerte con lo tuyo.-


 

anything