• AVR Freaks

Hot!Pic 16F15344 and Max7219 to drive 7 segment display in asm

Page: 123 > Showing page 1 of 3
Author
The alchmiste
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2018/03/14 02:55:48
  • Location: France
  • Status: offline
2018/03/15 00:10:15 (permalink)
0

Pic 16F15344 and Max7219 to drive 7 segment display in asm

Hello everyone,
 
I'm actually strugling with getting a 4 * 7 segment display drived by the Max7219 connected to a pic 16F15344.

I'm actually programing in asm as I feel it more detailed and I better understand what's hapening in IC and what I'm doing.
After reading datasheet of pic16F15344 and Max7219, I've created an asm code and made my hardware connection. 
The code is buiding without any issue and getting loaded into the pic throught pickit3 but after scratching my head for hours and checking my connections, I've not been able to find out where is the issue and the 7segment display is still blank and don't show the value 1991 as I would like to display. 
Can anyone help me to understand where is the issue in my code or share your code to make it working? 

My code:

; TODO INSERT INCLUDE CODE HERE
list p=16f15344 ; list directive to define processor
#include <p16f15344.inc> ; processor specific variable definitions

; TODO INSERT CONFIG HERE

__CONFIG _CONFIG1, _RSTOSC_HFINT1
__CONFIG _CONFIG3, _WDTE_OFF
__CONFIG _CONFIG4, _LVP_OFF
__CONFIG _CONFIG5, _CP_OFF

; _RSTOSC_HFINT1 -> permet l'activation de l'oscillateur interne a une frequence de 1Mhz soit 1 microS/osccillation
; _LVP_OFF -> permet la programmation a faible tenssion
; _CP_OFF -> Ne cache pas le code
; _WDT_OFF -> Desactive le Watch Dog


; TODO PLACE VARIABLE DEFINITIONS GO HERE

;***** VARIABLE DEFINITIONS at the bank 0 begining at adress 0x20
cblock 0X20
registre_Démarrage : 1
Donnée_Demmarrage : 1
Donnée_Fin : 1

registre_Parametrage : 1
Donnée_ParametrageBCD : 1

registre_Intensite : 1
Donnée_Intensite : 1

registre_nbrDigit : 1
Donnée_nbrDigit : 1

registre_Test : 1
Donnée_Test : 1

registre_Digit : 1
Donnée_Digit : 1

registre : 1
donnee : 1
endc
;*******************************************************************************
; Reset Vector
;*******************************************************************************

org 00H ; processor reset vector
goto START ; go to beginning of program

; TODO INSERT ISR HERE

;*******************************************************************************
; MAIN PROGRAM
;*******************************************************************************


START

; Initialisaton des variables


banksel registre_Démarrage

movlw 0x0c
movwf registre_Démarrage
movlw 0x03
movwf Donnée_Demmarrage

movlw 0x09
movwf registre_Parametrage
movlw 0x0F
movwf Donnée_ParametrageBCD

movlw 0x0A
movwf registre_Intensite
movlw 0x07
movwf Donnée_Intensite

movlw 0x0B
movwf registre_nbrDigit
movlw 0x03
movwf Donnée_nbrDigit

movlw 0x0F
movwf registre_Test
movlw 0x01
movwf Donnée_Test

movlw 0x01
movwf registre_Digit
movlw 0x01
movwf Donnée_Digit



; Initialisation des paramettres SPI

banksel RB4PPS
movlw 0x16 ;On associe SDO a RB4 ( les données transmises)
movwf RB4PPS

banksel RB5PPS
movlw 0x15 ;On associe SCK a RB5 (l'horloge)
movwf RB5PPS

banksel TRISB
movlw 0x8F ;RB4 et RB5 et RB6 en sortie tout le rest en entrée
movwf TRISB

banksel SSP1CON1
movlw 0x20 ;On active le SPI
movwf SSP1CON1

Banksel SSP1STAT ; On parametre l'horloge et l'echantillonage des données
clrf SSP1STAT

banksel PORTB
clrf PORTB ;on efface les valeurs du port B


; Debut du parametrage Driver
;1
banksel registre_Démarrage
movf registre_Démarrage,w
movwf registre

banksel Donnée_Demmarrage
movf Donnée_Demmarrage,w
movwf donnee
call RoutineveriffinSDI


;2
banksel registre_Parametrage
movf registre_Parametrage,w
movwf registre

banksel Donnée_ParametrageBCD
movf Donnée_ParametrageBCD,w
movwf donnee
call RoutineveriffinSDI


;3
banksel registre_Intensite
movf registre_Intensite,w
movwf registre

banksel Donnée_Intensite
movf Donnée_Intensite,w
movwf donnee
call RoutineveriffinSDI



;4
banksel registre_nbrDigit
movf registre_nbrDigit,w
movwf registre

banksel Donnée_nbrDigit
movf Donnée_nbrDigit,w
movwf donnee
call RoutineveriffinSDI



;5
banksel registre_Test
movf registre_Test,w
movwf registre

banksel Donnée_Test
movf Donnée_Test,w
movwf donnee
call RoutineveriffinSDI

banksel registre_Test
movf registre_Test,w
movwf registre


movlw 0x00 ;fin du test
movwf donnee
call RoutineveriffinSDI

; Debut du programme envoie des chiffres

; Chiffre 1

movlw 0x01
banksel registre
movwf registre

movlw 0x01
movwf donnee
call RoutineveriffinSDI

; Chiffre 2

movlw 0x02
banksel registre
movwf registre

movlw 0x09
movwf donnee
call RoutineveriffinSDI



; Chiffre 3

movlw 0x03
banksel registre
movwf registre

movlw 0x09
movwf donnee
call RoutineveriffinSDI


; Chiffre 4

movlw 0x04
banksel registre
movwf registre

movlw 0x01
movwf donnee
call RoutineveriffinSDI
sleep

RoutineveriffinSDI
banksel PORTB
bcf PORTB,6
banksel registre
movf registre,w
banksel SSP1BUF
movwf SSP1BUF
banksel SSP1STAT
btfss SSP1STAT,0
goto $-1
banksel SSP1BUF
movf SSP1BUF,w

banksel donnee
movf donnee,w
banksel SSP1BUF
movwf SSP1BUF
banksel SSP1STAT
btfss SSP1STAT,0
goto $-1
banksel PORTB
bsf PORTB,6

return
end


Thanks a lot
post edited by The alchmiste - 2018/03/18 03:45:08
#1

53 Replies Related Threads

    jack@kksound
    code tags!
    • Total Posts : 3198
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 11:14:23 (permalink)
    0
    Do you have the LED current set resistor on pin 18 of the MAX7219? It should be about 10K (adjust to get desired maximun segment current) to Vdd.
    #2
    The alchmiste
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2018/03/14 02:55:48
    • Location: France
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 12:14:05 (permalink)
    0
    Hi Jack,
     
    I've done it even if it's not mandatory as the intensity register 0x0A is supporting that function I think, and in my code I've intialized it to the midle value which is 0x07 data:
    movlw 0x0A
    movwf registre_Intensite
    movlw 0x07
    movwf Donnée_Intensite
    #3
    jack@kksound
    code tags!
    • Total Posts : 3198
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 12:22:02 (permalink)
    +1 (1)
    Oh no, the external resistor is absolutely necessary. The internsity register only sets the level relative to the current established by the resistor. From the datasheet:
    Digital control of display brightness is provided by an internal pulse-width modulator, which is controlled by the lower nibble of the intensity register. The modulator scales the average segment current in 16 steps from a maximum of 31/32 down to 1/32 of the peak current set by RSET (15/16 to 1/16 on MAX7221).

    Notice the reference to the peak current set by RSET (the external resistor).
    The paragraph that preceeds this explains the value of RSET:
    The MAX7219/MAX7221 allow display brightness to be controlled with an external resistor (RSET) connected between V+ and ISET. The peak current sourced from the segment drivers is nominally 100 times the current entering ISET

    #4
    jack@kksound
    code tags!
    • Total Posts : 3198
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 12:26:26 (permalink)
    0
    Also the MAX7219 is rated at a maximum  minimum clock speed of 100Khz period of 100ns. Are you exceeding this?
     
    edit: messed up the speed, corrected to period (from datasheet)
     
    Actually this is probably NOT an issue as the pic can't do SPI at over 10 Mhz, sorry.
    post edited by jack@kksound - 2018/03/15 12:29:34
    #5
    jack@kksound
    code tags!
    • Total Posts : 3198
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 12:32:26 (permalink)
    0
    How are you configuring the SPI? the MAX7219 samples input data on the rising edge so the SPI must make the data stable before the clock rising edge (change on the fall).
    #6
    The alchmiste
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2018/03/14 02:55:48
    • Location: France
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 13:34:01 (permalink)
    0
    Hi Jack,
     
    Ok thanks for this info regarding Rset I was thinking that it was kind of optional, but anyway I've set it.
     
    For what concerns the frequency:
     - I ve configured the clock of my pic 16f15344 with __CONFIG _CONFIG1, _RSTOSC_HFINT1, which should set the internal oscillator at a frequency of 1Mhz => to 1oscillations every 1 micro seconds and Tcp min for Max7219 is 100ns, so I'm 10 times on top of the minimum supported by Max7219
     
    - For the SPI clock setup I've done it through the SSP1CON1 register where the 4 first bits are set to 0 as I've cleared the register and this should set the Tcy at 4microseconds
     
    For what concern the SPI configuration:
    - I've configured the RB4 through PPS to SDO peripherial
    - I've configured the RB5 through PPS to SCK peripherial
    - I've configured the RB6 as the Load
    - I've set all the SSP1STAT register to 0 as only the 2 last bits are writable, so bit 7 is at 0 to make samples capture on the midle of the clock idle and bit 6 is at 0 to have a data output on every rising edge of the clock  from 0 to 1
     
    post edited by The alchmiste - 2018/08/13 12:02:39
    #7
    jack@kksound
    code tags!
    • Total Posts : 3198
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 14:25:26 (permalink)
    0
     data output on every rising edge of the clock  from 0 to 1

    Exactly opposite of what the 7219 wants: 
    . On CLK’s rising edge, data is shifted into the internal shift register.

    This means the data is "sampled" on the rising (o to 1) transition of the clock so obviously the data cannot be "output" on this same rising edge, it must be output before the rising edge (by at least the data setup time of the 7219).
    I think the datasheet is very clear on this.
    #8
    The alchmiste
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2018/03/14 02:55:48
    • Location: France
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 14:55:44 (permalink)
    0
    Ok thanks, just made this change on SSP1STAT register by putting 0x40, but still don't solve the issue, 
    I've used my logic analyzer to see what's hapening on the CLK and SDO pin and looks verry strange as I don't see a constante SLK
     
    #9
    dan1138
    Super Member
    • Total Posts : 3123
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 15:00:30 (permalink)
    0
    The alchmiste

    Hello everyone,

    I'm actually strugling with getting a 4 * 7 segment display drived by the Max7219 connected to a pic 16F15344.

    I'm actually programing in asm as I feel it more detailed and I better understand what's hapening in IC and what I'm doing.
    After reading datasheet of pic16F15344 and Max7219, I've created an asm code and made my hardware connection.
    The code is buiding without any issue and getting loaded into the pic throught pickit3 but after scratching my head for hours and checking my connections, I've not been able to find out where is the issue and the 7segment display is still blank and don't show the value 1991 as I would like to display.
    Can anyone help me to understand where is the issue in my code or share your code to make it working?

    My code:

    ; TODO INSERT INCLUDE CODE HERE
        list p=16f15344 ; list directive to define processor
        #include <p16f15344.inc> ; processor specific variable definitions

    ; TODO INSERT CONFIG HERE

        __CONFIG _CONFIG1, _RSTOSC_HFINT1
        __CONFIG _CONFIG3, _WDTE_OFF
        __CONFIG _CONFIG4, _LVP_OFF
        __CONFIG _CONFIG5, _CP_OFF

    ; _RSTOSC_HFINT1 -> permet l'activation de l'oscillateur interne a une frequence de 1Mhz soit 1 microS/osccillation
    ; _LVP_OFF -> permet la programmation a faible tenssion
    ; _CP_OFF -> Ne cache pas le code
    ; _WDT_OFF -> Desactive le Watch Dog


    ; TODO PLACE VARIABLE DEFINITIONS GO HERE

    ;***** VARIABLE DEFINITIONS at the bank 0 begining at adress 0x20
        cblock 0X20
            registre_Démarrage : 1
            Donnée_Demmarrage : 1
            Donnée_Fin : 1

            registre_Parametrage : 1
            Donnée_ParametrageBCD : 1

            registre_Intensite : 1
            Donnée_Intensite : 1

            registre_nbrDigit : 1
            Donnée_nbrDigit : 1

            registre_Test : 1
            Donnée_Test : 1

            registre_Digit : 1
            Donnée_Digit : 1

            registre : 1
            donnee : 1
        endc
    ;*******************************************************************************
    ; Reset Vector
    ;*******************************************************************************

        org     00H     ; processor reset vector
        goto    START   ; go to beginning of program

    ; TODO INSERT ISR HERE

    ;*******************************************************************************
    ; MAIN PROGRAM
    ;*******************************************************************************


    START:

    ; Initialisaton des variables


        banksel registre_Démarrage

        movlw   0x0c
        movwf   registre_Démarrage
        movlw   0x03
        movwf   Donnée_Demmarrage

        movlw   0x09
        movwf   registre_Parametrage
        movlw   0x0F
        movwf   Donnée_ParametrageBCD

        movlw   0x0A
        movwf   registre_Intensite
        movlw   0x07
        movwf   Donnée_Intensite

        movlw   0x0B
        movwf   registre_nbrDigit
        movlw   0x03
        movwf   Donnée_nbrDigit

        movlw   0x0F
        movwf   registre_Test
        movlw   0x01
        movwf   Donnée_Test

        movlw   0x01
        movwf   registre_Digit
        movlw   0x01
        movwf   Donnée_Digit

    ; Initialisation des paramettres SPI

        banksel RB4PPS
        movlw   0x16    ;On associe SDO a RB4 ( les données transmises)
        movwf   RB4PPS

        banksel RB5PPS
        movlw   0x15    ;On associe SCK a RB5 (l'horloge)
        movwf   RB5PPS

        banksel TRISB
        movlw   0x8F    ;RB4 et RB5 et RB6 en sortie tout le rest en entrée
        movwf   TRISB

        banksel SSP1CON1
        movlw   0x20    ;On active le SPI
        movwf   SSP1CON1

        Banksel     SSP1STAT    ; On parametre l'horloge et l'echantillonage des données
        clrf    SSP1STAT

        banksel PORTB
        clrf    PORTB   ;on efface les valeurs du port B

    ; Debut du parametrage Driver
    ;1
        banksel registre_Démarrage
        movf    registre_Démarrage,w
        movwf   registre

        banksel Donnée_Demmarrage
        movf    Donnée_Demmarrage,w
        movwf   donnee
        call    RoutineveriffinSDI

    ;2
        banksel registre_Parametrage
        movf    registre_Parametrage,w
        movwf   registre

        banksel Donnée_ParametrageBCD
        movf    Donnée_ParametrageBCD,w
        movwf   donnee
        call    RoutineveriffinSDI

    ;3
        banksel registre_Intensite
        movf    registre_Intensite,w
        movwf   registre

        banksel Donnée_Intensite
        movf    Donnée_Intensite,w
        movwf   donnee
        call    RoutineveriffinSDI

    ;4
        banksel registre_nbrDigit
        movf    registre_nbrDigit,w
        movwf   registre

        banksel Donnée_nbrDigit
        movf    Donnée_nbrDigit,w
        movwf   donnee
        call    RoutineveriffinSDI

    ;5
        banksel registre_Test
        movf    registre_Test,w
        movwf   registre

        banksel Donnée_Test
        movf    Donnée_Test,w
        movwf   donnee
        call    RoutineveriffinSDI

        banksel registre_Test
        movf    registre_Test,w
        movwf   registre

        movlw   0x00    ;fin du test
        movwf   donnee
        call    RoutineveriffinSDI

    ; Debut du programme envoie des chiffres

    ; Chiffre 1

        movlw   0x01
        banksel registre
        movwf   registre

        movlw   0x01
        movwf   donnee
        call    RoutineveriffinSDI

    ; Chiffre 2

        movlw   0x02
        banksel registre
        movwf   registre

        movlw   0x09
        movwf   donnee
        call    RoutineveriffinSDI

    ; Chiffre 3

        movlw   0x03
        banksel registre
        movwf   registre

        movlw   0x09
        movwf   donnee
        call    RoutineveriffinSDI

    ; Chiffre 4

        movlw   0x04
        banksel registre
        movwf   registre

        movlw   0x01
        movwf   donnee
        call    RoutineveriffinSDI
        sleep

    RoutineveriffinSDI:
        banksel PORTB
        bcf     PORTB,6
        banksel registre
        movf    registre,w
        banksel SSP1BUF
        movwf   SSP1BUF
        banksel SSP1STAT
        btfss   SSP1STAT,0
        goto    $-1
        banksel SSP1BUF
        movf    SSP1BUF,w

        banksel donnee
        movf    donnee,w
        banksel SSP1BUF
        movwf   SSP1BUF
        banksel SSP1STAT
        btfss   SSP1STAT,0
        goto    $-1
        banksel PORTB
        bsf     PORTB,6

        return
        end


    Thanks a lot


    This is a link to a GitHub project that does an assembly language implantation for a MAX7219.

    It uses a bit-bang SPI interface and it is for a PIC16F876A but it does work.
    post edited by dan1138 - 2018/03/15 17:41:57
    #10
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/15 15:01:14 (permalink)
    0
    The alchmiste
    ...
    I've used my logic analyzer to see what's hapening on the CLK and SDO pin and looks verry strange as I don't see a constante SLK

    Do you mean SCLK?
    It only pulses when data is being transferred.

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #11
    Gerald1
    Super Member
    • Total Posts : 338
    • Reward points : 0
    • Joined: 2009/05/12 06:50:37
    • Location: Wien, Austria
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/16 15:21:30 (permalink)
    0
    Hi,
    Here you will find a reference design and tutorial:
     
    https://www.maximintegrat...oard/6251.html/tb_tab1
    https://os.mbed.com/teams...tegrated/code/MAX7219/
    https://os.mbed.com/teams...code/MAXREFDES99_demo/
     
    Best Regards
    Gerald
    ---
    post edited by Gerald1 - 2018/03/16 15:32:47

    SG
    ---
    Daily the PC greets:
    "Press Enter!"; "Coward!"
    ---

    #12
    The alchmiste
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2018/03/14 02:55:48
    • Location: France
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/17 01:56:29 (permalink)
    0
    dan1138
    The alchmiste

    Hello everyone,

    I'm actually strugling with getting a 4 * 7 segment display drived by the Max7219 connected to a pic 16F15344.

    I'm actually programing in asm as I feel it more detailed and I better understand what's hapening in IC and what I'm doing.
    After reading datasheet of pic16F15344 and Max7219, I've created an asm code and made my hardware connection.
    The code is buiding without any issue and getting loaded into the pic throught pickit3 but after scratching my head for hours and checking my connections, I've not been able to find out where is the issue and the 7segment display is still blank and don't show the value 1991 as I would like to display.
    Can anyone help me to understand where is the issue in my code or share your code to make it working?

    My code:

    ; TODO INSERT INCLUDE CODE HERE
        list p=16f15344 ; list directive to define processor
        #include <p16f15344.inc> ; processor specific variable definitions

    ; TODO INSERT CONFIG HERE

        __CONFIG _CONFIG1, _RSTOSC_HFINT1
        __CONFIG _CONFIG3, _WDTE_OFF
        __CONFIG _CONFIG4, _LVP_OFF
        __CONFIG _CONFIG5, _CP_OFF

    ; _RSTOSC_HFINT1 -> permet l'activation de l'oscillateur interne a une frequence de 1Mhz soit 1 microS/osccillation
    ; _LVP_OFF -> permet la programmation a faible tenssion
    ; _CP_OFF -> Ne cache pas le code
    ; _WDT_OFF -> Desactive le Watch Dog


    ; TODO PLACE VARIABLE DEFINITIONS GO HERE

    ;***** VARIABLE DEFINITIONS at the bank 0 begining at adress 0x20
        cblock 0X20
            registre_Démarrage : 1
            Donnée_Demmarrage : 1
            Donnée_Fin : 1

            registre_Parametrage : 1
            Donnée_ParametrageBCD : 1

            registre_Intensite : 1
            Donnée_Intensite : 1

            registre_nbrDigit : 1
            Donnée_nbrDigit : 1

            registre_Test : 1
            Donnée_Test : 1

            registre_Digit : 1
            Donnée_Digit : 1

            registre : 1
            donnee : 1
        endc
    ;*******************************************************************************
    ; Reset Vector
    ;*******************************************************************************

        org     00H     ; processor reset vector
        goto    START   ; go to beginning of program

    ; TODO INSERT ISR HERE

    ;*******************************************************************************
    ; MAIN PROGRAM
    ;*******************************************************************************


    START:

    ; Initialisaton des variables


        banksel registre_Démarrage

        movlw   0x0c
        movwf   registre_Démarrage
        movlw   0x03
        movwf   Donnée_Demmarrage

        movlw   0x09
        movwf   registre_Parametrage
        movlw   0x0F
        movwf   Donnée_ParametrageBCD

        movlw   0x0A
        movwf   registre_Intensite
        movlw   0x07
        movwf   Donnée_Intensite

        movlw   0x0B
        movwf   registre_nbrDigit
        movlw   0x03
        movwf   Donnée_nbrDigit

        movlw   0x0F
        movwf   registre_Test
        movlw   0x01
        movwf   Donnée_Test

        movlw   0x01
        movwf   registre_Digit
        movlw   0x01
        movwf   Donnée_Digit

    ; Initialisation des paramettres SPI

        banksel RB4PPS
        movlw   0x16    ;On associe SDO a RB4 ( les données transmises)
        movwf   RB4PPS

        banksel RB5PPS
        movlw   0x15    ;On associe SCK a RB5 (l'horloge)
        movwf   RB5PPS

        banksel TRISB
        movlw   0x8F    ;RB4 et RB5 et RB6 en sortie tout le rest en entrée
        movwf   TRISB

        banksel SSP1CON1
        movlw   0x20    ;On active le SPI
        movwf   SSP1CON1

        Banksel     SSP1STAT    ; On parametre l'horloge et l'echantillonage des données
        clrf    SSP1STAT

        banksel PORTB
        clrf    PORTB   ;on efface les valeurs du port B

    ; Debut du parametrage Driver
    ;1
        banksel registre_Démarrage
        movf    registre_Démarrage,w
        movwf   registre

        banksel Donnée_Demmarrage
        movf    Donnée_Demmarrage,w
        movwf   donnee
        call    RoutineveriffinSDI

    ;2
        banksel registre_Parametrage
        movf    registre_Parametrage,w
        movwf   registre

        banksel Donnée_ParametrageBCD
        movf    Donnée_ParametrageBCD,w
        movwf   donnee
        call    RoutineveriffinSDI

    ;3
        banksel registre_Intensite
        movf    registre_Intensite,w
        movwf   registre

        banksel Donnée_Intensite
        movf    Donnée_Intensite,w
        movwf   donnee
        call    RoutineveriffinSDI

    ;4
        banksel registre_nbrDigit
        movf    registre_nbrDigit,w
        movwf   registre

        banksel Donnée_nbrDigit
        movf    Donnée_nbrDigit,w
        movwf   donnee
        call    RoutineveriffinSDI

    ;5
        banksel registre_Test
        movf    registre_Test,w
        movwf   registre

        banksel Donnée_Test
        movf    Donnée_Test,w
        movwf   donnee
        call    RoutineveriffinSDI

        banksel registre_Test
        movf    registre_Test,w
        movwf   registre

        movlw   0x00    ;fin du test
        movwf   donnee
        call    RoutineveriffinSDI

    ; Debut du programme envoie des chiffres

    ; Chiffre 1

        movlw   0x01
        banksel registre
        movwf   registre

        movlw   0x01
        movwf   donnee
        call    RoutineveriffinSDI

    ; Chiffre 2

        movlw   0x02
        banksel registre
        movwf   registre

        movlw   0x09
        movwf   donnee
        call    RoutineveriffinSDI

    ; Chiffre 3

        movlw   0x03
        banksel registre
        movwf   registre

        movlw   0x09
        movwf   donnee
        call    RoutineveriffinSDI

    ; Chiffre 4

        movlw   0x04
        banksel registre
        movwf   registre

        movlw   0x01
        movwf   donnee
        call    RoutineveriffinSDI
        sleep

    RoutineveriffinSDI:
        banksel PORTB
        bcf     PORTB,6
        banksel registre
        movf    registre,w
        banksel SSP1BUF
        movwf   SSP1BUF
        banksel SSP1STAT
        btfss   SSP1STAT,0
        goto    $-1
        banksel SSP1BUF
        movf    SSP1BUF,w

        banksel donnee
        movf    donnee,w
        banksel SSP1BUF
        movwf   SSP1BUF
        banksel SSP1STAT
        btfss   SSP1STAT,0
        goto    $-1
        banksel PORTB
        bsf     PORTB,6

        return
        end


    Thanks a lot


    This is a link to a GitHub project that does an assembly language implantation for a MAX7219.

    It uses a bit-bang SPI interface and it is for a PIC16F876A but it does work.



    Thanks qɥb, I've check this code but it's not using the SPI peripherial, it seems to use the rotate left funtion to send the data


    #13
    The alchmiste
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2018/03/14 02:55:48
    • Location: France
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/17 01:59:07 (permalink)
    0
    qɥb
    The alchmiste
    ...
    I've used my logic analyzer to see what's hapening on the CLK and SDO pin and looks verry strange as I don't see a constante SLK

    Do you mean SCLK?
    It only pulses when data is being transferred.


    Yes sorry you're right, I wanted to say SCK
    For the output sensed with the logic analyzer it's always hight. The reason why the output was strang was due to the fact that I've not connected the gnd (shame on me)...
    Keep you posted with the evolution
    #14
    The alchmiste
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2018/03/14 02:55:48
    • Location: France
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/17 02:03:27 (permalink)
    0
    geralds
    Hi,
    Here you will find a reference design and tutorial:
     
    https://www.maximintegrat...oard/6251.html/tb_tab1
    https://os.mbed.com/teams...tegrated/code/MAX7219/
    https://os.mbed.com/teams...code/MAXREFDES99_demo/
     
    Best Regards
    Gerald
    ---


    Thanks Gerald,
     
    Actually on these links th code is in C++ language I would like to get it in asm with the peripherial setup.
    #15
    MBedder
    Circuit breaker
    • Total Posts : 6767
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/17 03:33:59 (permalink)
    #16
    The alchmiste
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2018/03/14 02:55:48
    • Location: France
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/17 04:34:58 (permalink)
    0
    MBedder
    Check this - http://www.picmicrolab.co...6f876-microcontroller/


     Thanks Mbedder, Yes already checked it but it's not using the SPI peripheral.
    #17
    1and0
    Access is Denied
    • Total Posts : 9316
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/17 05:03:06 (permalink)
    0
    First, I really really hate this forum, as it is going to take several tries to get this completely posted here. :(
     
    I think you need to setup your SPI with SMP=0, CKP=0, and CKE=1, which I think Jack got you corrected this; if not, replace this
    banksel SSP1CON1
    movlw 0x20 ;On active le SPI
    movwf SSP1CON1
     
    Banksel SSP1STAT ; On parametre l'horloge et l'echantillonage des données
    clrf SSP1STAT

    with this
     banksel SSP1STAT
    movlw b'01000000' ; SMP=0, CKE=1
    movwf SSP1STAT
    movlw b'00100000' ; enable SPI, CKP=0
    movwf SSP1CON1

    Also, note I setup the SPI before enabling it; i.e. write SSP1STAT before SSP1CON1.
     
    I think your bug is you did not clear BF after sending the second byte, so replace your RoutineveriffinSDI routine
    RoutineveriffinSDI
    banksel PORTB
    bcf PORTB,6
     
    banksel registre
    movf registre,w
    banksel SSP1BUF
    movwf SSP1BUF
     
    banksel SSP1STAT
    btfss SSP1STAT,0
    goto $-1
    banksel SSP1BUF
    movf SSP1BUF,w
    ;
    banksel donnee
    movf donnee,w
    banksel SSP1BUF
    movwf SSP1BUF
     
    banksel SSP1STAT
    btfss SSP1STAT,0
    goto $-1
     
    banksel PORTB
    bsf PORTB,6
    return

    with this
    #define MAX_CS LATB,6 ; use LATx for output
    RoutineveriffinSDI
    banksel LATB
    bcf MAX_CS
     
    banksel registre ; actually this banksel is unecessary
    movf registre,w
    banksel SSP1BUF
    movwf SSP1BUF
     
    btfss SSP1STAT,BF ; use bit symbol BF
    goto $-1
    movf SSP1BUF,w
    ;
    banksel donnee
    movf donnee,w
    banksel SSP1BUF
    movwf SSP1BUF
     
    btfss SSP1STAT,BF
    goto $-1
    movf SSP1BUF,w ; add this line to clear BF
     
    banksel LATB
    bsf MAX_CS
    return

    Edit: I got my code all clear, neat, and aligned, but this stupid forum messed it all up. Sorry, I'm not going to fix it.
    post edited by 1and0 - 2018/03/17 05:06:53
    #18
    Gerald1
    Super Member
    • Total Posts : 338
    • Reward points : 0
    • Joined: 2009/05/12 06:50:37
    • Location: Wien, Austria
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/17 05:09:03 (permalink)
    0
    The alchmiste
    MBedder
    Check this - http://www.picmicrolab.co...6f876-microcontroller/


    Thanks Mbedder, Yes already checked it but it's not using the SPI peripheral.


    Can you please give us some details about e.g. schematics....
    Yes i know that is in c++ language. But this is an example for you how you can create your asm source.
    The construct is the same.
    Have you seen how many command lines you need? Please see this as a template.
     
    Best Regards
    Gerald
    --

    SG
    ---
    Daily the PC greets:
    "Press Enter!"; "Coward!"
    ---

    #19
    The alchmiste
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2018/03/14 02:55:48
    • Location: France
    • Status: offline
    Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/17 07:29:24 (permalink)
    0
    1and0
    First, I really really hate this forum, as it is going to take several tries to get this completely posted here. :(
     
    I think you need to setup your SPI with SMP=0, CKP=0, and CKE=1, which I think Jack got you corrected this; if not, replace this
    banksel SSP1CON1
    movlw 0x20 ;On active le SPI
    movwf SSP1CON1
     
     
     
    Banksel SSP1STAT ; On parametre l'horloge et l'echantillonage des données
     
    clrf SSP1STAT

    with this
     banksel SSP1STAT
    movlw b'01000000' ; SMP=0, CKE=1
    movwf SSP1STAT
    movlw b'00100000' ; enable SPI, CKP=0
    movwf SSP1CON1

    Also, note I setup the SPI before enabling it; i.e. write SSP1STAT before SSP1CON1.
     
    I think your bug is you did not clear BF after sending the second byte, so replace your RoutineveriffinSDI routine
    RoutineveriffinSDI
    banksel PORTB
    bcf PORTB,6
     
     
     
    banksel registre
    movf registre,w
    banksel SSP1BUF
    movwf SSP1BUF
     
     
     
    banksel SSP1STAT
    btfss SSP1STAT,0
    goto $-1
    banksel SSP1BUF
    movf SSP1BUF,w
    ;
    banksel donnee
    movf donnee,w
    banksel SSP1BUF
    movwf SSP1BUF
     
     
     
    banksel SSP1STAT
    btfss SSP1STAT,0
    goto $-1
     
     
     
    banksel PORTB
    bsf PORTB,6
    return

    with this
    #define MAX_CS LATB,6 ; use LATx for output
    RoutineveriffinSDI
    banksel LATB
    bcf MAX_CS
     
     
     
    banksel registre ; actually this banksel is unecessary
    movf registre,w
    banksel SSP1BUF
    movwf SSP1BUF
     
     
     
    btfss SSP1STAT,BF ; use bit symbol BF
    goto $-1
    movf SSP1BUF,w
    ;
    banksel donnee
    movf donnee,w
    banksel SSP1BUF
    movwf SSP1BUF
     
     
     
    btfss SSP1STAT,BF
    goto $-1
    movf SSP1BUF,w ; add this line to clear BF
     
     
     
    banksel LATB
    bsf MAX_CS
    return

    Edit: I got my code all clear, neat, and aligned, but this stupid forum messed it all up. Sorry, I'm not going to fix it.



    thanks 1and0,
     
    - For what concern the CKE, yes I've correted it
    - For what concern the BF flag, I've forgoten it thanks for noticing that. it's corrected now but normally even if the second byte is not out I should at least see the first data output and SCK through the logic Analyser no?
    - I've just implemented the code in the PIC and still nothing happening
     
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5