I recently received one of the cheap 8 digit led displays run by a max7219.
When I went looking for a demo, all I could find was demos for a max7219 hooked up to an 8x8 led matrix, and using the GLCD graphic display driver.
I can see from these demos how to do the front end. Connect the spi pins for clock and data, and two random pins connected to cs and di. Since I'm not planning on reading the display, I guess DI is unnecessary. From one of the demos (comments are mine and may be incorrect) -
'Set SPI pins for the Max7219
#defineMax7219_DOportb.5' spi data as set in pps routine
#defineMax7219_SCKportb.3' spi clock as set in pps routine
#defineMax7219_CSportc.3' random pin connected to cs for library to use
#defineMax7219_DIportb.4' do I need to connect a pin if I don'tread?
Then I am at a loss for what to do next. Since this not set up as an 8x8 matrix, it doesn't make sense to use the graphic GLCD display driver routines.
What do I use to simply show a number on the display?
I'm going to press on, and I'll figure it out in a few days, but I thought someone must have used one of these before and could save me some time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I got same display but 4 connected and there's a scrolling demo but I never worked out what was happening..ie understood it.
I have two that can be joined and wanted a pixel/led addressable 16x32 display...made from two 8x32.. each an 8x8 unit. Too hard for me.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been using these for a couple years. I almost made a library for them but was distracted and never finished. Just copy in the subs and use. This little project ,I was measuring a positive/ negative voltage on the input to a servo(not the toy ones).
'Plus and minus voltage +-10 vdc input to the adc'using resistor network of 3 resistors - no opamps' Vcc+5 -<22K >---adc input^|-----<12k>--gnd' inputvoltage --<80K>------|'10bit adc reads 300 dec when input touched to gnd'' MAX7219 Driver for Great Cow Basic'' using Hardware SPI routines for Great Cow BASIC' Copyright (C) 2016 - Mike Otte ,PearlCity IL' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' Lesser General Public License for more details.' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA'********************************************************************************'IMPORTANT:'THIS FILE IS ESSENTIAL FOR SOME OF THE COMMANDS IN GCBASIC. DO NOT ALTER THIS FILE'UNLESS YOU KNOW WHAT YOU ARE DOING. CHANGING THIS FILE COULD RENDER SOME GCBASIC'COMMANDS UNUSABLE!'********************************************************************************'Changes: Aug 2016 written'Register Address map of commands'NO-OP 0xX0 0x00'Digit 0 0xX1 0x01'Digit 1 0xX2 0x02'Digit 2 0xX3 0x03'Digit 3 0xX4 0x04'Digit 4 0xX5 0x05'Digit 5 0xX6 0x06'Digit 6 0xX7 0x07'Digit 7 0xX8 0x08'Decode 0xX9 0x09'Intesity 0xXA 0x0A'ScanLim 0xXB 0x0B'Shutdown 0xXC 0x0C'DispTest 0xXF 0x0F' 16 bits spi transfer for each digit/COMMANDS'clock rising - data read'Load pin low to allow clocked in data'Sub routines list'Initialize'set decode mode'set intensity of digit x'set san limit'writeToDigitX(address,data)'TurnOn Display'Changes:
#chip16F886, 8
#defineCSPortA.5' out
#defineSCKPortC.3'clk out
#defineMOSIPortC.4'in
#defineMISOPortC.5'outCS=1'Set SPI pin directionsdirPORTC.5out'SDOdirPORTC.4in'SDIdirPORTC.3out'SCKdirPORTA.5out'SS loadDimcount,myValueasWord'Set SPI Mode to master, with fast clock'SPIMode MasterFast,0SPIMode(MasterFast, SPI_CPOL_0+SPI_CPHA_0)'SSPSTAT = 0x40 'spimodewasnotsetcorrectlyinmyGCcompiler'SSPCON1 = 0x20InitMax7219_7segdomyValue=ReadAD10(AN1)IfmyValue>=297thenmyValue=(myValue-297)*10/16MLED_write(5 ,0x0F)elsemyValue=(297-myValue)*10/16MLED_write(5 ,0x0A)endifMLED_Dec(myValue , 4)wait1sLoopsubInitMax7219_7segcs=1wait100ms'set decode modeMLED_write(0x09 , 0xFF)'set intensity 3/4MLED_write(0x0A , 0x06)'set scan limitMLED_write(0x0B , 0x07)'set display ONMLED_write(0x0C , 0x01)Forcount=1to8MLED_write(count,0x0F)'Clear digitsnextendsubsubMLED_write(cmd , dayta)#NRcs=0serBuf=0x00'empty bucketSPITransfercmd, serBufserBuf=0x00'empty bucketSPITransferdayta, serBufcs=1endsubSubMLED_Int(InMLEDValue,InNumDig)MLEDValueTemp=0MLED_write(NumDig,0x0F)MLED_write(NumDig-1,0x0F)MLED_write(NumDig-2,0x0F)IFMLEDValue>=100ThenMLEDValueTemp=MLEDValue/100MLEDValue=SysCalcTempXMLED_write(NumDig ,MLEDValueTemp)'NumDig--EndIfIfMLEDValueTemp>0OrMLEDValue>=10ThenMLEDValueTemp=MLEDValue/10MLEDValue=SysCalcTempXMLED_write(NumDig-1 ,MLEDValueTemp)'NumDig--EndIfMLEDValueTemp=MLEDValueMLED_write(NumDig-2 ,MLEDValueTemp)EndSubSubMLED_Dec(InMLEDValueasword,InNumDig)MLEDValueTemp=0MLED_write(NumDig,0x0F)MLED_write(NumDig-1,0x0F)MLED_write(NumDig-2,0x0F)MLED_write(NumDig-3,0x0F)IFMLEDValue>=1000ThenMLEDValueTemp=MLEDValue/1000MLEDValue=SysCalcTempXMLED_write(NumDig ,MLEDValueTemp)'NumDig--EndIfIFMLEDValueTemp>0OrMLEDValue>=100ThenMLEDValueTemp=MLEDValue/100MLEDValue=SysCalcTempXMLED_write(NumDig-1 ,MLEDValueTemp)'NumDig--EndIfIfMLEDValueTemp>0OrMLEDValue>=10ThenMLEDValueTemp=MLEDValue/10MLEDValue=SysCalcTempXMLED_write(NumDig-2 ,MLEDValueTemp+0x80)'NumDig--EndIfMLEDValueTemp=MLEDValueMLED_write(NumDig-3 ,MLEDValueTemp)EndSub
Have fun!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, I tried mmotte's program and got the same results. Any write to the max7219 results in all segments on, just as if I did a "display test ". Either a wiring error, which I've check multiple times, or this unit from China is just no good.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are absolutely correct. I did have the pps screwed up. Too much cut and paste. At least I'm getting something now, not correct, but encouraging! Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You will see this is most demos where SPI is used, or, can be used. There may be a variant of #define SPI_HardwareSPI for a specific device.
What does this do? If you comment this out then the software SPI is supported. This means that you do not need PPS or any SPIMode commands. As software SPImode does not required PPS of the setting of SPMode.
To complete the picture. Some SPI impmentations across the PIC range require SPIBAUD. The demos show how to use but essentially this is a speed adjuster.
My rule of thumb advice.
Always, always start with software SPI. Get the device operational then use hardware SPI.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
New demo program. Finally got pps right (thanks mmotte)
Edit- found undocumented mode MasterUltraFast, which at 32mhz no longer requires wait between sends, which makes the output MUCH faster.
' 8 digit led to Maxim 7219 demo program
#optionExplicit
#chip16F18325,32'Generated by PIC PPS Tool for Great Cow Basic for 16F18325
#startupInitPPS, 85
#definePPSToolPart16F18325SubInitPPSRC0PPS=0x0018'SCK1 > RC0SSP1CLKPPS=0x0010'RC0 > SCK1 (bi-directional)RC1PPS=0x0019'SDO1 > RC1EndSub
#defineSPI_HardwareSPISPIModeMasterUltraFast, 0dirportc.0out' clock sck1dirportc.1out' data out sdi1dirporta.2out' cs
#defineSpiCSporta.2' csgetsegsdimii,kkSpics=1doitb'00001001',b'11111111'' decode mode=set all digits to BCD Code Bdoitb'00001011',b'00000111'' multiplex all eight digitsdoitb'00001010',b'00001111'' max intensityerasebcd' erase all digitsdoitb'00001100',b'00000001'' turn on displaydoitb'00001111',b'00000001'' display test all digitswait1sdoitb'00001111',b'00000000'' turn off display testerasebcd' clear all digitswait500msforii=1to8doitii,ii-1' increasing from right to left using bcdnextiiwait2serasebcd' clear all digitswait500msdoitb'00001001',b'00000000'' set no-decode modeforii=1to8doitii,seg(9-ii)' increasing from left to right using non-bcdnextiiwait2serase'clear all digitswait500msdoit8,b'00000001'doit7,b'00110111'doit6,b'01001111'doit5,b'00001110'doit4,b'00001110'doit3,b'01111110'doit2,b'00000000'doit1,b'00111110'wait2serase' clear all digitswait500msdoitb'00001001',b'11111111'' decode mode=set all digits to BCD Code Bdimdig(9)' bcd value of digitforkk=1to8: dig(kk)=0: nextkkdoforkk=1to8dig(kk)++ifdig(kk)<10thendoitkk,dig(kk)exitFor' no more carrysendifdig(kk)=0doitkk,dig(kk)nextkk' loop back and do carryloopsubdoit(reg,value)' wait 250 us 'increaseifdigitsmisbehaving' not necessary if using MasterUltraFast spics=0FastHWSPITransferregFastHWSPITransfervaluespics=1endsubdimiksuberasebcd'erase all digits when in decode bcd modeforik=1to8: doitik,b'1111': nextikendsubsuberase'erase all digits in non-bcd modeforik=1to8: doitik,0: nextikendsubDimseg(11)subgetsegs' dABCDEFGseg(1)=b'01111110''0 - 1 Aseg(2)=b'00110000''1 | | 6 2 F Bseg(3)=b'01101101''2 - 7 Gseg(4)=b'01111001''3 | | 5 3 E Cseg(5)=b'00110011''4 - 4 E dpseg(6)=b'01011011''5seg(7)=b'01011111''6seg(8)=b'01110000''7seg(9)=b'01111111''8seg(10)=b'01111011''9seg(11)=b'10000000''.endsub
Last edit: Jim giordano 2019-11-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I recently received one of the cheap 8 digit led displays run by a max7219.
When I went looking for a demo, all I could find was demos for a max7219 hooked up to an 8x8 led matrix, and using the GLCD graphic display driver.
I can see from these demos how to do the front end. Connect the spi pins for clock and data, and two random pins connected to cs and di. Since I'm not planning on reading the display, I guess DI is unnecessary. From one of the demos (comments are mine and may be incorrect) -
Then I am at a loss for what to do next. Since this not set up as an 8x8 matrix, it doesn't make sense to use the graphic GLCD display driver routines.
What do I use to simply show a number on the display?
I'm going to press on, and I'll figure it out in a few days, but I thought someone must have used one of these before and could save me some time.
edit - deleted as newer code shown later
Last edit: Jim giordano 2019-11-15
I am stupid but shouldn't it be
I got same display but 4 connected and there's a scrolling demo but I never worked out what was happening..ie understood it.
I have two that can be joined and wanted a pixel/led addressable 16x32 display...made from two 8x32.. each an 8x8 unit. Too hard for me.
I have been using these for a couple years. I almost made a library for them but was distracted and never finished. Just copy in the subs and use. This little project ,I was measuring a positive/ negative voltage on the input to a servo(not the toy ones).
Have fun!
Thanks for that, I'll give it a try shortly.
Well, I think this should work unless I'm missing something important. Or I misunderstand how it works in general.
Yup, I was definately misunderstanding. Bad code deleted. Final working code below.
Last edit: Jim giordano 2019-11-15
Well, I tried mmotte's program and got the same results. Any write to the max7219 results in all segments on, just as if I did a "display test ". Either a wiring error, which I've check multiple times, or this unit from China is just no good.
Might it be the PPS setup?
• SDI must have corresponding TRIS bit set
• SDO must have corresponding TRIS bit cleared
• SCK (Master mode) must have corresponding
TRIS bit cleared
SDO instead of sda(i2c)
SPIMode gave me trouble those years ago. it is probably ironed out now.
SPIMode Master in yours
--
I see I must add #define SPI_HardwareSPI which we didn't need back then.
73
Mike
You are absolutely correct. I did have the pps screwed up. Too much cut and paste. At least I'm getting something now, not correct, but encouraging! Thanks.
And the final working solution :)
later- nope, still had pps screwed up.
Code deleted. New version farther down.
Last edit: Jim giordano 2019-11-15
An insight
#define SPI_HardwareSPI
You will see this is most demos where SPI is used, or, can be used. There may be a variant of
#define SPI_HardwareSPI
for a specific device.What does this do? If you comment this out then the software SPI is supported. This means that you do not need PPS or any SPIMode commands. As software SPImode does not required PPS of the setting of SPMode.
To complete the picture. Some SPI impmentations across the PIC range require SPIBAUD. The demos show how to use but essentially this is a speed adjuster.
My rule of thumb advice.
Always, always start with software SPI. Get the device operational then use hardware SPI.
New demo program. Finally got pps right (thanks mmotte)
Edit- found undocumented mode MasterUltraFast, which at 32mhz no longer requires wait between sends, which makes the output MUCH faster.
Last edit: Jim giordano 2019-11-15