A few Max7219 questions

Ga-Retired

New Member
Hi all,while getting to understand the Max7219 a little better and lots of different combinations of programmingI've settled on,at least for me, the program format presented by forum member" Westaust55".I've also included sections of my program from "Marks" for his magic math solutions I'm trying to use with the DS18B20 temperature sensor in my latest project.
Now to my problem which I've spent much time trying to resolve on my own and now must turn to the "experts' for help.Using the 4 digit CC led display with has been proven to 'work like a champ' with Westaust55 decimal counter using a 08m2,I now want to use the led display for a temperature readout with .1 degree resolution using Marks code snippet.

SYMBOL Ds18b20 = C.1
SYMBOL Temperature = W0 SYMBOL whole_degrees = b1 SYMBOL decimal_degrees = b0

Main:
Readtemp12 Ds18b20,Temperature

Convert:

Temperature = Temperature +880 *9 /5 - 1072 *16 'Fahrenheit (0.0F to 255.9F)
decimal_degrees = decimal_degrees **2560 ' (0.1)resolutuion

SERTXD (CR, LF, "Temperature ",#whole_degrees,".",#decimal_degrees," Degrees F", CR, LF)

PAUSE 1000
GOTO Main

To be to the point,all variables are set up,test mode works fine and DP =128 set to .1 resolution.So the problem I'm incuring is getting the proper numbers to be displayed on the readout in the proper format like:" 109.2 " in degrees F.I'm also using blanking on the leading zero's so will want something like' 89.6 ' degrees F. What I'm using now is : Units,Tens,Hundr,and Thous (which is defined in Symbol).
Units =Units //10
Tens =Tens /10
Hundr =Hundr /10//10
Thous = thous /10/10/10
Sertxd is reading out just like I expected,just can't get the correct value to the display.i appreciate all your suggestions and help and maybe I can,once and for all, complete this project and move to the next idea I want to use the Picaxe on.I realize there may be many questions about setup,code ect,ect but It seems I just don't have the right code in place to display the numbers correctly.
Thanks everyone,my best,Ga-Retired
 

marks

Senior Member
Hi Ga-Retired ,
i'm not sure whats required with the max7219
but perhaps this helps a bit .
Code:
SYMBOL Ds18b20      = C.0
SYMBOL Temperature  = W0 

SYMBOL units           = b4 
SYMBOL tens            = b5 
SYMBOL hunds           = b6 
SYMBOL thous           = b7

Main:
Readtemp12 Ds18b20,Temperature 
      
  Convert:                                      
       
  Temperature = Temperature  +880 *16 **4608 -670                  '  Fahrenheit (0.0F to 257.0F)
  units = temperature//10  
  tens  = temperature/10//10
  hunds = temperature/100//10
  thous = temperature/1000 
  
  
  IF  thous = 0 THEN : thous = " "-32                              ' leading zero blanking change (" "-32) to value required to blank digit
       IF hunds = 0 THEN : hunds = " "-32 : ENDIF                  ' leading zero blanking       ( will show 0 )
      ENDIF                          
    
 SERTXD (CR, LF, "Temperature ",#thous,#hunds,#tens,".",#units," degrees F", CR, LF) '  test   
GOTO Main
 

westaust55

Moderator
Calculation of the Tens digits will need to mask off higher digits so
Tens = Temperature / 10 // 10

Likewise for hundreds digit.

Edit:
As a worked example for the tens digit.
Say we have a number 9876 - so we are trying to extract the "7"
divide first by 10 so 9876 / 10 ==> 987
now take the modulus (remainder)of 10 to get the left most digit
so 987 // 10 ==> 7 that is the remainder of 987 / 10 (or 987 - (INT(987/10)*10) = 987 - 98*10 ==> 7)


Note that my oriignal code in the Getting started tutorial is:
Thous = Counter / Base / Base / Base
Hundr = Counter / Base / Base //Base
Tens = Counter / Base // Base
Units = Counter // Base

where "Base" could be 10 (for decimal), 16 (for hexadecimal) or other base like 8 for octal
 
Last edited:

Ga-Retired

New Member
Hi everyone,and a special thanks to "Marks & Westaust55" for their reply's to my dilemna on extracting numbers to be displayed correctly on the 4 digit Led readout.I will make these corrections and see what I come up with and report back with,hopefully, the results I'm looking for.Also,would like to thank "MartinM57" for his nice work which helped me fiquire out some bugs in my code that was dumbfounding me on this project.Thanks again guys,my best,Ga-Retired
 

Ga-Retired

New Member
Well guys back from implementing your suggestions and once again you have solved most of my problems,working just fine and displaying the correct nimbers now.However, (Calling Marks!),on your code that you posted for me,(Thank You) I'm somewhat confused(Nothing new about that,HaHa)about the "leading zero blanking on the "Thous and Hunds.
IF thous = 0 THEN : thous = " "-32 ' leading zero blanking change (" "-32) to value required to blank digit
IF hunds = 0 THEN : hunds = " "-32 : ENDIF ' leading zero blanking ( will show 0 )
ENDIF
The ====> " " -32 part plus the comment section. My "Symbol" for "DigitBlank = 15 to blank a digit so I placed 15 where you indicated a"value" and it blanked it just fine but when I checked the terminal read out it put a "15 ' in front of the displayed temperature.Example, Temp. displayed on 4 digit display was 65.3 ,terminal showed 1565.3.So,of course that showed I was doing something right,just probably not the right "Value " needed to display correctly on the terminal.I need for this to display correctely below 32 degrees F so I want to make sure I have everything coded right to accomplish this.
Thanks you all,your continued help is always appreicated,Ga-Retired
 

marks

Senior Member
Hi Ga-Retired ,
I should perhaps try to post more clearly
but you did work it out
now that yourve seen whats happening in the terminal
yourve probaly moved the blanking section.

using a highword was just an example *16**4608 = 1.125
this can be changed back too 9/8

extra statements are only need to go negative zero F
keep up the good work!
Code:
SYMBOL Ds18b20      = C.0
SYMBOL Temperature  = W0 

SYMBOL units           = b4 
SYMBOL tens            = b5 
SYMBOL hunds           = b6 
SYMBOL thous           = b7

Main:
Readtemp12 Ds18b20,Temperature 
 
  Convert:                                      
       
  Temperature = Temperature  +880 *9 /8 -670                  '  Fahrenheit (0.0F to 257.0F)
  units = temperature//10  
  tens  = temperature/10//10
  hunds = temperature/100//10
  thous = temperature/1000 
     
 SERTXD (CR, LF, "Temperature ",#thous,#hunds,#tens,".",#units," degrees F", CR, LF) '   no blanking
 
 DigitBlanking:                                                ' max7219
  IF  thous = 0 THEN : thous = 15                              ' leading zero blanking  
       IF hunds = 0 THEN : hunds = 15 : ENDIF                  ' leading zero blanking       
      ENDIF                          
    
GOTO Main
 

Ga-Retired

New Member
Hi everyone,just an update on this project.Thanks to the members that provided me with the info needed to complete the programming of my project I can say its working just the way I want,I'm very happy to get this part complete ........... finally! Thanks again to "Marks" for his great work and input.Also to "Westaust55" which was the basis for my project incorporating the Max7219,which by the way is a great IC for driving a bunch of Led's once you get to understand the critter better which I give credit also to "MartinM57" for his great contributions on this chip,thanks again guys,your help was greatly appreciated!Ga-Retired
 
Top