PDA

View Full Version : Show 4 different values on LED display using one display driver



Moskog
03-02-2010, 05:37 PM
I need some advice her. I am testing temperature readings on LED display using MAX7219 LED driver and a BS2.
The scenario is measuring temperature on four different places using four sensors that provide integer temperature readings, like 10C, 15C, 9C and 25C. And then display them all using one LED driver
I found this example code in Parallax App-docs and with this I can display one of the numbers right now on the right side of a four-digit display:

dispVal = temperature1и 'Let us say temperature1 is our first reading (decimal value 10)
иииииииииииииииииииииии 'temperature2 is 15 and so on.

Display:
nonZ = 0иииииииииииииииииииииииииииииииииииииииии ' Clear flag for 1st non-zero digit.
FOR index = 2 TO 1иииииииииииииииииииииииииииииии ' Work from digit 2 down to digit 1.
и SHIFTOUT MaxDATA_n,MaxCLK,MSBFIRST,[index]иииии ' Send digit position.
и temp = dispVal DIG (index-1)иииииииииииииииииии ' Get decimal digit (0-4) of dispVal.
и IF temp = 0 THEN skip1иииииииииииииииииииииииии ' If digit = 0, don't set nonZ flag.
и nonZ = 1
skip1:
и IF nonZ = 1 OR temp <> 0 OR index = 1 THEN skip2и ' If leading 0..
и temp = 15ииииииииииииииииииииииииииииииииииииииии '..write a blank to the display.
skip2:
и SHIFTOUT MaxDATA_n,MaxCLK,MSBFIRST,[temp]ииииииии ' Send the digit.
и PULSOUT MaxLoad,5ииииииииииииииииииииииииииииииии ' And load the display.
NEXTииииииииииииииииииииииииииииииииииииииииииииии и ' Repeat for all 4 digits.
RETURNииииииииииииииииииииииииииииииииииииииииииии и ' Done? Return.

Now, as an example, if I have an 8-digit LED display and I want to display all four readings on that display
so the display shows 10150925. (One single MAX7219 can handle eight digits), this is what I need help to do! In case of one digit reading the leading zero can be displayed.
---------------------------------------------------------------------------------------
In the end I am not going to use one 8-digit display but four 4-digits displays instead
where I use only the two left digits on each display to show the (dynamic) temperature readings. Then use the two remaining digits to the right to show the (static) degree-sign and the letter C, but those can be made by using resistors and not waste BS2 memory.
The main thing here is to use one single MAX7219 to display 4 different readings instead of have to use 4 different expensive display drivers.

Tracy Allen
03-03-2010, 01:08 AM
Most of the complexity of that display routine is involved with skipping the leading zeros--no doing so should be much simpler! I added one variable, "position" that would set the starting point for each dispVal.


Display:
FOR index = 1 TO 0 ' Work from digit 2 down to digit 1.
SHIFTOUT MaxDATA_n,MaxCLK,MSBFIRST,[index+position] ' Send digit position.
temp = dispVal DIG (index) ' Get decimal digit (1-0) of dispVal.
SHIFTOUT MaxDATA_n,MaxCLK,MSBFIRST,[temp] ' Send the digit.
PULSOUT MaxLoad,5 ' And load the display.
NEXT ' Repeat for all 2 digits.
RETURN ' Done? Return.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

Moskog
03-03-2010, 04:19 AM
Thank you, Tracy, that is exactly what I was looking for.
It is so amazing how simple a solution can be sometimes, I spent hours to figure out how and was never able to see it.
Just remove a lot of stuff and add a single Nib!
Works perfect, now I can continue with the project. Thanks again!