TODOPIC

Microcontroladores PIC => Almacén del Assembler => Mensaje iniciado por: Alan Valdivia en 23 de Septiembre de 2017, 23:24:11

Título: Ayuda con Cascada y Scroll - Matriz de LEDs 8x8 MAX7219
Publicado por: Alan Valdivia en 23 de Septiembre de 2017, 23:24:11
Buenas, como ya mencioné en un post pasado, estoy realizando el control de 4 matrices de LED's 8x8, controlando las letras que se elijen mediante el celular, con un módulo Bluetooth, programando todo en assembler, con el PIC16F88.

Estoy tratando de ponerlas en cascada, y que las letras se vayan desplazando por las matrices. Logré ponerlos en cascada, y almenos en el simulador de proteus y MPLAB, el programa funciona bien, pero cuando lo conecto en la realidad, no funciona, todas las matrices aparecen con todos sus LED's encendidos, y no entiendo por qué, en el simulador funciona perfecto. Revisé varias veces el conexionado, todos los CLK y CS de las matrices están conectados entre ellos, y conecté el DIN al pic, y a los demás DIN les conecté el DOUT del otro. (Adjunto foto del circuito, el de verdad y el simulado en proteus).

(https://image.ibb.co/ekJgb5/Matriz_proteus.png)
(https://lh4.googleusercontent.com/g4zwV3t8DhopLt_Zkr1kyfOrGcN9D3UPDFuvJhh_ocCNyx1MCZ3rGAM21UfXjwtrfVE-xnv0ZBrSIBc=w1680-h920-rw)
(https://lh3.googleusercontent.com/3g6ci-MObxBOxCTza1YLdOZzwMRH7OxNp52ZzSHTatNfkFBEUapR5melQxQXuicod5YIeTHKEMH8brs=w1680-h920-rw)
(https://lh5.googleusercontent.com/VbyTuHqtrwleyAd_PFnLCU7q9aR3ZZL5rLZTi2Z34O8k6sNPMZzK0baFYb-RYAC3m8M4EyyamTDJEwY=w1680-h920-rw)
(https://lh3.googleusercontent.com/f5B3tWFLB0TiNtPxk5pd947XW6t5xoZYagR0zkmovEhSpq5JXLwPsw2mvJ27L6jG4pJvl6SpBAGUO2U=w1680-h920-rw)


El programa a continuación lo hice solo para probar las matrices en cascada, el que tiene configurada la transmisión bluetooth y funciona bien, es otro. Lo único que hace el siguiente programa es escribir mi nombre (Alan), constantemente.

Código: [Seleccionar]
LIST        p=16F88             
#INCLUDE    <P16F88.INC> 
ERRORLEVEL  -302

__CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
__CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

CBLOCK 0x20
Timer
Register
Value
Register0
Value0
Register1
Value1
Register2
Value2
Register3
ENDC

CBLOCK 0x30
Value3
SendRegister
SendValue
Matrices
Matrices_temp
Temp
Contador
Letra
Temp1
ENDC

W_TEMP        EQU   0x7D
STATUS_TEMP   EQU   0x7E
PCLATH_TEMP   EQU   0x7F 

DATAEE        ORG  0x2100
    DE        "MCHP" 

RESET     ORG     0x0000           
          PAGESEL START
          GOTO    START     

ISR       ORG     0x0004           

          MOVWF   W_TEMP           
          MOVF    STATUS,W         
          MOVWF   STATUS_TEMP     
          MOVF    PCLATH,W         
          MOVWF   PCLATH_TEMP       

          MOVF    PCLATH_TEMP,W     
          MOVWF   PCLATH           
          MOVF    STATUS_TEMP,W     
          MOVWF   STATUS           
          SWAPF   W_TEMP,F
          SWAPF   W_TEMP,W         
          RETFIE   

START
movlw    b'01100001'
        BANKSEL OSCCON
        movwf    OSCCON
        btfss    OSCCON,IOFS
        goto    $-1
 
banksel PORTA
CLRF PORTA

banksel PORTB
CLRF PORTB

banksel ANSEL  
clrf ANSEL

banksel TRISA
clrf TRISA
clrf TRISB

banksel OPTION_REG
movlw b'10000111'
movwf OPTION_REG

banksel INTCON
clrf INTCON

banksel PIR1
clrf PIR1

banksel PIE1
clrf PIE1

banksel PIR2
clrf PIR2  

banksel PIE2
clrf PIE2

banksel PCON
clrf PCON

banksel ADCON0
clrf ADCON0

banksel ADCON1
movlw b'10000000'
movwf ADCON1

banksel PORTB
Setup
#define DIN PORTB,1
#define LOAD         PORTB,2
#define CLK PORTB,3

movlw .4
movwf Matrices
clrw
call SetDecodeMode
movlw 0x0f
call SetIntensity
movlw 0x07
call SetScanLimit
call Display_ON
clrw
call SetDisplayTest
clrf Matrices

Main
call Cambiar_Matriz
movlw 'A'
call Bucle_letra
call Delay_1s
call Cambiar_Matriz
movlw 'L'
call Bucle_letra
call Delay_1s
call Cambiar_Matriz
movlw 'A'
call Bucle_letra
call Delay_1s
call Cambiar_Matriz
movlw 'N'
call Bucle_letra
call Delay_1s
call Clear_All
call Delay_1s
clrf Matrices
goto Main

Values
movlw .4
xorwf Matrices,0
btfss STATUS,Z
goto $+4
movf Value, 0
movwf Value3
return
movlw .3
xorwf Matrices,0
btfss STATUS,Z
goto $+4
movf Value,0
movwf Value2
return
movlw .2
xorwf Matrices,0
btfss STATUS,Z
goto $+4
movf Value,0
movwf Value1
return
movf Value, 0
movwf Value0
return

Registers
movlw .4
xorwf Matrices,0
btfss STATUS,Z
goto $+4
movf Register, 0
movwf Register3
return
movlw .3
xorwf Matrices,0
btfss STATUS,Z
goto $+4
movf Register,0
movwf Register2
return
movlw .2
xorwf Matrices,0
btfss STATUS,Z
goto $+4
movf Register,0
movwf Register1
return
movf Register, 0
movwf Register0
return

Cambiar_Matriz
movlw .4
xorwf Matrices,0
btfsc STATUS,Z
goto Main
incf Matrices,1
return

;------------------------------------------------------------------------------------------------
; Retardos
;------------------------------------------------------------------------------------------------
Delay_1s
movlw .20
movwf Timer
call Delay_50ms
decfsz Timer,1
goto $-2
return

Delay_50ms
movlw .61
movwf TMR0
clrw
subwf TMR0,W
btfss STATUS,Z
goto $-3
return
;------------------------------------------------------------------------------------------------
; Enviar datos
;------------------------------------------------------------------------------------------------
Send

movf Matrices,0
movwf Matrices_temp
S1 call CS
            movlw .16
bcf LOAD
Send_Loop
bcf DIN
btfsc SendRegister, 7
bsf DIN
rlf SendValue, 1
rlf SendRegister, 1
bsf CLK
nop
bcf CLK
addlw 0xff
btfss STATUS, Z
goto Send_Loop
decfsz Matrices_temp,1
goto S1
bsf LOAD
return

CS
movlw .4
xorwf Matrices_temp,0
btfss STATUS,Z
goto $+6
movf Register3, 0
movwf SendRegister
movf Value3,0
movwf SendValue
return
movlw .3
xorwf Matrices_temp,0
btfss STATUS,Z
goto $+6
movf Register2, 0
movwf SendRegister
movf Value2,0
movwf SendValue
return
movlw .2
xorwf Matrices_temp,0
btfss STATUS,Z
goto $+6
movf Register1, 0
movwf SendRegister
movf Value1,0
movwf SendValue
return
movf Register0, 0
movwf SendRegister
movf Value0, 0
movwf SendValue
return
;------------------------------------------------------------------------------------------------
; Configurar decode mode
;------------------------------------------------------------------------------------------------
SetDecodeMode
movwf Value0
movwf Value1
movwf Value2
movwf Value3
movlw 0x09
movwf Register0
movwf Register1
movwf Register2
movwf Register3
goto Send
;------------------------------------------------------------------------------------------------
; Configurar intensidad
;------------------------------------------------------------------------------------------------
SetIntensity
movwf Value0
movwf Value1
movwf Value2
movwf Value3
movlw 0x0a
movwf Register0
movwf Register1
movwf Register2
movwf Register3
goto Send
;------------------------------------------------------------------------------------------------
; Configurar columnas
;------------------------------------------------------------------------------------------------
SetScanLimit
movwf Value0
movwf Value1
movwf Value2
movwf Value3
movlw 0x0b
movwf Register0
movwf Register1
movwf Register2
movwf Register3
goto Send
;------------------------------------------------------------------------------------------------
; Configurar Shutdown
;------------------------------------------------------------------------------------------------
Display_ON
movlw 0x01
goto SetShutdown

Display_OFF
movlw 0x00

SetShutdown
movwf Value0
movwf Value1
movwf Value2
movwf Value3
movlw 0x0c
movwf Register0
movwf Register1
movwf Register2
movwf Register3
goto Send
;------------------------------------------------------------------------------------------------
; Configurar Test
;------------------------------------------------------------------------------------------------
SetDisplayTest
movwf Value0
movwf Value1
movwf Value2
movwf Value3
movlw 0x0f
movwf Register0
movwf Register1
movwf Register2
movwf Register3
goto Send
;------------------------------------------------------------------------------------------------
; Clarear
;------------------------------------------------------------------------------------------------
Clear_All
movlw .4
movwf Contador
movlw .1
movwf Matrices
r1 call Clear
decfsz Contador,1
goto $+2
return
incf Matrices,1
goto r1

Clear
movlw 0x00
movwf Temp
movlw 0x08
movwf Register
Bucle
call Registers
movf Temp, w
movwf Value
call Values
call Send
decfsz Register, 1
goto Bucle
return
;------------------------------------------------------------------------------------------------
; Letras
;------------------------------------------------------------------------------------------------
Bucle_letra
movwf Letra
movlw 0x01
movwf Register
r2 call Registers
call Elegir_letra
movwf Value
call Values
call Send
incf Contador,1
incf Register,1
movlw 0x09
xorwf Register,0
btfss STATUS,Z
goto r2
clrf Contador
return

Elegir_letra
movlw .4
movwf PCLATH
movlw 'A'
xorwf Letra,0
btfss STATUS,Z
goto $+3
call A_
return
movlw 'L'
xorwf Letra,0
btfss STATUS,Z
goto $+3
call L_
return
call N_
return

;------------------------------------------------------------------------------------------------
; Letras
;------------------------------------------------------------------------------------------------
ORG 0x400
A_
movf Contador,0
addwf PCL,f
retlw b'00000000'
retlw b'01111111'
retlw b'10001000'
retlw b'10001000'
retlw b'10001000'
retlw b'10001000'
retlw b'01111111'
retlw b'00000000'

L_
movf Contador,0
addwf PCL,f
retlw b'00000000'
retlw b'11111111'
retlw b'00000001'
retlw b'00000001'
retlw b'00000001'
retlw b'00000001'
retlw b'00000000'
retlw b'00000000'

N_
movf Contador,0
addwf PCL,f
retlw b'00000000'
retlw b'11111111'
retlw b'01110000'
retlw b'00111000'
retlw b'00011100'
retlw b'00001110'
retlw b'11111111'
retlw b'00000000'


END

En fin, si alguno tuvo un problema similar, o sabe la solución, por favor explíqueme que estoy haciendo mal.

Esto es lo que se ve al conectarlo...

(https://lh4.googleusercontent.com/NdLV6DQvzqUJSMrH96IR2wesWN_CvII1YJB8F2O2Gl_UWxg5Fh7FfQF-cO6ucbhwuDTtkGIubTd7bD0=w1680-h920-rw)

PD: Les dejo adjunto el .hex y el .dsn de proteus por si quieren testearlo.
Título: Re:Ayuda con Cascada y Scroll - Matriz de LEDs 8x8 MAX7219
Publicado por: KILLERJC en 24 de Septiembre de 2017, 11:58:18
Las simulaciones son tan buenas que tenes el MCLR ON , no tenes nada puesto en el MCLR y aun asi el micro funciona. Nunca confies plenamente en las simulaciones.

El circuito que tenes realizado, es asi ? Ya que presenta  que el micro siempre esta reseteado. Pienso que tambien deberias tener resistencias de pull-down en algunos pines, ya que sino estos estarian flotando hasta que el micro comience a dar las señales.

PD: Proteus es famoso por no hacerle caso al oscilador, ni tampoco a los FUSES ( Config ) simplemente eso lo omite.