|
Forum Index : Microcontroller and PC projects : MAX7219 led display driver
| Author | Message | ||||
| viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
Hi All, From the thread "[MicroMite]AD9850 Controller Source Code" - Member Boss has posted some code that I believe needs to have its own thread. The MAX7219 is a very interesting chip and there are several different types of LED displays that are readily available to us uMiters that can add a bit of coolness to our projects. I have seen 8x8 matrix and 8 digit 7 segment displays and there are more. On ebay, they can be had quite reasonably. This chip uses spi communications and Boss has done a bang up job on providing some code that will get me going using this chip with little pain. This is a great example of using SPI to interface with. I pulled up the MAX7219 data sheet and Boss's code side by side on my screen and saw how he is addressing the different registers on the chip to make things happen. Very exciting!!! A BIG THANKS! I hope I am not out of line repeating Boss's code here. Again, THANKS BOSS!!!! '================================================== ' MAX7219 LED DISPLAY * '================================================= 'SPI PINS RX=1 TX=14 CLK=15 PLOAD=16 SetPin RX, DIN SetPin TX, DOUT SetPin CLK,DOUT SetPin PLOAD,DOUT Pin(14)=0 Pin(15)=0 PIN9160=0 '----------------------MAIN---------------------------- M7219_INIT TEST_E TEST_F DP 1 RAND_NUM End '===================================================== Sub M7219_INIT AA=SPI(RX,TX,CLK,&H0C00,,,16): Pulse PLOAD,1 'SHUTDOWN AA=SPI(RX,TX,CLK,&H09FF,,,16): Pulse PLOAD, 0.1 'BCD DECODE ALL DIGITS AA=SPI(RX,TX,CLK,&H0A08,,,16): Pulse PLOAD, 0.1 'BRIGHT 17/32% AA=SPI(RX,TX,CLK,&H0B07,,,16): Pulse PLOAD, 0.1 '8 DIGITS AA=SPI(RX,TX,CLK,&H0F00,,,16): Pulse PLOAD, 0.1 'TESTS OFF AA=SPI(RX,TX,CLK,&H0C01,,,16): Pulse PLOAD, 1 'RUN ERASE_ALL DP 1 ' . End Sub '----------------------------------------------------------- --- Sub ERASE_ALL Local I,AA For I=1 To 8 AA=SPI(RX,TX,CLK,&H000F+I*256,,,16): Pulse PLOAD,1 Next I End Sub '----------------------------------------------------------- Sub TEST_F Local AA AA=SPI(RX,TX,CLK,&H0F01,,,16): Pulse PLOAD,1 Pause 3000 AA=SPI(RX,TX,CLK,&H0F00,,,16): Pulse PLOAD,1 End Sub '---------------------------------------------------------- Sub TEST_E Local I,J,AA For I=1 To 8 For J=1 To 15 AA=SPI(RX,TX,CLK,I*256+J,,,16): Pulse PLOAD,0.1 Pause 200 Next J Pause 300 Next I End Sub '----------------------------------------------------------- - Sub DP (T) Local AA If T<1 Or T>8 Then T=1 AA=SPI(RX,TX,CLK,T*256+&H8F,,,16): Pulse PLOAD,0.1 End Sub '----------------------------------------------------------- Sub RAND_NUM (RN) Local I,J,RN$,B Do Randomize Timer ERASE_ALL RN=Rnd()*1000000 RN$=Str$(RN) J=Len(RN$) For I=1 To J A$=Mid$(RN$,I,1) C=Val(A$) AA=SPI(RX,TX,CLK,(J-I+1)*256+C,,,16): Pulse PLOAD,0.1 Next I ' Print RN;RN$ Pause 1000 Loop End Sub |
||||
| viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
Upon further examination of this code, it was written for the Maximite series. So if you want to use this on a uMite, there are a few changes needed, such as the pins being used are very specific to both the 28 and 44 pin uMites. Also, the spi channel must first be opened, and also closed. Take a look at page 66 of the uMite manual to see the changes necessary. Sorry to jump the gun. When my spi displays arrive, I will post my results and subsequent code changes. |
||||
| Frank N. Furter Guru Joined: 28/05/2012 Location: GermanyPosts: 985 |
Hi All, special thanks to Member Boss and to Viscomjim for sharing this code. I adapted the code successful to White Wizzards 44pin Micromite module: '==================================================
' MAX7219 LED DISPLAY for 44pin µMite * '================================================= 'SPI PINS SPI OPEN 3000000, 3, 16 'RX not needed 'TX=20 'CLK=14 PLOAD=5 SetPin PLOAD,DOUT '----------------------MAIN---------------------------- M7219_INIT TEST_E TEST_F DP 1 RAND_NUM End '===================================================== Sub M7219_INIT AA=SPI(&H0C00): Pulse PLOAD,1 'SHUTDOWN AA=SPI(&H09FF): Pulse PLOAD, 0.1 'BCD DECODE ALL DIGITS AA=SPI(&H0A08): Pulse PLOAD, 0.1 'BRIGHT 17/32% AA=SPI(&H0B07): Pulse PLOAD, 0.1 '8 DIGITS AA=SPI(&H0F00): Pulse PLOAD, 0.1 'TESTS OFF AA=SPI(&H0C01): Pulse PLOAD, 1 'RUN ERASE_ALL DP 1 ' . End Sub '----------------------------------------------------------- --- Sub ERASE_ALL Local I,AA For I=1 To 8 AA=SPI(&H000F+I*256): Pulse PLOAD,1 Next I End Sub '----------------------------------------------------------- Sub TEST_F Local AA AA=SPI(&H0F01): Pulse PLOAD,1 Pause 3000 AA=SPI(&H0F00): Pulse PLOAD,1 End Sub '---------------------------------------------------------- Sub TEST_E Local I,J,AA For I=1 To 8 For J=1 To 15 AA=SPI(I*256+J): Pulse PLOAD,0.1 Pause 200 Next J Pause 300 Next I End Sub '----------------------------------------------------------- - Sub DP (T) Local AA If T<1 Or T>8 Then T=1 AA=SPI(T*256+&H8F): Pulse PLOAD,0.1 End Sub '----------------------------------------------------------- Sub RAND_NUM (RN) Local I,J,RN$,B Do Randomize Timer ERASE_ALL RN=Rnd()*1000000 RN$=Str$(RN) J=Len(RN$) For I=1 To J A$=Mid$(RN$,I,1) C=Val(A$) AA=SPI((J-I+1)*256+C): Pulse PLOAD,0.1 Next I ' Print RN;RN$ Pause 1000 Loop End Sub Thanks again Frank |
||||
| boss Senior Member Joined: 19/08/2011 Location: CanadaPosts: 268 |
Hi, I'm glad you found this code usable, Thank you
boss |
||||
Cyber![]() Senior Member Joined: 13/01/2019 Location: UkrainePosts: 161 |
Thanx a lot! The code helped me to figure out how things work. I also modified the code for use with 8x8 matrix. Below is my code and video of how it works. Hope this also helps someone. Datasheet: 2019-07-04_093638_MAX7219-MAX7221.pdf Video: https://youtu.be/6bcrovHx6Os '================================================== ' MAX7219 LED DISPLAY * 8X8 MATRIX '================================================= 'SPI PINS RX=1 ' MISO, DIN TX=14 ' MOSI, DOUT CLK=15 ' SCLK, CLOCK PLOAD=16 ' SS, CS SETPIN RX, DIN SETPIN TX, DOUT SETPIN CLK,DOUT SETPIN PLOAD,DOUT PIN(TX)=0 PIN(CLK)=0 PIN(PLOAD)=0 '----------------------MAIN---------------------------- M7219_INIT TEST_F 'DISPLAY TEST MODE TEST_E 'ALL LED ON/OFF COMBINATIONS RAND_LINE 'DRAW RANDOM PATTERNS ANIM_ARROW 'ANIMATION ERASE_ALL 'CLEAR SCREEN END '====================================================== SUB M7219_INIT AA=SPI(RX,TX,CLK,&H0C00,,,16): PULSE PLOAD,1 'SHUTDOWN MODE ON AA=SPI(RX,TX,CLK,&H0900,,,16): PULSE PLOAD, 0.1 'NO DECODE AA=SPI(RX,TX,CLK,&H0A08,,,16): PULSE PLOAD, 0.1 'BRIGHT 17/32 AA=SPI(RX,TX,CLK,&H0B07,,,16): PULSE PLOAD, 0.1 'SCAN-LIMIT ALL AA=SPI(RX,TX,CLK,&H0F00,,,16): PULSE PLOAD, 0.1 'TESTS OFF AA=SPI(RX,TX,CLK,&H0C01,,,16): PULSE PLOAD, 1 'SHUTDOWN MODE OFF ERASE_ALL 'CLEAR SCREEN END SUB '----------------------------------------------------------- SUB ERASE_ALL LOCAL I,AA FOR I=1 TO 8 'FOR EACH LINE AA=SPI(RX,TX,CLK,I*256,,,16): PULSE PLOAD,1 'CLEAR LINE NEXT I END SUB '----------------------------------------------------------- SUB TEST_F LOCAL AA AA=SPI(RX,TX,CLK,&H0F01,,,16): PULSE PLOAD,1 'DISPLAY TEST MODE ON PAUSE 3000 AA=SPI(RX,TX,CLK,&H0F00,,,16): PULSE PLOAD,1 'DISPLAY TEST MODE OFF END SUB '---------------------------------------------------------- SUB TEST_E LOCAL I,J,AA FOR I=1 TO 8 FOR J=0 TO 255 AA=SPI(RX,TX,CLK, I*256+J ,,,16): PULSE PLOAD,0.1 PAUSE 10 NEXT J PAUSE 500 NEXT I PAUSE 1000 END SUB '----------------------------------------------------------- SUB RAND_LINE LOCAL F,I,R,AA FOR F = 1 TO 50 FOR I = 1 TO 8 R = CINT(RND() * 255) AA = SPI(RX, TX, CLK, I*256 + R, , , 16) : PULSE PLOAD, 0.1 NEXT I PAUSE 100 NEXT F END SUB '----------------------------------------------------------- SUB ANIM_ARROW LOCAL D(7), F, K, R, N, AA D(0) = &B00010000 D(1) = &B00111000 D(2) = &B01111100 D(3) = &B11111110 D(4) = &B00111000 D(5) = &B00111000 D(6) = &B00111000 D(7) = &B00000000 FOR F = 1 TO 10 FOR K = -1 TO 6 FOR R = 1 TO 8 N = R + K IF N > 7 THEN N = N - 8 AA = SPI(RX, TX, CLK, R*256 + D(N), , , 16) : PULSE PLOAD, 0.1 NEXT R PAUSE 100 NEXT K NEXT F END SUB |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
timely! I have one of these chips in a design for an electronic dial in a Harley Davidson FDX bike (for a customer). I am using it not as a matrix controller, but simply as a display adapter for 24 individual LEDs (rev counter) and a clock (4 x seven segment) module. The board is all made up but not tested and the code is embryonic because a key part of the head unit is being supplied from a crowd-funded source which is typically, running late. This old thread, which I was not aware of, and the demo code will prove useful as I progress. thanks for bringing this up On the subject of that beeline thing, I had thought of doing it all with a MM... GPS... bit of maths... one of those round LCDs... but it is quite a complex beast - it isn't simply a bearing and distance but is a full-blooded navi-com just with a simplistic (non-map based) display. If it was simply a "your destination is 2 miles that-a-way" it would have been a piece of cake, but that could take the rider over a cliff... the beeline knows about the roads. The memory alone for that is way over the abilities of a mite and a GSM connection can't be guaranteed to let google do it. It is possible with their API on tiny systems - easily a mite, but you need network all the time. |
||||
bigmik![]() Guru Joined: 20/06/2011 Location: AustraliaPosts: 2971 |
Hi viscomjim, cyber, Some time ago Curtis Pratt and I came up with the Mik-Matrix which uses 2 x max7219 per module and creates a 3 colour matrix and moving message board.. Curtis taught himself C to get the speed required to manipulate the data and came up with a very nice lump of code.. Kind Regards, Mick Edit *** The sample vid clips look more jerky than the actual module. It was hard to video showing the brilliant colours. (Read near impossible) Mik Edit 2 *** I am happy to send you a few PCB if you want to play but I am on holidays for another week. Mik Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
| Justplayin Guru Joined: 31/01/2014 Location: United StatesPosts: 330 |
Since the TBS search feature is currently offline I can not point to the original thread I posted these to. These are my original efforts with the MAX7219 and mono-matrix 8x8 displays. Micromite 170 Powered Clock: http://youtu.be/va1OBuAXC0s Halloween Animation: https://www.youtube.com/watch?v=o5LF-GLEE9w --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
Cyber![]() Senior Member Joined: 13/01/2019 Location: UkrainePosts: 161 |
Why can't you? You mean this thread? https://www.thebackshed.com/forum/forum_posts.asp?TID=7916 |
||||
| Justplayin Guru Joined: 31/01/2014 Location: United StatesPosts: 330 |
I did not realize I could find old posts using a profile... Learned something new. I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
bigmik![]() Guru Joined: 20/06/2011 Location: AustraliaPosts: 2971 |
Lads, I didn’t know search was off line. Does Gizmo realise it isn’t working.? Mik PS. Enjoying the sun in Mulwala NSW Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
| BrianP Senior Member Joined: 30/03/2017 Location: AustraliaPosts: 292 |
@bigmik - see the "forum is ill" sticky post at the very top... |
||||
bigmik![]() Guru Joined: 20/06/2011 Location: AustraliaPosts: 2971 |
Thanks Brian, I usually skip the stickies to read the micro posts... Shows I should’ve more attentive to things.. Regards, Mik Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
| BrianP Senior Member Joined: 30/03/2017 Location: AustraliaPosts: 292 |
Join the club... |
||||
Cyber![]() Senior Member Joined: 13/01/2019 Location: UkrainePosts: 161 |
That's how I found it. :) Also you can type in google: site:www.somesite.com text to find For example: https://www.google.com/search?q=site:www.thebackshed.com+8x8+matrix+led |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
Now that is new (for me) live & learn - Thanks! |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |