• AVR Freaks

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

Page: < 123 > Showing page 2 of 3
Author
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:31:35 (permalink)
0
; 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
#define MAX_CS LATB,6 ; use LATx for output
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 0x07
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 SSP1STAT
movlw b'01000000' ; SMP=0, CKE=1
movwf SSP1STAT
movlw b'00100000' ; enable SPI, CKP=0
movwf SSP1CON1


; 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 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

here the code reviewed
post edited by The alchmiste - 2018/03/18 03:14:12
#21
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:36:27 (permalink)
0
geralds
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
--




Hi Geralds,
 
Yes sure, I'll draw one in the next hours and post it
For what concern the C++ code, I think it's a bit different even if the organisation of the steps are same as the main issue I suppose with my issue should be comming from registers configurations and I dont use any librairies no?
 
thanks
#22
1and0
Access is Denied
  • Total Posts : 9882
  • 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 13:17:22 (permalink)
0
PORTB is multiplexed with analog function, so you'll need to disable them in order to use these pins are digital I/O
        banksel ANSELB
        clrf    ANSELB

Also, I suggest you to initialize the peripheral registers before initializing your variables.
#23
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/18 01:30:40 (permalink)
0
Thanks again 1and0,
 
I've made this change and still same situation, I'don't know if maybe I've forgotten something on the initial configuration with the use of internal oscillator or anyother conf?
 
Below the code with the new change:
; 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
#define MAX_CS LATB,6 ; use LATx for output
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

; 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 ANSELB
clrf ANSELB

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

; 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 0x07
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



; 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 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
end

post edited by The alchmiste - 2018/03/18 01:32:57

Attached Image(s)

#24
dan1138
Super Member
  • Total Posts : 3261
  • 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/18 01:55:37 (permalink)
0
The alchmiste
dan1138
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.

I've check this code but it's not using the SPI peripheral, it seems to use the rotate left function to send the data

With a carful study of the project I posted you could learn something useful, perhpas it is too complex for you.

I suspect that you have not configured the PIC16F16F15344 completely.

This may be what you need for the configuration words:
;
;                            PIC16F15344
;                    +-----------:_:-----------+
;             VDD -> :  1 VDD           VSS 20 : <- VSS
;             RA4 <> :  2 OSC2          PGD 19 : <> RA0 ICD_PGD
;             RA5 <> :  3 OSC1          PGC 18 : <> RA1 ICD_PGC
;         VPP RA3 -> :  4 VPP/MCLRn         17 : <> RA2
;             RC5 <> :  5                   16 : <> RC0
;             RC4 <> :  6                   15 : <> RC1
;             RC3 <> :  7                   14 : <> RC2
;             RC6 <> :  8               SDO 13 : <> RB4 MAX7219_DI
;             RC7 -> :  9               CSn 12 : <> RB5 MAX7219_LOAD
;             RC8 <- : 10               SCK 11 : <> RB6 MAX7219_CLK
;                    +-------------------------+
;                              DIP-20
;
        LIST    r=dec, n=0, c=160
        errorlevel -302         ; Suppress the not in bank zero warning

#include "p16f15344.inc"

 __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_OFF
 __CONFIG _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON
 __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
 __CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_OFF
 __CONFIG _CONFIG5, _CP_OFF


This may get your I/O pins setup:
INIT:
                CLRF    INTCON          ;DISABLE INTERUPTS

                banksel TRISA
                MOVLW   B'11111111'     ;PORT C INPUTS
                MOVWF   TRISC      
                MOVLW   B'10000000'     ;PORT B TRISB6 - Input, TRISB6,TRISB5,TRISB4 - Outpits, TRISB3,TRISB2,TRISB1,TRISB0 - not implemented
                MOVWF   TRISB
                MOVLW   B'00110111'     ;PORT A INPUTS, TRISA7,TRISA6,TRISA3 - not implented,
                MOVWF   TRISA
                
                banksel SSP1DATPPS
                movlw   H'0C'
                movwf   SSP1DATPPS      ;Assign SPI data input to RB4
                movlw   H'0E'
                movwf   SSP1CLKPPS      ;assign SPI clock input to RB6
                
                banksel RB4PPS
                movlw   H'16'
                movwf   RB4PPS          ;Set RB4 as SPI data output
                movlw   H'00'
                movwf   RB5PPS          ;Set RB5 as CSn output (no PPS assigned)
                movlw   H'15'
                movwf   RB6PPS          ;Set RB6 as SPI clock output
                
                clrf    ANSELA
                clrf    ANSELB
                clrf    ANSELC
                
                banksel LATA
                CLRF    LATA            ;PORTA CLEAR
                MOVLW   B'00100000'     ;ASSERT MAX7219 LOAD PIN TO HIGH
                MOVWF   LATB            ;PORTB CLEAR
                CLRF    LATC            ;PORTC CLEAR
                
                RETURN                  ;END OF SUB

I seem to remember that the SPI inputs for the clock and data need to be setup with the PPS even when not needed for a write only usage. I do not have a PIC16F15344 to test this code with.

By the way I cannot see any information in your posts where you stated that you have measure the SPI clock, data out and chip select outputs working as you expect.

Do you see correct signals on the SPI clock, data and chip select pins?
post edited by dan1138 - 2019/10/22 23:38:22
#25
timijk
Super Member
  • Total Posts : 1216
  • Reward points : 0
  • Joined: 2007/11/26 00:30:07
  • Location: Taiwan
  • Status: offline
Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/18 01:56:10 (permalink)
0
What's the initial value of MAX_CS?  It has to be 1 (High) before you call the subroutine RoutineveriffinSDI.
#26
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/18 02:09:40 (permalink)
0
Hi Dan1138,
dan1138


By the way I cannot see any information in your posts where you stated that you have measure the SPI clock, data out and chip select outputs working as you expect.

Do you see correct signals on the SPI clock, data and chip select pins?



I've attached the signal I got from pins remaped to SCK and SDO when I power on the uC.
I'll check carefully the configuration and test if setting the SDI is making a difference.
 
Thanks.

Attached Image(s)

#27
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/18 03:43:29 (permalink)
0

;                                         MAX7219
;                           +-----------:_:-----------+
; Din -> : 1 RB4                                                      20 : <- Dout
; DIG0 <> : 2 connected                          connected 19 : <> SEG D
; DIG4 <> : 3 connected                                         18 : <> SEG DP
; GND -> : 4 GND                                    connected 17 : <> SEG E
; DIG6 <> : 5 connected                                         16 : <> SEG C
; DIG2 <> : 6 connected                                4.75v 15 : <> V+
; DIG3 <> : 7 connected                          9.9k ohm 14 : <> Iset
; DIG7 <> : 8 connected                                         13 : <> SEG G
; GND -> : 9 GND                                   connected 12 : <> SEG B
; DIG5 <- : 10 connected                                        11 : <> SEG F
; DIG1 -> : 9 connected                          connected 12 : <> SEG A
; Load <- : 10 RB5                                          RB6 11 : <> CLK
; +-------------------------+
; DIP-24
 
 
 
 
;                                   PIC16F15344
;                         +-----------:_:-----------+
; VDD -> : 1 VDD                              VSS 20 : <- VSS
; RA4 <> : 2 OSC2                            PGD 19 : <> RA0 ICD_PGD
; RA5 <> : 3 OSC1                            PGC 18 : <> RA1 ICD_PGC
; VPP RA3 -> : 4 VPP/MCLRn                     17 : <> RA2
; RC5 <> : 5                                            16 : <> RC0
; RC4 <> : 6                                            15 : <> RC1
; RC3 <> : 7                                            14 : <> RC2
; RC6 <> : 8                                     SDO 13 : <> RB4 MAX7219_DI
; RC7 -> : 9                                       CSn 12 : <> RB5 MAX7219_LOAD
; RC8 <- : 10                                     SCK 11 : <> RB6 MAX7219_CLK
;                        +-------------------------+
;                                      DIP-20
;
        LIST r=dec, n=0, c=160
        errorlevel -302 ; Suppress the not in bank zero warning

#include "p16f15344.inc"

 __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_OFF
 __CONFIG _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON
 __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
 __CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _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
    #define MAX_CS LATB,6 ; use LATx for output
    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

       ; Initialisation des paramettres SPI
 
                CLRF INTCON ;DISABLE INTERUPTS

                banksel TRISA
                MOVLW B'11111111' ;PORT C INPUTS
                MOVWF TRISC
                MOVLW B'10000000' ;PORT B TRISB6 - Input, TRISB6,TRISB5,TRISB4 - Outpits, TRISB3,TRISB2,TRISB1,TRISB0 - not implemented
                MOVWF TRISB
                MOVLW B'00110111' ;PORT A INPUTS, TRISA7,TRISA6,TRISA3 - not implented,
                MOVWF TRISA
                
                banksel SSP1DATPPS
                movlw H'0C'
                movwf SSP1DATPPS ;Assign SPI data input to RB4
                movlw H'0E'
                movwf SSP1CLKPPS ;assign SPI clock input to RB6
                
                banksel RB4PPS
                movlw H'16'
                movwf RB4PPS ;Set RB4 as SPI data output
                movlw H'00'
                movwf RB5PPS ;Set RB5 as CSn output (no PPS assigned)
                movlw H'15'
                movwf RB6PPS ;Set RB6 as SPI clock output
                
                clrf ANSELA
                clrf ANSELB
                clrf ANSELC
                
                banksel LATA
                CLRF LATA ;PORTA CLEAR
                MOVLW B'00100000' ;ASSERT MAX7219 LOAD PIN TO HIGH
                MOVWF LATB ;PORTB CLEAR
                CLRF LATC ;PORTC CLEAR
    
; 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 0x07
    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


 
; 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 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
    end
This is really crazy, I have 3 different pic 16F15344 and tried in all of them with the updated code and still can't get even a SDO and SCK output after updating with the following code as advised by dan1138, 1and0 and Jack (I've also added the connection of the Max7219 even if it's useless for the moment as no SDO SCK)
post edited by The alchmiste - 2018/03/18 03:52:59
#28
timijk
Super Member
  • Total Posts : 1216
  • Reward points : 0
  • Joined: 2007/11/26 00:30:07
  • Location: Taiwan
  • Status: offline
Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/18 04:17:41 (permalink)
0
In your post #28, did you miss this block?
 
banksel SSP1STAT
movlw b'01000000' ; SMP=0, CKE=1
movwf SSP1STAT
movlw b'00100000' ; enable SPI, CKP=0
movwf SSP1CON1

#29
1and0
Access is Denied
  • Total Posts : 9882
  • 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/18 05:45:09 (permalink)
0
Also, for the code in Post #28, the CS (LOAD) and SCK pins are different from your earlier posts; so are these pins correctly connected to the MAX chip?  You will also need to change the MAX_CS definition to match.
 
With config bit MCLRE_ON, have you connected the /MCLR pin to Vdd with a pull-up resistor?  I suspect if your PIC is running at all.  Perhaps try toggle an output pin continually to check.
 
#30
Gerald1
Super Member
  • Total Posts : 339
  • Reward points : 0
  • Joined: 2009/05/12 06:50:37
  • Location: Wien, Austria
  • Status: online
Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/03/18 07:05:59 (permalink)
0

MAX7219_KOMMANDO
; save the accu values to the stack!!!! here!!!

You need 2 registers where the values are stored (they are coming from the ohter routines):
;TEMP1 for the address values, TEMP2 for the data values
;TEMP3 just stores the values for the loopcounter in this methode (subroutine)
; the serial transmitting goes not directly, they where are set or unset the DIN_pin for the MAX7219 under one CLK_time (set/unset the CLK_pin).
;the address values and data values will be compared after one shift-left by checking the carry flag.
;is the carry flag set (one) then the DIN_pin will be set to one, else (carry is null) it will be set to null.
;this is going 8 times under the loopcounter as well the adress and data values.
;each value will then sent out with one CLK_time.
;after the 16th step the LOAD-pin will be set once for storing into the MAX7219
; -> first you must send the adress(for the registers in the MAX7219), second you must send the data, third you must send the LOAD for storing the combined values.
;after that the MAX7219 will do what he get in its registers.

;this rountine is also needing for the init routine - all init values will be send with this routine
;also all user data values will be send with this routine.

                  ;Step 1: Lead LOAD unset
                               bcf MAX7219PORT,MAX7219LOAD ; Steuerleitung LOAD loeschen

                  ;Step 2: Send the address (TEMP1) to the MAX7219
                               movlw .8 ;(load the loopcounter with the value 8) Schleifenzaehler (TEMP3) mit dem Wert 8
                               movwf TEMP3 ; laden

MAX7219_SCHL1      rlf TEMP1,f ;Alle Bits im Uebergaberegister TEMP1 auf
                                   ; die naechst hoehere Stelle schieben
                               btfss STAT,C ;compare the value - ist das soeben ins Carry geschobene Bit
                                   ; 1?
                               goto MAX7219_WEITER1
                               bsf MAX7219PORT,MAX7219DIN ;ja: Datenleitung DIN = 1
                               goto MAX7219_WEITER2
MAX7219_WEITER1   bcf MAX7219PORT,MAX7219DIN ;nein: Datenleitung DIN = 0
MAX7219_WEITER2   bsf MAX7219PORT,MAX7219CLK ;Takt (positive und negative
                               bcf MAX7219PORT,MAX7219CLK ; Flanke) erzeugen

                               decfsz TEMP3,f ;Diesen Vorgang 8mal durchfuehren
                               goto MAX7219_SCHL1

                  ;Step 3: send Data (TEMP2) auf die gleiche Weise wie die
                  ; Adresse (TEMP1) an den MAX7219 senden
                               movlw .8 ;Schleifenzaehler (TEMP3) mit dem Wert 8
                               movwf TEMP3 ; laden

MAX7219_SCHL2      rlf TEMP2,f ;Bits im Uebergaberegister TEMP2 auf die
                                   ; naechst hoehere Stelle schieben
                               btfss STAT,C ;ist das soeben ins Carry geschobene Bit 1?
                               goto MAX7219_WEITER3
                               bsf MAX7219PORT,MAX7219DIN ;ja: Datenleitung DIN = 1
                               goto MAX7219_WEITER4
MAX7219_WEITER3  bcf MAX7219PORT,MAX7219DIN ;nein: Datenleitung DIN = 0
MAX7219_WEITER4  bsf MAX7219PORT,MAX7219CLK ;Takt (positive und negative
                              bcf MAX7219PORT,MAX7219CLK ; Flanke) erzeugen

                              decfsz TEMP3,f ;Diesen Vorgang 8mal durchfuehren
                              goto MAX7219_SCHL2

                  ;Step 4: set the LOAD - Die Steuerleitung LOAD wieder setzen, und eine
                  ; positive Taktflanke erzeugen
                              bsf MAX7219PORT,MAX7219LOAD ;Steuerleitung LOAD wieder
                              bsf MAX7219PORT,MAX7219CLK ; setzen und eine positive
                                                 ; CLK-edge - Taktflanke erzeugen
 
; restore the accu values from the stack here!!!!
; now you can go out, "by by"
                              return

 
The alchmiste

 
;                                         MAX7219
;                           +-----------:_:-----------+
; Din -> : 1 RB4                                                      20 : <- Dout
; DIG0 <> : 2 connected                          connected 19 : <> SEG D
; DIG4 <> : 3 connected                                         18 : <> SEG DP
; GND -> : 4 GND                                    connected 17 : <> SEG E
; DIG6 <> : 5 connected                                         16 : <> SEG C
; DIG2 <> : 6 connected                                4.75v 15 : <> V+
; DIG3 <> : 7 connected                          9.9k ohm 14 : <> Iset
; DIG7 <> : 8 connected                                         13 : <> SEG G
; GND -> : 9 GND                                   connected 12 : <> SEG B
; DIG5 <- : 10 connected                                        11 : <> SEG F
; DIG1 -> : 9 connected                          connected 12 : <> SEG A
; Load <- : 10 RB5                                          RB6 11 : <> CLK
; +-------------------------+
; DIP-24
 
 
 
 
;                                   PIC16F15344
;                         +-----------:_:-----------+
; VDD -> : 1 VDD                              VSS 20 : <- VSS
; RA4 <> : 2 OSC2                            PGD 19 : <> RA0 ICD_PGD
; RA5 <> : 3 OSC1                            PGC 18 : <> RA1 ICD_PGC
; VPP RA3 -> : 4 VPP/MCLRn                     17 : <> RA2
; RC5 <> : 5                                            16 : <> RC0
; RC4 <> : 6                                            15 : <> RC1
; RC3 <> : 7                                            14 : <> RC2
; RC6 <> : 8                                     SDO 13 : <> RB4 MAX7219_DI
; RC7 -> : 9                                       CSn 12 : <> RB5 MAX7219_LOAD
; RC8 <- : 10                                     SCK 11 : <> RB6 MAX7219_CLK
;                        +-------------------------+
;                                      DIP-20
;
        LIST r=dec, n=0, c=160
        errorlevel -302 ; Suppress the not in bank zero warning

#include "p16f15344.inc"

 __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_OFF
 __CONFIG _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON
 __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
 __CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _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
    #define MAX_CS LATB,6 ; use LATx for output
    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

       ; Initialisation des paramettres SPI
 
                CLRF INTCON ;DISABLE INTERUPTS

                banksel TRISA
                MOVLW B'11111111' ;PORT C INPUTS
                MOVWF TRISC
                MOVLW B'10000000' ;PORT B TRISB6 - Input, TRISB6,TRISB5,TRISB4 - Outpits, TRISB3,TRISB2,TRISB1,TRISB0 - not implemented
                MOVWF TRISB
                MOVLW B'00110111' ;PORT A INPUTS, TRISA7,TRISA6,TRISA3 - not implented,
                MOVWF TRISA
                
                banksel SSP1DATPPS
                movlw H'0C'
                movwf SSP1DATPPS ;Assign SPI data input to RB4
                movlw H'0E'
                movwf SSP1CLKPPS ;assign SPI clock input to RB6
                
                banksel RB4PPS
                movlw H'16'
                movwf RB4PPS ;Set RB4 as SPI data output
                movlw H'00'
                movwf RB5PPS ;Set RB5 as CSn output (no PPS assigned)
                movlw H'15'
                movwf RB6PPS ;Set RB6 as SPI clock output
                
                clrf ANSELA
                clrf ANSELB
                clrf ANSELC
                
                banksel LATA
                CLRF LATA ;PORTA CLEAR
                MOVLW B'00100000' ;ASSERT MAX7219 LOAD PIN TO HIGH
                MOVWF LATB ;PORTB CLEAR
                CLRF LATC ;PORTC CLEAR
    
; 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 0x07
    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


 
; 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 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
    end
This is really crazy, I have 3 different pic 16F15344 and tried in all of them with the updated code and still can't get even a SDO and SCK output after updating with the following code as advised by dan1138, 1and0 and Jack (I've also added the connection of the Max7219 even if it's useless for the moment as no SDO SCK)
 
Best Regards
Gerald




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

#31
dan1138
Super Member
  • Total Posts : 3261
  • 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/18 13:30:44 (permalink)
+1 (1)
<EDIT> Fixed bug reported by 1and0

This is your code with some of the bugs fixed:
;                           MAX7219
;               +-------------:_:-------------+
;        Din -> :  1 RB4                   24 : -> Dout
;       DIG0 <- :  2 connected   connected 23 : -> SEG D
;       DIG4 <- :  3 connected             22 : -> SEG DP
;        GND -> :  4 GND         connected 21 : -> SEG E
;       DIG6 <- :  5 connected             20 : -> SEG C
;       DIG2 <- :  6 connected       4.75v 19 : <- V+
;       DIG3 <- :  7 connected    9.9k ohm 18 : <- Iset
;       DIG7 <- :  8 connected             17 : -> SEG G
;        GND -> :  9 GND         connected 16 : -> SEG B
;       DIG5 <- : 10 connected             15 : -> SEG F
;       DIG1 <- : 11 connected   connected 14 : -> SEG A
;       Load -> : 12 RB5               RB6 13 : <- CLK
;               +-----------------------------+
;                           DIP-24
;
;                         PIC16F15344
;                 +-----------:_:-----------+
;          VDD -> : 1 VDD            VSS 20 : <- VSS
;          RA4 <> : 2 OSC2           PGD 19 : <> RA0 ICD_PGD
;          RA5 <> : 3 OSC1           PGC 18 : <> RA1 ICD_PGC
;      VPP RA3 -> : 4 VPP/MCLRn          17 : <> RA2
;          RC5 <> : 5                    16 : <> RC0
;          RC4 <> : 6                    15 : <> RC1
;          RC3 <> : 7                    14 : <> RC2
;          RC6 <> : 8                SDO 13 : <> RB4 MAX7219_DI
;          RC7 -> : 9                CSn 12 : <> RB5 MAX7219_LOAD
;          RC8 <- : 10               SCK 11 : <> RB6 MAX7219_CLK
;                 +-------------------------+
;                           DIP-20
;
        LIST r=dec, n=0, c=160
        errorlevel -302 ; Suppress the not in bank zero warning

#include "p16f15344.inc"

 __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_OFF
 __CONFIG _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON
 __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
 __CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _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
;    #define MAX_CS LATB,6 ; use LATx for output
#define MAX_CS LATB,5 ; use LATx for output
    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

    ; Initialisation des paramettres SPI

    CLRF    INTCON          ;DISABLE INTERUPTS

    banksel TRISA
    MOVLW   B'11111111'     ;PORT C INPUTS
    MOVWF   TRISC
    MOVLW   B'10000000'     ;PORT B TRISB6 - Input, TRISB6,TRISB5,TRISB4 - Outpits, TRISB3,TRISB2,TRISB1,TRISB0 - not implemented
    MOVWF   TRISB
    MOVLW   B'00110111'     ;PORT A INPUTS, TRISA7,TRISA6,TRISA3 - not implented,
    MOVWF   TRISA

    banksel SSP1DATPPS
    movlw   H'0C'
    movwf   SSP1DATPPS      ;Assign SPI data input to RB4
    movlw   H'0E'
    movwf   SSP1CLKPPS      ;assign SPI clock input to RB6

    banksel RB4PPS
    movlw   H'16'
    movwf   RB4PPS          ;Set RB4 as SPI data output
    movlw   H'00'
    movwf   RB5PPS          ;Set RB5 as CSn output (no PPS assigned)
    movlw   H'15'
    movwf   RB6PPS          ;Set RB6 as SPI clock output

    BANKSEL SSP1CON1
    MOVLW   B'00000001'     ;SPI master with clock at 2MHz (FOSC/16 mode)
    MOVWF   SSP1CON1
    CLRF    SSP1CON2
    CLRF    SSP1CON3
    CLRF    SSP1STAT
    BSF     SSP1STAT,CKE
    BSF     SSP1CON1,SSPEN

    banksel ANSELA
    clrf    ANSELA
    clrf    ANSELB
    clrf    ANSELC

    banksel LATA
    CLRF    LATA        ;PORTA CLEAR
    MOVLW   B'00100000' ;ASSERT MAX7219 LOAD PIN TO HIGH
    MOVWF   LATB        ;PORTB CLEAR
    CLRF    LATC        ;PORTC CLEAR

; 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   0x07
    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

; 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

STOP:
    GOTO    STOP

RoutineveriffinSDI:
    banksel LATB
    bcf     MAX_CS

    banksel registre ; actually this banksel is unecessary
    movf    registre,w
    banksel SSP1BUF
    BCF     SSP1STAT,BF
    movwf   SSP1BUF

    btfss   SSP1STAT,BF ; use bit symbol BF
    goto    $-1
    movf    SSP1BUF,w
;
    banksel donnee
    movf    donnee,w
    banksel SSP1BUF
    BCF     SSP1STAT,BF
    movwf   SSP1BUF

    btfss   SSP1STAT,BF
    goto    $-1
    movf    SSP1BUF,w ; add this line to clear BF

    banksel LATB
    bsf     MAX_CS
    return

    end

This is what it looks like on my logic analyzer:

Note that my MAX7219 initialization data is different from yours because my LEDs are an 8x8 array not an 8 digit seven segment display.
post edited by dan1138 - 2018/03/18 19:21:45
#32
1and0
Access is Denied
  • Total Posts : 9882
  • 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/18 17:22:05 (permalink)
+1 (1)
dan1138
This is your code with some of the bugs fixed:
...
This is what it looks like on my logic analyzer:

I'm puzzled how that code can result in the traces shown on the logic analyzer when the LOAD (CS) pin is configured to RB5 and the CLK pin to RB6
    banksel RB4PPS
    movlw   H'16'
    movwf   RB4PPS ;Set RB4 as SPI data output
    movlw   H'00'
    movwf   RB5PPS ;Set RB5 as CSn output (no PPS assigned)
    movlw   H'15'
    movwf   RB6PPS ;Set RB6 as SPI clock output

but in the code the LOAD pin is defined as LATB6
    #define MAX_CS LATB,6 ; use LATx for output

and is used in the routine
RoutineveriffinSDI:
    banksel LATB
    bcf     MAX_CS
;   snipped
    banksel LATB
    bsf     MAX_CS
    return

#33
dan1138
Super Member
  • Total Posts : 3261
  • 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/18 19:16:14 (permalink)
0
1and0
dan1138
This is your code with some of the bugs fixed:
...
This is what it looks like on my logic analyzer:

I'm puzzled how that code can result in the traces shown on the logic analyzer when the LOAD (CS) pin is configured to RB5 and the CLK pin to RB6
    banksel RB4PPS
    movlw   H'16'
    movwf   RB4PPS ;Set RB4 as SPI data output
    movlw   H'00'
    movwf   RB5PPS ;Set RB5 as CSn output (no PPS assigned)
    movlw   H'15'
    movwf   RB6PPS ;Set RB6 as SPI clock output

but in the code the LOAD pin is defined as LATB6
    #define MAX_CS LATB,6 ; use LATx for output

and is used in the routine
RoutineveriffinSDI:
    banksel LATB
    bcf     MAX_CS
 
;   snipped
 
    banksel LATB
    bsf     MAX_CS
    return


The logic analyzer traces are from my prototype using a PIC16F18877 so it would seem that when I put my updates in "The alchmiste" code I missed this bug. All I can say good job in spotting it.
 
When it comes to assembly language programming it has always been a brutal, no prisoners, experience for me. Nothing works until every thing has been checked and validated. It is especially important recheck all the things that are obviously correct.
#34
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/19 10:29:23 (permalink)
0
1and0
Also, for the code in Post #28, the CS (LOAD) and SCK pins are different from your earlier posts; so are these pins correctly connected to the MAX chip?  You will also need to change the MAX_CS definition to match.
 
With config bit MCLRE_ON, have you connected the /MCLR pin to Vdd with a pull-up resistor?  I suspect if your PIC is running at all.  Perhaps try toggle an output pin continually to check.
 





Hi 1and0,
 
I think you're right regarding the functionment of the PIC, there is something that is not working somewere.
But at this step I don't think you can help, I'll try to check if it's not due to the fact of setting the voltage programing to 4.75 due to my USB port as I use the option of powering the uC from pickit3 when programing
 
Great job for the code redesign, thanks to you dan1138 and 1and0. This will help me and others readers to improve the way of programing in asm.
 
Dan1138 the logic analyser picture you've posted is giving me hope! thanks a lot!
#35
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/27 07:04:08 (permalink)
0
Hi Guys,
 
I'm back after some tryes on the code and I've found some typo:
- BF can't be cleared so I've removed the "BCF     SSP1STAT,BF" instruction and replaced it by a read of SSP1BUF
- I've added a clear of SSP1BUF at the begining of the program as otherwith on the Mplab simulator, it's set to the same value.
 
I've now learned how to use the Mplab simulator and what's happening is that the BF test loop is never ending as the BF is never set. Does anyone understand why?

    
    
  ; MAX7219
; +-------------:_:-------------+
; Din -> : 1 RB4 24 : -> Dout
; DIG0 <- : 2 connected connected 23 : -> SEG D
; DIG4 <- : 3 connected 22 : -> SEG DP
; GND -> : 4 GND connected 21 : -> SEG E
; DIG6 <- : 5 connected 20 : -> SEG C
; DIG2 <- : 6 connected 4.75v 19 : <- V+
; DIG3 <- : 7 connected 9.9k ohm 18 : <- Iset
; DIG7 <- : 8 connected 17 : -> SEG G
; GND -> : 9 GND connected 16 : -> SEG B
; DIG5 <- : 10 connected 15 : -> SEG F
; DIG1 <- : 11 connected connected 14 : -> SEG A
; Load -> : 12 RB5 RB6 13 : <- CLK
; +-----------------------------+
; DIP-24
;
; PIC16F15344
; +-----------:_:-----------+
; VDD -> : 1 VDD VSS 20 : <- VSS
; RA4 <> : 2 OSC2 PGD 19 : <> RA0 ICD_PGD
; RA5 <> : 3 OSC1 PGC 18 : <> RA1 ICD_PGC
; VPP RA3 -> : 4 VPP/MCLRn 17 : <> RA2
; RC5 <> : 5 16 : <> RC0
; RC4 <> : 6 15 : <> RC1
; RC3 <> : 7 14 : <> RC2
; RC6 <> : 8 SDO 13 : <> RB4 MAX7219_DI
; RC7 -> : 9 CSn 12 : <> RB5 MAX7219_LOAD
; RC8 <- : 10 SCK 11 : <> RB6 MAX7219_CLK
; +-------------------------+
; DIP-20
;
        LIST r=dec, n=0, c=160
        errorlevel -302 ; Suppress the not in bank zero warning

#include "p16f15344.inc"

 __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_OFF
 __CONFIG _CONFIG2, _MCLRE_OFF & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON
 __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
 __CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _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
; #define MAX_CS LATB,6 ; use LATx for output
    #define MAX_CS LATB,5 ; use LATx for output
    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

    ; Initialisation des paramettres SPI

    banksel INTCON
    CLRF INTCON ;DISABLE INTERUPTS
    banksel SSP1BUF
    CLRF SSP1BUF

    banksel TRISA
    MOVLW B'11111111' ;PORT C INPUTS
    MOVWF TRISC
    MOVLW B'10000000' ;PORT B TRISB6 - Input, TRISB6,TRISB5,TRISB4 - Outpits, TRISB3,TRISB2,TRISB1,TRISB0 - not implemented
    MOVWF TRISB
    MOVLW B'00110111' ;PORT A INPUTS, TRISA7,TRISA6,TRISA3 - not implented,
    MOVWF TRISA

   banksel SSP1DATPPS
   movlw H'0C'
   movwf SSP1DATPPS ;Assign SPI data input to RB4
   movlw H'0E'
   movwf SSP1CLKPPS ;assign SPI clock input to RB6

    banksel RB4PPS
    movlw H'16'
    movwf RB4PPS ;Set RB4 as SPI data output
    movlw H'00'
    movwf RB5PPS ;Set RB5 as CSn output (no PPS assigned)
    movlw H'15'
    movwf RB6PPS ;Set RB6 as SPI clock output

    BANKSEL SSP1CON1
    MOVLW B'00000001' ;SPI master with clock at 2MHz (FOSC/16 mode)
    MOVWF SSP1CON1
    CLRF SSP1CON2
    CLRF SSP1CON3
    CLRF SSP1STAT
    BSF SSP1STAT,CKE
    BSF SSP1CON1,SSPEN


    banksel ANSELA
    clrf ANSELA
    clrf ANSELB
    clrf ANSELC

    banksel LATA
    CLRF LATA ;PORTA CLEAR
    MOVLW B'00100000' ;ASSERT MAX7219 LOAD PIN TO HIGH
    MOVWF LATB ;PORTB CLEAR
    CLRF LATC ;PORTC CLEAR

; 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 0x07
    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

; 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

STOP:
    GOTO STOP

RoutineveriffinSDI:
    banksel LATB
    bcf MAX_CS
    
    
    banksel SSP1BUF
    movf SSP1BUF,w
    banksel registre ; actually this banksel is unecessary
    movf registre,w
    banksel SSP1BUF
    movwf SSP1BUF

tsts
    btfss SSP1STAT,BF ; use bit symbol BF
    goto tsts
    movf SSP1BUF,w
;
    banksel SSP1BUF
    movf SSP1BUF,w
    banksel donnee
    movf donnee,w
    banksel SSP1BUF
    movwf SSP1BUF
    
tsts1
    btfss SSP1STAT,BF
    goto tsts1
    movf SSP1BUF,w ; add this line to clear BF

    banksel LATB
    bsf MAX_CS
    return

    end
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

post edited by The alchmiste - 2018/03/27 07:05:42

Attached Image(s)

#36
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/05/01 03:56:39 (permalink)
0
Hello everyone,
 
Does anyone understand why the BF bit is never high?
 
Thanks
#37
timijk
Super Member
  • Total Posts : 1216
  • Reward points : 0
  • Joined: 2007/11/26 00:30:07
  • Location: Taiwan
  • Status: offline
Re: Pic 16F15344 and Max7219 to drive 7 segment display in asm 2018/05/01 05:46:52 (permalink)
0
in Simulator Help > Limitations > General Limitations

For devices with the listed peripherals, these peripherals are NOT supported:
* Serial I/O (i.e., SSP including I 2C and SPI). As a result, the SSPSTAT register has been made readable and writable.  You can use stimulus to emulate many of the signals of SPI and have firmware read data as if it was SPI.

 
#38
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/05/01 05:54:28 (permalink)
+1 (1)
Have you tried it in a real chip?
I always distrust the simulator in this sort of situation.
 
Edit: I see Tim posted while I was cogitating, confirming it IS a simulator limitation...
post edited by qɥb - 2018/05/01 05:55:41

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"
#39
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/08/11 11:20:49 (permalink)
0
   list p=16f15344 , r=dec
 #include <p16f15344.inc>


; CONFIG1
; __config 0x3E8C
 __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_ON & _CSWEN_ON & _FCMEN_ON
; CONFIG2
; __config 0x279C
 __CONFIG _CONFIG2, _MCLRE_OFF & _PWRTE_ON & _LPBOREN_ON & _BOREN_NSLEEP & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_OFF
; CONFIG3
; __config 0xFFFF
; __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
; CONFIG4
; __config 0x1FE0
 __CONFIG _CONFIG4, _BBSIZE_BB64K & _BBEN_ON & _SAFEN_ON & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_OFF
; CONFIG5
; __config 0x3FFF
 __CONFIG _CONFIG5, _CP_OFF

 
 #Define Compteur1 0x22
        #Define Compteur2 0x23
 #Define Compteur3 0x24
 #Define etat 0x25,1


 Org 0x00

 Goto initialisation
 
 
initialisation
 banksel OSCCON1
 movlw 0x60
 movwf OSCCON1
 banksel TRISB
 movlw 0xEF
 movwf TRISB
 Goto start
start
 btfss etat
 goto allumer
 goto eteindre
allumer
 bsf etat
 banksel PORTB
 bsf PORTB,4
 goto timmer
eteindre
 bcf etat
 banksel PORTB
 bcf PORTB,4
 goto timmer
 
timmer
     banksel Compteur1
     movlw 0
     movwf Compteur1
     banksel Compteur2
     movlw 10
     movwf Compteur2
     banksel Compteur3
     movlw 1
     movwf Compteur3
boucle
     banksel Compteur1
     Decfsz Compteur1
     goto boucle

     banksel Compteur2
     Decfsz Compteur2
     Goto boucle

     banksel Compteur3
     Decfsz Compteur3
     Goto boucle
     Goto start
 end
Hi everyone,
 
I'm back on this project after a bit of abscenc.
After trying to set the 5 configuration bit,
I've made a simple code (attached) to check if the internal oscillator is runing by spoofing the pic 16F15344 pins, but it don't seem so when I had a look on the scope attached.
Is some one able to tell me why and if some thing is wrong with my config words?
 
Thanks
the alchimiste
post edited by The alchmiste - 2018/08/11 11:23:22

Attached Image(s)

#40
Page: < 123 > Showing page 2 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5