MAX7219 help


Today 18:02
Forum: Proton Plus Compiler v3
Starter: towlerg
Views: 0
Replies: 0
Today 00:44
Forum: Proton Plus Compiler v3
Starter: davroski
Views: 0
Replies: 4
+ Reply to Thread
Results 1 to 10 of 10

Thread: MAX7219 help21 days old

  1. #1
    Junior Member antonhsp's Avatar
    Join Date
    Jul 2019
    Posts
    4
    Thumbs Up
    Received: 1
    Given: 0
    Total Downloaded
    171.37 MB

    0 Not allowed!

    Default MAX7219 help

    Hello everyone
    I am new to proton and I need your help
    After much reading and endless hours of effort I managed to build this voltmeter ampmeter and temperature meter
    The problem is that I can not print on the letter C in 7-segment display

    Please help me
    Thank you

    my code
    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  :                                                   *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    :                                                   *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    Device 16F819
    Declare Xtal = 4
    
    '========================= A/D SETUP =========================
    Declare Adin_Res 10
    Declare Adin_Tad FRC
    Declare Adin_Stime 50
    ;Declare Shift_DelayUs 4
    ADCON1=110000
    TRISA=01111
    ;TRISB=00000
    
    '-----VARIABLES-----
    Dim ADDRESS As Word 'variable address for display
    Dim DATAREG As Word 'variable data register for display
    Dim X As Word 'misc variable used in loops
    Dim Y As Word ' DEZE TOEVOEGEN
    
    
    '******** VOLT AMPER ************
    Dim VOLT As Word          '  Volt
    Dim GUCV As Word
    Dim HAM As Word           '  Α/D
    Dim HVD As Word
    Dim MV As Byte            '  mVolt
    Dim HAMA As Word
    Dim GUCA As Word
    Dim MA As Byte             ' mAmper
    Dim AMPER As Word          ' Amper
    Dim Aeep As Word
    Dim Temp1   As  Word       ' temp
    Dim Temp2   As  Word 
    Dim b As Word
    Dim c As Word
    b = 1250
    c = 500
    
    
    '*************************
    
    '-----Declare Pins Used-----
        Symbol Clk    = PORTB.1             ' Data is clocked on rising edge of this pin
        Symbol Dta  = PORTB.0               ' Bits are shifted out of this pin
        Symbol Load = PORTB.2               ' Transfers data to LEDs when Pulsed
        
    
    '-----PIN SETUPS-----
    ;low portb.0 'data pin for MAX7219 (1)
    ;low portb.1 'clock pin for MAX7219 (13)
    ;low portb.2 'load pin for MAX7219 (12)
    
    
    '========================= MAX7219 SETUP ========================
    ADDRESS = $0C : DATAREG = $01 : GoSub MaxWrite  ' NO SHUTDOWN MODE, NORMAL OPERATION
    ADDRESS = $09 : DATAREG = $FF : GoSub MaxWrite  ' COMBINATION BINARY, NO DECODE
    ADDRESS = $0A : DATAREG = $04 : GoSub MaxWrite  ' INTENSITY OF LEDS
    ADDRESS = $0B : DATAREG = $07 : GoSub MaxWrite  ' SCAN LIMIT DIGIT NUMBERS
    ADDRESS = $0F : DATAREG = $00 : GoSub MaxWrite  ' NORMAL OPERATION INSTEAD OF TEST
    GoSub Blank
    
    '========================= Main program =========================
    Start:
            ADCIN 0,HAM             ' Volt
    BAK:    If ADCON0.2=1 Then BAK
            DelayMS 5
            GoSub YPOLV              ' Volt
           
            ADCIN 1,HAMA             ' Amper
    BAK1:   If ADCON0.2=1 Then BAK1
            DelayMS 5
            GoSub YPOLA              ' Amper
           
            ADCIN 2,HAM              ' temp
    BAK3:   If ADCON0.2=1 Then BAK3
            DelayMS 5
            GoSub YPOLT              ' temp
            
            ADCIN 3,HAM              ' 
    BAK4:   If ADCON0.2=1 Then BAK4
            DelayMS 5
            GoSub YPOLT2              '       
    
    If PORTB.6=0 Then
             X = Temp1
             Y = Temp2
    GoTo ValueT
    EndIf        
             
    If PORTB.7=1 Then
            X = GUCV        ' F??t?se t?? t?? t?? Volt ?a? mV
            Y = GUCA      ' F??t?se t?? t?? t?? AMPER ?a? mA
    Else 
            Y = GUCV        ' F??t?se t?? t?? t?? Volt ?a? mV
            X = GUCA      ' F??t?se t?? t?? t?? AMPER ?a? mA
    EndIf
    
    ValueT:       
    GoSub ValueToMax
    DelayMS 100
    GoTo Start 'do it all over again
    End
    
    '-----SUBROUTINES-----
    ValueToMax:
    
    ADDRESS = 1 : DATAREG =  Dig X, 3
    DATAREG.7 = 0
    If Dig X, 3=0 Then DATAREG= 15
    GoSub MaxWrite
    ADDRESS = 2 : DATAREG = Dig X, 2
    DATAREG.7 = 0
    If Dig X, 2=0 And Dig X, 3=0 Then DATAREG= 15
    GoSub MaxWrite
    ADDRESS = 3 : DATAREG = Dig X, 1
    If PORTB.6=0 Then
    DATAREG.7 = 0
    Else
    DATAREG.7 = 1
    EndIf
    GoSub MaxWrite
    ADDRESS = 4 : DATAREG = Dig X, 0
    DATAREG.7 = 0
    GoSub MaxWrite
    '-----SUBROUTINES-----
    ADDRESS = 5 : DATAREG = Dig Y, 3
    DATAREG.7 = 0
    If Dig Y, 3=0 Then DATAREG= 15
    GoSub MaxWrite
    ADDRESS = 6 : DATAREG = Dig Y, 2 
    DATAREG.7 = 0
    If Dig Y, 2=0 And Dig Y, 3=0 Then DATAREG= 15
    GoSub MaxWrite
    ADDRESS = 7 : DATAREG = Dig Y, 1
    If PORTB.6=0 Then
    DATAREG.7 = 0
    Else
    DATAREG.7 = 1
    EndIf
    GoSub MaxWrite
    ADDRESS = 8 : DATAREG = Dig Y, 0
    DATAREG.7 = 0
    GoSub MaxWrite
    Return
    
    MaxWrite:
    SHOut Dta,Clk,MsbFirst,[ADDRESS,DATAREG] ' Shift Out the Register first, then the data
    High Load                                ' The data is now acted upon
    DelayUS 2                                ' A small delay to ensure correct clocking times
    Low Load                                 ' Disable the MAX7219
    Return
    
    Blank:
    For X = 1 To 4 'write $0F (blank) to all digits
    ADDRESS = X : DATAREG = $0F : GoSub MaxWrite
    Next X
    Return
    
    
    '==================  Volt Amper Temp ==================
    
    YPOLV: 'Volt 0-50 V*100/1024)*256
            HVD=(HAM+1)*/ b                   
            VOLT=HVD/10
            MV=(HVD)//100
            GUCV=VOLT+(MV/100)
    Return
    
    YPOLA: 'Amper 0-20 A*100/1024)*256 
            HVD=(HAMA+1) */ c     
            AMPER=HVD/10
            MA=HVD//100
            GUCA=AMPER+(MA/100)
            Return
            
    YPOLT:  'temp 1
    Temp1= ((HAM */ 500) >> 2)
            Return 
            
    YPOLT2: 'temp 2
    Temp2= ((HAM */ 500) >> 2)
            Return
    my sch
    MAX7219 temp.jpg

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    522
    Thumbs Up
    Received: 50
    Given: 23
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: MAX7219 help

    Hi antonhsp,

    Below is a code snippet which might be of help to you.....

    Code:
        Symbol LED_CLK = PORTB.5'PORTB.5
        Symbol LED_CS =  PORTB.4'PORTB.4
        Symbol LED_Data = PORTB.3'PORTB.3
    
        Symbol DispTest = $0F01
        Symbol NormDisp = $0F00
        Symbol NormOp = $0C01
        Symbol Shutdown = $0C00
        Symbol Intensity = $0A00
        Symbol NumDigToScan = $0B00
        Symbol DoLetters = $0900
        Symbol DoNumbers = $09FF
    
        Symbol Dig1 = $0100
        Symbol Dig2 = $0200
        Symbol Dig3 = $0300
        Symbol Dig4 = $0400
        Symbol Dig5 = $0500
        Symbol Dig6 = $0600
        Symbol Dig7 = $0700
        Symbol Dig8 = $0800
    
        $define SendToDisp (MaxData) DispData=maxdata:GoSub LED_Display
    
    '****************************************************************
    ' Hello World.
    '****************************************************************
        Hello:
        
        SendToDisp (DoLetters)
        SendToDisp (Dig1 + $37) 'H
        SendToDisp (Dig2 + $4F) 'E
        SendToDisp (Dig3 + $0E) 'L
        SendToDisp (Dig4 + $0E) 'L
        SendToDisp (Dig5 + $7E) 'O
    
        Return
    
    '****************************************************************
    ' Send data to display.
    '****************************************************************
        LED_Display:
    
        Low LED_CS
        SHOut LED_Data,LED_CLK,MsbFirst,[DispData\16]
        High LED_CS
    
        Return
    ''***************************************************************
    I think you need to send something like $4E to the 7219 in order to get capital C.


    Regards,

    Bob

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Junior Member antonhsp's Avatar
    Join Date
    Jul 2019
    Posts
    4
    Thumbs Up
    Received: 1
    Given: 0
    Total Downloaded
    171.37 MB

    1 Not allowed!

    Default Re: MAX7219 help

    Mellbreak
    Thank you so much for your help
    I'll try it (Dig1 + $4E)

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Junior Member antonhsp's Avatar
    Join Date
    Jul 2019
    Posts
    4
    Thumbs Up
    Received: 1
    Given: 0
    Total Downloaded
    171.37 MB

    0 Not allowed!

    Default Re: MAX7219 help

    I tried, but I did nothing do anything
    It is impossible to i print a custom symbol on 7-segment display except the custom symbols that which are in the rom of MAX7219

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    522
    Thumbs Up
    Received: 50
    Given: 23
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: MAX7219 help

    If you want to display display letters, you must first send $09FF to the '7219. This will set all digits to the to non-decode mode. I suggest that you try this first. Once you have done this, send $014E to the '7219. This should display the letter C on digit 0.

    I'm guessing that you really want to display a mixture on numbers and letters on your display. As an example, let us suppose that you display the letter C on digit 0 and digits 1-7 as numbers. Do do this try sending $09FE followed by $014E.

    If you haven't got a copy of the MAX7219 datasheet, I suggest you download it. You'll find a lot of really useful information in there that will help you get the display working as you want.

    Let us know how you get on. I don't have much time in the next couple of days, but should you still be struggling after that I'll try and write a short piece of code to help you out.


    Bob

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    478
    Thumbs Up
    Received: 40
    Given: 7
    Total Downloaded
    3.18 GB

    0 Not allowed!

    Default Re: MAX7219 help

    I think you will find the answer is on page 7 of the data sheet.
    If the decode data in the Decode-Mode register for a specific digit is set to 1 then the internal B-code font will be used (Table 5, page 8) and so the displayed item is based on the low nibble of that data. However, it it is set to 0 then you should have direct control over each segment (Table 6, page 8). Consequently I think one of the problems lies with...
    Code:
    ADDRESS = $09 : DATAREG = $FF : GoSub MaxWrite  ' COMBINATION BINARY, NO DECODE
    DATAREG should be $00 for direct (no B-code) control of the segments.

    As Mellbreak said use $4E for "C", but use $0D for "c".

    I am curious that from your question it would appear that you only have a problem writing C, but everything else is working, yet from my brief look at your code and the MAX7219 datasheet I am not sure how as you have defined ADDRESS and DATAREG as Words so
    Code:
    SHOut Dta,Clk,MsbFirst,[ADDRESS,DATAREG] ' Shift Out the Register first, then the data
    is shifting out 32 bits of data, not 16. Consequently, the upper bytes could be anything so what registers you are actually writing the ADDRESS and DATAREG vaules to and how the MAX7219 is interpreting that it is unknown.

    From Table 1 (page 6) it seems clear they should both be bytes and that every time you send data to the MAX7219 you should be sending a byte size address for the register (either control or digit to display) and a data byte for its contents. So try changing
    Code:
    Dim ADDRESS As Word 'variable address for display
    Dim DATAREG As Word 'variable data register for display
    to
    Code:
    Dim ADDRESS As Byte 'variable address for display
    Dim DATAREG As Byte 'variable data register for display
    and see what effect that has.

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,246
    Thumbs Up
    Received: 38
    Given: 0
    Total Downloaded
    861.68 MB

    0 Not allowed!

    Default Re: MAX7219 help

    Anton,
    The connections to the display are wrong. A problem with the ISIS model of the display. The left digit is connected to terminal 1.

    MAX7219 DIG0 connects to terminal 4 of the display, DIG1 to terminal 3, DIG2 to terminal 3 and DIG4 to terminal 4 then DIG4 is the character C

    This code is part of a larger program that works in ISIS and real hardware

    Code:
    $define _LCD_PORT_ 1                ' LCD PortA = 0, PortB = 1, PORTB = 2
                                        ' Custom = 3, see below
    Include "18F25K22 INTOSC 16.inc"
    
    ' Max 7219 connections
        Symbol Clk        = PORTB.0        ' Data is clocked on rising edge of this pin
        Symbol Dta      = PORTB.1        ' Bits are shifted out of this pin
        Symbol Load     = PORTB.2        ' Transfers data to LEDs when Pulsed
        
    ' Max 7219 Constants
        Symbol Decode_Reg     9       ' Decode register, a 1 turns on BCD decoding for each digit. 
        Symbol Lum_Reg        10       ' Intensity register.
        Symbol Scan_Reg        11       ' Scan-limit register.
        Symbol Switch_Reg   12       ' On/Off Register.
        Symbol Test_Reg        15       ' Test mode register (all digits on, 100% bright)
        
    ' Max 7219 Variables
        Dim Disp_Val    As Word       ' 16-bit value to be displayed by the MAX7219
        Dim Register    As Byte       ' Pointer to the Internal Registers of the MAX7219
        Dim R_Val        As Byte       ' Data placed in Each Register
        Dim Thou        As Byte    ' used to get Digit of Disp_Val
        Dim Hund        As Byte
        Dim Tens        As Byte
        Dim Unit        As Byte
        Dim DP          As Byte    ' 0 = no ~DP, 1 = right digit etc
        Dim LEDs        As Byte    ' digit 4 is decoded to individual LEDs    
        Dim Digit4      As Byte    ' alphapbet letter
        Dim TEST_Value  As Word
    
    ' ---------------------- uncoded digit 4 used for characters ---------------    
        Symbol A = %01110111                ' Actual weld voltage
        Symbol C = %01001110                ' calibrate
        Symbol d = %00111101
        Symbol E = %01001111
        Symbol H = %00110111
        Symbol o = %00011101                ' lower case O used for 'off'    
        Symbol P = %01100111
        Symbol t = %00001111
        Symbol U = %00111110
        Symbol v = %00011100                ' lower case V
        
    Start:
        DelayMS 250
        GoSub Max_Setup
        DP = 2                              ' Decimal point on digit 2
        Disp_Val = 0
        Digit4 = C : GoSub Digit_4
        While 1 = 1
            For Disp_Val = 0 To 999
                GoSub Display
                DelayMS 250
            Next
        Wend
        
    ' --------------------------- Start of MAX 7219 code -------------------
    Display:
        GoSub Max_Setup         ' just in case it was corrupted by HF
      
    '    Thou = Dig Disp_Val,3 : If DP = 4 Then Thou = Thou + 128
        Hund = Dig Disp_Val,2 : If DP = 3 Then Hund = Hund + 128
        Tens = Dig Disp_Val,1 : If DP = 2 Then Tens = Tens + 128
        Unit = Dig Disp_Val,0 : If DP = 1 Then Unit = Unit + 128
        If Thou + Hund = 0 Then Hund = 15
    '    If Thou = 0 Then Thou = 15
    '    Register = 4 : R_Val = Thou
    '    GoSub Transfer
        Register = 3 : R_Val = Hund
        GoSub Transfer
        Register = 2 : R_Val = Tens
        GoSub Transfer
        Register = 1 : R_Val = Unit
        GoSub Transfer
              
        Return    
                 
    Max_Setup:
    
            Register = Scan_Reg            ' Point to the Scan Register
            R_Val = 5                    ' Send 3, (Four LED Displays 0-3)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Lum_Reg            ' Point to the Luminance Register
            R_Val = 4                    ' Send 5, (Value for Brightness)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Decode_Reg        ' Point to BCD Decode Register
            R_Val = %00000111            ' Decode the first 4 digits
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Switch_Reg        ' Point to the Switch Register 
            R_Val = 1                    ' Set to One, (switches the display ON)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Test_Reg            ' Point to the Test Register
    '        R_Val = 1                   ' test all leds
    '        GoSub Transfer
    '        DelayMS 1000
            R_Val = 0                    ' Reset to Zero, (turns off Test mode)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    Digit_4:        
            Register = 4                ' 4 = third digit from right
            R_Val = Digit4
            GoSub Transfer  
    Change_LEDs:                        ' use 'digit 5' for individual LEDs
            Register = 5                ' Clear unused Digit 5 (single LEDs)
            R_Val = LEDs
            GoSub Transfer
            Return
    
    Transfer:                       ' Send a 16-bit word to the MAX7219 
                                    ' Shift Out the Register first, then the data
              SHOut Dta,Clk,MsbFirst,[Register,R_Val]     
            High Load                ' The data is now acted upon
            DelayUS 5                ' A small delay to ensure correct clocking times                
            Low Load                ' Disable the MAX7219 
            Return                    ' Exit from Subroutine        
    
    ' --------------------------------- end of Max 7219 code ----------------------
    Capture.jpg
    Last edited by See_Mos; 29th July 2019 at 14:40.
    My RAM is failing

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Junior Member antonhsp's Avatar
    Join Date
    Jul 2019
    Posts
    4
    Thumbs Up
    Received: 1
    Given: 0
    Total Downloaded
    171.37 MB

    0 Not allowed!

    Default Re: MAX7219 help

    Thank you very much all for your help


    Regards,

    antonhs

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,246
    Thumbs Up
    Received: 38
    Given: 0
    Total Downloaded
    861.68 MB

    0 Not allowed!

    Default Re: MAX7219 help

    I admit I made a mistake. That code comes from something I did about fifteen years ago. I had forgotten that the digit registers can be swapped around in any way that suits the PCB layout, in fact I did just that about a year ago when I did a project where the layout had to be single sided PCB and the digit sequence was random compared to the above.

    There are still a couple of errors in the REM notes but this code works for the diagram in the first post

    Code:
    ' #### note to change digit registers to suit display connections ###
    
    $define _LCD_PORT_ 1                ' LCD PortA = 0, PortB = 1, PORTC = 2
                                        ' Custom = 3
    Include "18F25K22 INTOSC 16.inc"
    
    ' Max 7219 connections
        Symbol Clk        = PORTB.0        ' Data is clocked on rising edge of this pin
        Symbol Dta      = PORTB.1        ' Bits are shifted out of this pin
        Symbol Load     = PORTB.2        ' Transfers data to LEDs when Pulsed
        
    ' Max 7219 Constants
        Symbol Decode_Reg     9       ' Decode register, a 1 turns on BCD decoding for each digit. 
        Symbol Lum_Reg        10       ' Intensity register.
        Symbol Scan_Reg        11       ' Scan-limit register.
        Symbol Switch_Reg   12       ' On/Off Register.
        Symbol Test_Reg        15       ' Test mode register (all digits on, 100% bright)
        
    ' Max 7219 Variables
        Dim Disp_Val    As Word       ' 16-bit value to be displayed by the MAX7219
        Dim Register    As Byte       ' Pointer to the Internal Registers of the MAX7219
        Dim R_Val        As Byte       ' Data placed in Each Register
        Dim Thou        As Byte    ' used to get Digit of Disp_Val
        Dim Hund        As Byte
        Dim Tens        As Byte
        Dim Unit        As Byte
        Dim DP          As Byte    ' 0 = no ~DP, 1 = right digit etc
        Dim LEDs        As Byte    ' digit 4 is decoded to individual LEDs
        Dim Digit1      As Byte       ' alphabet letter
    '    Dim Digit4      As Byte    ' alphapbet letter
        Dim TEST_Value  As Word
    
    ' ---------------------- uncoded digit 4 used for characters ---------------    
        Symbol A = %01110111                ' Actual weld voltage
        Symbol C = %01001110                ' calibrate
        Symbol d = %00111101
        Symbol E = %01001111
        Symbol H = %00110111
        Symbol o = %00011101                ' lower case O used for 'off'    
        Symbol P = %01100111
        Symbol t = %00001111
        Symbol U = %00111110
        Symbol v = %00011100                ' lower case V
        
    Start:
        DelayMS 250
        GoSub Max_Setup
        DP = 3                              ' Decimal point on digit 3
        Disp_Val = 0
        Digit1 = C : GoSub Digit_1
        While 1 = 1
            For Disp_Val = 0 To 999
                GoSub Display
                DelayMS 100
            Next
        Wend
        
    ' --------------------------- Start of MAX 7219 code -------------------
    Display:
        GoSub Max_Setup         ' just in case it was corrupted by HF
      
    '    Thou = Dig Disp_Val,3 : If DP = 1 Then Thou = Thou + 128
        Hund = Dig Disp_Val,2 : If DP = 2 Then Hund = Hund + 128
        Tens = Dig Disp_Val,1 : If DP = 3 Then Tens = Tens + 128
        Unit = Dig Disp_Val,0 : If DP = 4 Then Unit = Unit + 128
        If Thou + Hund = 0 Then Hund = 15
    '    If Thou = 0 Then Thou = 15
    '    Register = 1 : R_Val = Thou
    '    GoSub Transfer
        Register = 2 : R_Val = Hund
        GoSub Transfer
        Register = 3 : R_Val = Tens
        GoSub Transfer
        Register = 4 : R_Val = Unit
        GoSub Transfer
              
        Return    
                 
    Max_Setup:
    
            Register = Scan_Reg            ' Point to the Scan Register
            R_Val = 5                    ' Send 3, (Four LED Displays 0-3)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Lum_Reg            ' Point to the Luminance Register
            R_Val = 4                    ' Send 5, (Value for Brightness)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Decode_Reg        ' Point to BCD Decode Register
            R_Val = %00001110            ' Decode 
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Switch_Reg        ' Point to the Switch Register 
            R_Val = 1                    ' Set to One, (switches the display ON)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Test_Reg            ' Point to the Test Register
    '        R_Val = 1                   ' test all leds
    '        GoSub Transfer
    '        DelayMS 1000
            R_Val = 0                    ' Reset to Zero, (turns off Test mode)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    Digit_1:        
            Register = 1                ' 4 = third digit from right
            R_Val = Digit1
            GoSub Transfer  
    Change_LEDs:                        ' use 'digit 5' for individual LEDs
            Register = 5                ' Clear unused Digit 5 (single LEDs)
            R_Val = LEDs
            GoSub Transfer
            Return
    
    Transfer:                       ' Send a 16-bit word to the MAX7219 
                                    ' Shift Out the Register first, then the data
              SHOut Dta,Clk,MsbFirst,[Register,R_Val]     
            High Load                ' The data is now acted upon
            DelayUS 5                ' A small delay to ensure correct clocking times                
            Low Load                ' Disable the MAX7219 
            Return                    ' Exit from Subroutine        
    
    ' --------------------------------- end of Max 7219 code ----------------------
    Last edited by See_Mos; 30th July 2019 at 10:11.
    My RAM is failing

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,246
    Thumbs Up
    Received: 38
    Given: 0
    Total Downloaded
    861.68 MB

    0 Not allowed!

    Default Re: MAX7219 help

    Still has some REM error but this code works for two displays connected as post #1

    Code:
    ' #### note to change digit registers to suit display connections ###
    
    $define _LCD_PORT_ 1                ' LCD PortA = 0, PortB = 1, PORTC = 2
                                        ' Custom = 3
    Include "18F25K22 INTOSC 16.inc"
    
    ' Max 7219 connections
        Symbol Clk        = PORTB.0        ' Data is clocked on rising edge of this pin
        Symbol Dta      = PORTB.1        ' Bits are shifted out of this pin
        Symbol Load     = PORTB.2        ' Transfers data to LEDs when Pulsed
        
    ' Max 7219 Constants
        Symbol Decode_Reg     9       ' Decode register, a 1 turns on BCD decoding for each digit. 
        Symbol Lum_Reg        10       ' Intensity register.
        Symbol Scan_Reg        11       ' Scan-limit register.
        Symbol Switch_Reg   12       ' On/Off Register.
        Symbol Test_Reg        15       ' Test mode register (all digits on, 100% bright)
        
    ' Max 7219 Variables
        Dim Disp_Val    As Word       ' 16-bit value to be displayed by the MAX7219
        Dim Register    As Byte       ' Pointer to the Internal Registers of the MAX7219
        Dim R_Val        As Byte       ' Data placed in Each Register
        Dim Thou        As Byte    ' used to get Digit of Disp_Val
        Dim Hund        As Byte
        Dim Tens        As Byte
        Dim Unit        As Byte
        Dim DP          As Byte    ' 0 = no ~DP, 1 = right digit etc
        Dim LEDs        As Byte    ' digit 4 is decoded to individual LEDs
        Dim Digit1      As Byte       ' alphabet letter
        Dim Digit5      As Byte    ' alphapbet letter
        Dim TEST_Value  As Word
    
    ' ---------------------- uncoded digit 4 used for characters ---------------    
        Symbol A = %01110111                ' Actual weld voltage
        Symbol C = %01001110                ' calibrate
        Symbol d = %00111101                ' DOWN
        Symbol E = %01001111                ' error code
        Symbol H = %00110111
        Symbol o = %00011101                ' lower case O used for 'off'    
        Symbol P = %01100111                ' preset voltage
        Symbol t = %00001111                ' test mode
        Symbol U = %00111110                ' UP
        Symbol v = %00011100                ' lower case V
        
    Start:
        DelayMS 250
        GoSub Max_Setup
    
        Disp_Val = 0
        Digit1 = C : Digit5 = E
        While 1 = 1
            For TEST_Value = 0 To 999
                DP = 3                      ' Decimal point on digit 3        
                Disp_Val = TEST_Value : GoSub Display_1
                DP = 2
                Disp_Val = 999 - TEST_Value : GoSub Display_2
                DelayMS 100
            Next
        Wend
        
    ' --------------------------- Start of MAX 7219 code -------------------
    Display_1:
        GoSub Max_Setup         ' just in case it was corrupted by HF
      
    '    Thou = Dig Disp_Val,3 : If DP = 1 Then Thou = Thou + 128
        Hund = Dig Disp_Val,2 : If DP = 2 Then Hund = Hund + 128
        Tens = Dig Disp_Val,1 : If DP = 3 Then Tens = Tens + 128
        Unit = Dig Disp_Val,0 : If DP = 4 Then Unit = Unit + 128
        If Thou + Hund = 0 Then Hund = 15
    '    If Thou = 0 Then Thou = 15
    '    Register = 1 : R_Val = Thou
    '    GoSub Transfer
        Register = 1                ' 4 = third digit from right
        R_Val = Digit1
        GoSub Transfer
        Register = 2 : R_Val = Hund
        GoSub Transfer
        Register = 3 : R_Val = Tens
        GoSub Transfer
        Register = 4 : R_Val = Unit
        GoSub Transfer
              
        Return
        
    Display_2:
        GoSub Max_Setup         ' just in case it was corrupted by HF
      
    '    Thou = Dig Disp_Val,3 : If DP = 1 Then Thou = Thou + 128
        Hund = Dig Disp_Val,2 : If DP = 2 Then Hund = Hund + 128
        Tens = Dig Disp_Val,1 : If DP = 3 Then Tens = Tens + 128
        Unit = Dig Disp_Val,0 : If DP = 4 Then Unit = Unit + 128
        If Thou + Hund = 0 Then Hund = 15
    '    If Thou = 0 Then Thou = 15
    '    Register = 5 : R_Val = Thou
    '    GoSub Transfer
        Register = 5                ' 4 = third digit from right
        R_Val = Digit5
        GoSub Transfer
        Register = 6 : R_Val = Hund
        GoSub Transfer
        Register = 7 : R_Val = Tens
        GoSub Transfer
        Register = 8 : R_Val = Unit
        GoSub Transfer
              
        Return        
                 
    Max_Setup:
    
            Register = Scan_Reg            ' Point to the Scan Register
            R_Val = 7                    ' Send 7, scan 8 digits 0-7
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Lum_Reg            ' Point to the Luminance Register
            R_Val = 4                    ' Send 5, (Value for Brightness)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Decode_Reg        ' Point to BCD Decode Register
            R_Val = %11101110            ' Decode 
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Switch_Reg        ' Point to the Switch Register 
            R_Val = 1                    ' Set to One, (switches the display ON)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    
            Register = Test_Reg            ' Point to the Test Register
    '        R_Val = 1                   ' test all leds
    '        GoSub Transfer
    '        DelayMS 1000
            R_Val = 0                    ' Reset to Zero, (turns off Test mode)
            GoSub Transfer                ' Transfer this 16-bit Word to the MAX7219
    'Digit_1:        
    '        Register = 1                ' 4 = third digit from right
    '        R_Val = Digit1
    '        GoSub Transfer  
    'Change_LEDs:                        ' use 'digit 5' for individual LEDs
    '        Register = 5                ' Clear unused Digit 5 (single LEDs)
    '        R_Val = LEDs
    '        GoSub Transfer
    '        Return
    
    Transfer:                       ' Send a 16-bit word to the MAX7219 
                                    ' Shift Out the Register first, then the data
              SHOut Dta,Clk,MsbFirst,[Register,R_Val]     
            High Load                ' The data is now acted upon
            DelayUS 5                ' A small delay to ensure correct clocking times                
            Low Load                ' Disable the MAX7219 
            Return                    ' Exit from Subroutine        
    
    ' --------------------------------- end of Max 7219 code ----------------------
    Last edited by See_Mos; 30th July 2019 at 11:28.
    My RAM is failing

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. MAX7219 random faults
    By See_Mos in forum The Lounge
    Replies: 1
    Last Post: 22nd May 2017, 05:06
  2. MAX7219 sample code, Need some directions
    By seconika in forum Proton Plus Compiler v3
    Replies: 6
    Last Post: 27th December 2010, 10:53
  3. max7219 & interrupts
    By chuckieboy in forum Proton Plus Compiler v3
    Replies: 6
    Last Post: 7th July 2008, 20:57
  4. MAX7219 Tap On
    By _Gabi_ in forum The Lounge
    Replies: 2
    Last Post: 8th January 2008, 15:22
  5. ADC with a MAX7219
    By chuckieboy in forum Proton Plus Compiler v3
    Replies: 15
    Last Post: 2nd January 2007, 19:13

Members who have read this thread since 3rd August 2019, 14:45 : 19

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts