max7219 4x 8x8 panels spi


+ Reply to Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087

    Default max7219 4x 8x8 panels spi

    for pic16 with spi port . 5 digits 6x5 numeric font right justified with leading zero suppression
    Attached Files Attached Files
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    A bit late but just noticed this valuable post! Thanks once again.

    Is this driver for such a display?
    Attached Images Attached Images  

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi


    looks the same
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Thanks!

    Really cheap toys to play with!

    Ioannis

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Since I have on hand only 16F1827, I modified the code for the PortC pins but as expected does not work. Modifications in red.

    I really do not know what lata.5 does in your code. Maybe a led to sign start?

    Code:
       '****************************************************************
    '*  Name    : max7219 16f1825                                      *
    '*  Author  : richard                                              *
    '*  Notice  : Copyright (c) 2019                                   *
    '*          :                                                      *
    '*  Date    : 25/2/2020                                            *
    '*  Version : 1.1                                                  *
    '*  Notes   : max7219   5 6x5 chrs on 4 8x8 panels                 *
    '*          : right justified leading zero suppression             *
    '*          :                                                      * 
    '*          :                                                      * 
    '*          : modified for pic16f1827                              *
    '*******************************************************************
    
    #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_OFF  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
     
    
    define OSC 32
    goto overasm 
    asm
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
        movlw High Label         ; get high byte
        movwf Wout + 1
        endm
    endasm
    overasm:
    
    SSPCON1 = $20;
    SSPSTAT = $40;
    ANSELA = 0
    ANSELB = 0
    OSCCON = $70
    
    tmp      var byte
    dsp      var byte
    dspbuff  var byte[32]
    BUFF     var byte[16]
    cnt      var byte
    row      var byte
    drow     var byte
    srow     var byte
    col      var byte
    dcol     var byte
    aFont    var word
    fOffset  var word
    cga      var byte
    cgah     var byte
    ch       var byte
    chr      var byte
    inx      var byte
    mask     var word
    counter  var word
    bcnt     var byte
    ncnt     var byte
    number  var word
    
    clear
    
    'mxld     var portc.1
    'mxck     var portc.0
    'mxdi     var portc.2
    mxld     var portb.1
    mxck     var portb.4
    mxdi     var porta.6
    
    'trisc = %11111000
    'trisa = %11011110
    trisb = 0
    trisa = 0
    
     
    init:
        lata.5 = 1
        mxld = 1
        dsp = 11
        tmp = 5
        gosub xfer4
        dsp = 9
        tmp = 0
        gosub xfer4
        dsp = 12 
        tmp = 1
        gosub xfer4
        dsp = 10
        tmp = 8     
        gosub xfer4
        dsp = $b
        tmp = 7     
        gosub xfer4
        dsp = $f
        tmp = 0     
        gosub xfer4
    @ GetAddress _font,_aFont
    
     
    loopy:
        row = 1:col = 1  
        gosub showrjbuf
        gosub  strchr
        gosub show
        counter  =  counter + 1
        pause 100
    GOTO loopy
    end	 
    
    strchr:     ;null  terminated
        bcnt = 0
        while buff[bcnt]
            chr = buff[bcnt]
            gosub gcga 
            bcnt = bcnt + 1
            col = col + 6
        wend
    return 
     
    show:     
        for srow = 0 to 7
            GOSUB SHOWROW 
        next 
    return        
       
    showROW:      
        	mxld = 0		
       	    for dcol = 0 to 3        	 
            	 SSPBUF = srow + 1 
                 while !pir1.3:wend
                 pir1.3 = 0
                 SSPBUF = dspbuff[(srow<<2) + dcol]  rev 8
                 while !pir1.3:wend
                 pir1.3 = 0    
            next 
        	mxld = 1 
    return     
    
    
    xfer4:
         for dcol = 0 to 3
             mxld = 0
             pir1.3 = 0
             SSPBUF = dsp  
             while !pir1.3:wend
             pir1.3=0
             SSPBUF =tmp 
             while !pir1.3:wend
             pir1.3 = 0
         next
         mxld = 1 
    return
    
    gcga:      ;ROW= 0-1 COL=0-28 CHR = SPACE,"0" TO ";"
        if chr = " " then chr = ";"   ;TRANSLATE SPACE TO ";"
        fOffset = (chr - "0")*3 + aFont  ; point to cga data
        drow = row  ;0 or 1
        mask = ~(63<<(col//8))
        inx = col/8
        for tmp = 0 to 2 
            gosub unpack
            inx = (drow<<2) + col/8 
            dspbuff[inx] = dspbuff[inx] & mask.lowbyte
            dspbuff[inx] = dspbuff[inx] | (cga<<(col//8))         
            if  mask.highbyte then
                INX = INX + 1
                dspbuff[inx] = dspbuff[inx] & mask.highbyte
                dspbuff[inx] = dspbuff[inx] | (cga>>(8-col//8) )
                inx = inx + 3
            else
                inx = inx + 4
            endif
    '        SROW=DROW
    '        GOSUB SHOWROW
    '        PAUSE 50
            drow = drow + 1
            dspbuff[inx] = dspbuff[inx] & mask.lowbyte
            dspbuff[inx] = dspbuff[inx] | (cgah<<(col//8))
            if  mask.highbyte then
                INX = INX+1
                dspbuff[inx] = dspbuff[inx] & mask.highbyte
                dspbuff[inx] = dspbuff[inx] | (cgah>>(8 - col//8) )
            endif
    '        SROW=DROW
    '        GOSUB SHOWROW
    '        PAUSE 50
            drow = drow + 1
            fOffset = fOffset + 1
         next            
    return  
            
     
    showrjbuf:    ;load  buff righ justified
        number = counter
        for ncnt = 0 to 4
            BUFF[ncnt] = $30
        next
        while number >10000
            buff[0] = buff[0] + 1
            number = number - 10000
        wend
        while number >1000
            buff[1] = buff[1] + 1
            number = number - 1000
        wend 
        while number>100
            buff[2] = buff[2] + 1
            number = number - 100
        wend 
        while number >10
            buff[3] = buff[3] + 1
            number = number -10
        wend 
        buff[4] = buff[4] + number    
    lzr:       ;repress leading zeros
        for ncnt = 0 to 3
          if BUFF[ncnt] == $30 then
               BUFF[ncnt] = $20
          else
              return
          endif
        next
    return
     
           
    
    unpack:
      asm
        CHK?RP  _fOffset
        MOVF _fOffset+1,W
        CHK?RP   EEADRH
        MOVWF EEADRH ;MS Byte of Program Address to read
        CHK?RP  _fOffset
        MOVF _fOffset,W
        CHK?RP   EEADR
        MOVWF EEADR ;LS Byte of Program Address to read
        CHK?RP   EECON1
        BSF EECON1, EEPGD ;Point to PROGRAM memory
        BSF EECON1, RD ;EE Read
        NOP
        NOP 
        CHK?RP   EEDAT              ;UNPACK DATA
        RLF    EEDAT, W 
        RLF    EEDATH, W
        CHK?RP  _cgah
        MOVWF   _cgah
        CHK?RP   EEDAT
        BCF    EEDAT,7
        MOVF   EEDAT,W 
        CHK?RP  _cga
        MOVWF   _cga
        RST?RP 
        return        
     endasm 
    
    
    '//Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0
    '//MikroElektrnika 2011 
    '//http://www.mikroe.com 
    
    '//GLCD FontName : Untitled5x6
    '//GLCD FontSize : 5 x 6
    
    'const unsigned short Untitled5x6[] = {
    font :      ;in packed format for pic16 dw lines
    ;@ db  0x0E,0x11,0x11,0x11,0x11,0x0E;                                                   // Code for char num 48  0
    @ dw    0x88e,0x891,0x711    ;                                           
    ;@ db   0x04,0x06,0x04,0x04,0x04,0x0E;                                                  // Code for char num 49  1
    @ dw    0x304,0x204,0x704
    ;@ db   0x0E,0x11,0x08,0x04,0x02,0x1F;                                                  // Code for char num 50
    @ dw   0x88e,0x208,0xf82
    ;@ db   0x0E,0x10,0x1C,0x10,0x10,0x0E;                                                  // Code for char num 51
    @ dw    0x80e,0xe10,0x710
    ;@ db   0x01,0x01,0x05,0x1F,0x04,0x04;                                                  // Code for char num 52
    @ dw    0x81,0xf85,0x204
    ;@ db   0x0F,0x01,0x01,0x0E,0x10,0x0F;                                                  // Code for char num 53
    @ dw    0x8f,0x701,0x790
    ;@ db   0x0E,0x11,0x01,0x0F,0x11,0x0E;                                                  // Code for char num 54  6
    @ dw   0x88e,0x781,0x711 
    ;@ db   0x1F,0x10,0x08,0x04,0x02,0x02;                                                  // Code for char num 55 
    @ dw    0x81f,0x208,0x102
    ;@ db   0x0E,0x11,0x11,0x0E,0x11,0x0E;                                                  // Code for char num 56  8
    @ dw    0x88e,0x88e ,0x711 
    ;@ db   0x0E,0x11,0x11,0x1E,0x10,0x0E;                                                  // Code for char num 57  
    @ dw   0x88e,0xf11,0x711
    ;@ db   0x00,0x04,0x00,0x00,0x04,0x00;                                                  // Code for char num 58  ;
    @ dw    0x200,0,0x200                                                                    
    ;@ db   0x00,0x00,0x00,0x00,0x00,0x00;                                                   // space
    @ dw     0,0, 0
    Ioannis

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Since I have on hand only 16F1827, I modified the code for the PortC pins but as expected does not work. Modifications in red.

    default sdo for that chip is rb2, for mxdi var porta.6 ​you need to set apfcon0.6




    I really do not know what lata.5 does in your code. Maybe a led to sign start?
    nether do i , most probably a trigger for log analyzer
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Well, I was just about to post that logic analyzer keeps data at zero. I was watching that and could not think what was wrong...!

    Doh!

    Thanks Richard. Works now.

    Ioannis

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    What is the logic in the packing of the characters into words?

    Ioannis

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    What is the logic in the packing of the characters into words?
    uses half the amount of flash memory when using 7bit numbers [pic16 flash is 14 bits wide] so you need to pack it.
    it takes very little time for the pic to unpack so there is no real penalty for a huge saving
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Yes, OK. But from 6 bytes you went to 3 words. Cannot understand the calculation you did.

    ;@ db 0x0E,0x10,0x1C,0x10,0x10,0x0E; // Code for char num 51 "3"
    @ dw 0x80e,0xe10,0x710

    0E=00001110, 10=00010000 and all these makes 80E?

    Ioannis

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    0xE=0b00001110, 0x10=0b00010000


    and all these makes 80E

    7 high bits | 7 low bits
    0x10<<7 | 0x0e &0x7f = 0x80e
    0b000100000000000 | 0b0001110 = 0b00010000001110 <==> 0x80e [14 bits]
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    After making the paper and pencil homework, I was amazed by your thinking! So simple, so clever, so efficient!

    Ioannis

  13. #13
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Mikroe outputs the characters in columns but your data is in rows. Did you rotate them by hand or can GLCD do that?

    Ioannis

  14. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Last edited by richard; - 16th January 2022 at 11:54.
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  15. #15
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Well, results don't match.

    I do this:

    1. on GLCD Font Creator 5x6 is selected since that is what says in the program: '//GLCD FontSize : 5 x 6

    Name:  1.JPG
Views: 50
Size:  22.3 KB

    2. Then the character 48 is designed

    Name:  2.JPG
Views: 53
Size:  96.8 KB

    3.Then Export for GLCD

    Name:  4.JPG
Views: 50
Size:  82.5 KB

    The data do not match as can be seen. I am sure that I did something wrong, but what?

    Ioannis

  16. #16
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    thats glcd mode you need tft mode
    Attached Images Attached Images  
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  17. #17
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: max7219 4x 8x8 panels spi

    Yes, that did it.

    Thanks,
    Ioannis

  18. #18
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Question Re: max7219 4x 8x8 panels spi

    The 5x6 grid is not very roomy for good fonts. After a bit of experimenting I ended up with the rectangular fonts that follow. I thing they are readable from longer distance.

    Code:
    @ dw 0x89F,	0x891,	0xF91      ; 0
    @ dw 0x206,	0x204,	0xF84      ; 1
    @ dw 0x81F,	0x9F,	0xF81      ; 2
    @ dw 0x81F,	0x81E,	0xF90      ; 3
    @ dw 0x489,	0xF89,	0x408      ; 4
    @ dw 0x9F,	0x81F,	0xF90      ; 5
    @ dw 0x9F,	0x89F,	0xF91      ; 6
    @ dw 0x81F,	0x410,	0x408      ; 7
    @ dw 0x89F,	0x89F,	0xF91      ; 8
    @ dw 0x89F,	0x81F,	0xF90      ; 9
    @ dw 0x200,     0x0,	0x200      ; :
    @ dw 0,0,0                         ; space
    A small demo video is uloaded here:



    Ioannis
    Last edited by Ioannis; - 22nd January 2022 at 10:29.

Similar Threads

  1. 8x8 keypad matrix...
    By mbox in forum General
    Replies: 5
    Last Post: - 9th October 2014, 18:43
  2. 8x8 Scrolling LED display (Simple example)
    By wellyboot in forum Code Examples
    Replies: 68
    Last Post: - 11th July 2013, 05:03
  3. DC/DC with MPPT for solar panels
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 14th May 2013, 02:26
  4. MY FIRST scrolling 8X8 LED
    By earltyso in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th August 2008, 16:23
  5. SPI instead of SHIFTOUT - MAX7219
    By Momboz in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 26th April 2008, 22:58

Posting Permissions

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