Anyone know how to blank a separate 7-digit display on a MAX7219?
kingspud
Posts: 128
Hello all,
I have created a program that can be used to show two separate scores for a horseshoe game.
The program uses three buttons:· one button for incrementing player 1's score from 1 to 21,
another button for incrementing player 2's score from 1 to 21
and
the third button to reset all the displays to blanks for a new game.
The problem I am having is when you push the player buttons both digit displays start with ZEROS and they stay on the displays!· I am hoping someone knows how to start the scoring with only the single digit when the score is less than 10 and not have a zero show up in the display.
So...· instead of a 01 when you first hit the player buttons, you get only a 1 on display.
Thanks for any help
The code is tested and works great
Joe
Here is the code:
I am using·the BS2px24, a MAX7219 chip, and the PDB board with four of the 7-segment displays.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“Intellectual growth should commence at birth and cease only at death”
Albert Einstein
I have created a program that can be used to show two separate scores for a horseshoe game.
The program uses three buttons:· one button for incrementing player 1's score from 1 to 21,
another button for incrementing player 2's score from 1 to 21
and
the third button to reset all the displays to blanks for a new game.
The problem I am having is when you push the player buttons both digit displays start with ZEROS and they stay on the displays!· I am hoping someone knows how to start the scoring with only the single digit when the score is less than 10 and not have a zero show up in the display.
So...· instead of a 01 when you first hit the player buttons, you get only a 1 on display.
Thanks for any help
The code is tested and works great
Joe
Here is the code:
I am using·the BS2px24, a MAX7219 chip, and the PDB board with four of the 7-segment displays.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“Intellectual growth should commence at birth and cease only at death”
Albert Einstein
Comments
' {$STAMP BS2px}
' {$PBASIC 2.5}
' This program is used to create a score counter for Horseshoes
'
'The program has two buttons that each count up by 1 to 21
'
'The third button is used to reset the displays to all blanks
'
'
[noparse][[/noparse] I/O Definitions ]
'0 sets pin as input
'button PIN 0 makes the word button = pin 0
DIRS = $000E 'pins 1 2 3 output,all other pins outputs
DOUT PIN 1 'pin 1 of stamp to pin 1 of 7219
Load PIN 2 'pin 2 of stamp to pin 12 of 7219
CLK PIN 3 'pin 3 of stamp to pin 13 of 7219
'
[noparse][[/noparse] Constants ]
IsLow CON 0
IsHigh CON 1
'
[noparse][[/noparse] Variables ]
Digit0 VAR Word
Digit1 VAR Word
Digit2 VAR Word
Digit3 VAR Word
Value VAR Nib
score1 VAR Word
score2 VAR Word
'
[noparse][[/noparse] Variables ]
btn VAR Bit
'
[noparse][[/noparse] Initialization ]
Digit0 = $010F
Digit1 = $020F
Digit2 = $030F
Digit3 = $040F
score1=0
score2=0
'
[noparse][[/noparse] Main Program ]
main:
GOSUB DecodeMode
GOTO reset
loop1:
BUTTON 10,0,255,250,btn,1,press0
BUTTON 11,0,255,250,btn,1,press1
BUTTON 12,0,255,250,btn,1,press2
GOTO loop1
press0: 'Player 1 Press BUTTON [noparse][[/noparse]0] ON PIN 10 AND GOTO player1
GOSUB DecodeMode
GOTO player1
press1: 'Player 2 Press BUTTON ON PIN 11 AND GOTO player2
GOSUB DecodeMode
GOTO player2
press2: ' Reset Press BUTTON ON PIN 12 AND GOTO Reset
GOSUB DecodeMode
GOTO reset
'
[noparse][[/noparse] GOSUB RESET ]
reset:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0900\16]
HIGH Load
score1 = 1
score2 = 1
Digit0 = $0100 'BLANK
Digit1 = $0200 'BLANK
Digit2 = $0300 'BLANK
Digit3 = $0400 'BLANK
GOSUB board_display:
GOTO loop1
'
[noparse][[/noparse] GOSUB player1 ]
player1:
IF score1 < 10 THEN
Digit0 = score1 DIG 0 + $0100
ENDIF
IF score1 >= 10 THEN
Digit0 = score1 DIG 0 + $0100
Digit1 = score1 DIG 1 + $0200
ENDIF
IF score1 => 21 THEN
score1 = 20
ENDIF
score1 = score1 + 1
GOSUB board_display:
GOTO loop1
'
[noparse][[/noparse] GOSUB player2]
player2:
IF score2 < 10 THEN
Digit2 = score2 DIG 0 + $300
ENDIF
IF score2 >= 10 THEN
Digit2 = score2 DIG 0 + $0300
Digit3 = score2 DIG 1 + $0400
ENDIF
IF score2 => 21 THEN
score2 = 20
ENDIF
score2 = score2 + 1
GOSUB board_display:
GOTO loop1
'
[noparse][[/noparse] Subroutines ]
'Decode mode for no decoding to BCD
'Least sig nibble:
'0 = no decode
'1 = decode Digitit 0
'F = decode Digitits 0-3
'FF = decode Digitits 0-7
DecodeMode:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$090F\16]
HIGH Load
RETURN
board_display:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]Digit0\16]
HIGH Load
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]Digit1\16]
HIGH Load
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]Digit2\16]
HIGH Load
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]Digit3\16]
HIGH Load
PAUSE 400
RETURN
'
[noparse][[/noparse] GOSUB RESET ]
clear:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0900\16]
HIGH Load
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“Intellectual growth should commence at birth and cease only at death”
Albert Einstein
Try this for your BLANK routines towards the top of your program...
...in your initialization routine AND your reset routine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 6/24/2007 8:49:35 PM GMT
' {$STAMP BS2}
' {$PBASIC 2.5}
DataIO····· PIN···· 15························· ' 1302.6/1620.1/7219.1
Clock······ PIN···· 13························· ' 1302.7/1620.2/7219.13
Decode····· CON·· 9···························· ' Decode register; a 1 turns on BCD decoding.
Brite······ CON·· 10··························· ' "······ "·· " intensity register.
Scan······· CON·· 11··························· ' "······ "·· " scan-limit register.
Switch····· CON·· 12··························· ' "······ "·· " on/off register.
Test······· CON·· 15··························· ' Activates test mode (all digits on, 100% bright)
T·········· CON·· %1111
P·········· CON·· %1010
CWPr······· CON·· $8E·························· 'Write Protect Register
WPr1······· CON·· $80·························· 'Set Write Protect
RdBurst···· CON·· $BF·························· 'Read Burst Of Data
DecPnt····· CON·· %10000000···················· 'Decimal Point
Hr24······· CON·· 0···························· '24 Hour Mode
Hr12······· CON·· 1···························· '12 Hour Mode
Blank······ CON·· %1111························ 'Blank A Digit
X·········· VAR·· Word························· 'General purpose variable, byte.
DegF······· VAR·· Word························· 'Variable for Deg F.
DegC······· VAR·· Word
Sign······· VAR·· X.BIT15······················ 'Sign bit of X
Index······ VAR·· Byte························· 'Variable for Initialization of Max7219
Index1····· VAR·· Byte
Value1····· VAR·· Byte
Value2····· VAR·· Byte
Value3····· VAR·· Byte
MaxTemp···· VAR·· Word························· 'Variable used for Initialization of Max7219 - Temp
Odd········ VAR·· Index.BIT0··················· 'Lsb of Index.
Reg········ VAR·· Byte························· 'Read/Write Address
IoByte····· VAR·· Byte························· 'Data To/From Devices
d7219······ VAR·· Byte························· 'Data For MAX7219
Secs······· VAR·· Byte························· 'Seconds
Mins······· VAR·· Byte························· 'Minutes
Hrs········ VAR·· Byte························· 'Hours
Date······· VAR·· Byte························· 'Date
Month······ VAR·· Byte························· 'Month
Day········ VAR·· Nib·························· 'Day
Year······· VAR·· Byte························· 'Year
modeFlag··· VAR·· Bit·························· '0 = 24, 1 = 12 (Hours)
ampmFlag··· VAR·· Bit·························· '0 = AM, 1 = PM
'
Initialization
FREQOUT 3, 1000, 3800
'Max7219 for Temp
FOR Index = 0 TO 7····················· ' Retrieve 8 items from table.
· LOOKUP index,[noparse][[/noparse]Scan, 3, Brite, 15, Decode,$FF, Switch,1],MaxTemp
· SHIFTOUT DataIO, Clock,MSBFIRST,[noparse][[/noparse]MaxTemp]
· IF Odd = 0· THEN NoLoad·············· 'If odd is 1, pulse Load line.
· PULSOUT 14,5························· 'Latch The Data
NoLoad:································ 'Else, don't pulse.
NEXT··································· 'Get next item from table.
'Max7219 for Clock
FOR Index = 0 TO 7····················· ' Initialize MAX7219
· LOOKUP index, [noparse][[/noparse]Scan, 3, Brite, 15, Decode, $FF, Switch, 1], d7219
· SHIFTOUT DataIO, Clock, MSBFIRST, [noparse][[/noparse]d7219]
· IF Odd = 0 THEN NoLoad2
· PULSOUT 12, 5··················· ' Latch The Data
NoLoad2:································ 'Else, don't pulse.
NEXT··································· 'Get next item from table.
'DS1620
HIGH 0································· 'Select the DS1620.
SHIFTOUT 2, 1, LSBFIRST, [noparse][[/noparse]238]········· 'Send the "Start Conversions" command.
LOW 0·································· 'Do the command.
'DS1302
Reg = CWPr····························· ' Initialize DS1302
IoByte = WPr1·························· ' Set Write Protect
· HIGH 11······························ ' Select DS1302
· SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg, ioByte]
· LOW 11······························· ' Deselect DS1302
'
Main_Program
Main:
DO
· GOSUB Get_Temp························ 'Get Current Temp
· GOSUB Temperature_Display_Table······· 'Get Index VAR for Temp display
· GOSUB Display_Temp···················· 'Update 7-Seg Display
· GOSUB Get_Time························ 'Get Current Time/Date Data
· GOSUB Show_Time······················· 'Update 7-Seg Display
· GOSUB Door_1_Switch··················· 'Check if door 1 is Open or Closed
· DEBUG " ", HEX2 month, "/", HEX2 date, "/", HEX2 year, " " ,HEX2 hrs, ":", HEX2 mins," [noparse][[/noparse]", HEX2 secs, "]"
LOOP
'----Get_Temp_Sub
Get_Temp:
HIGH 0································· 'Select the DS1620
· SHIFTOUT 2, 1, LSBFIRST, [noparse][[/noparse]170]······· 'Send the "Get Data" command.
· SHIFTIN 2,1,LSBPRE, [noparse][[/noparse]X\9]············ 'Get the data.
LOW 0·································· 'End the command.
·· X.BYTE1 = -x.BIT8··················· 'Extend the sign to 16 bits
·· degC=x*5···························· 'Convert to 'C*10 (resolution 0.5 'C)
·· degF= degC+2732*9/50-459············ 'Convert to Fahrenheit
· DEBUG HOME··························· 'Set Debug to Home Position
· DEBUG "The Temp is ",DEC DegF,32,"Degrees", CR· 'Display The Temp in Debug
· RETURN································· 'Return to where you came from.
'----Display_Temp_Sub
Display_Temp:
'Diget #1
··· SHIFTOUT 15,13,MSBFIRST,[noparse][[/noparse]01]······· 'Send digit 1 position.
··· SHIFTOUT 15,13,MSBFIRST,[noparse][[/noparse]8]········ 'Send the digit.
··· PULSOUT 14,1······················· 'Load the display.
'Diget #2
· LOOKUP Index1, [noparse][[/noparse]0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0], value1
··· SHIFTOUT 15,13,MSBFIRST,[noparse][[/noparse]02]······· 'Send digit 2 position.
··· SHIFTOUT 15,13,MSBFIRST,[noparse][[/noparse]Value1]··· 'Send the digit.
··· PULSOUT 14,1······················· 'Load the display.
'Diget #3
· LOOKUP Index1, [noparse][[/noparse]5,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,%1111,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2], Value2
··· SHIFTOUT 15,13,MSBFIRST,[noparse][[/noparse]03]········· 'Send digit 3 position.
··· SHIFTOUT 15,13,MSBFIRST,[noparse][[/noparse]Value2]····· 'Send the digit.
··· PULSOUT 14,1························· 'Load the display.
'Diget #4
· LOOKUP Index1, [noparse][[/noparse]P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], Value3
··· SHIFTOUT 15,13,MSBFIRST,[noparse][[/noparse]04]········· 'Send digit 4 position.
··· SHIFTOUT 15,13,MSBFIRST,[noparse][[/noparse]Value3]····· 'Send the digit.
··· PULSOUT 14,1························· 'Load the display.
RETURN··································· 'Return to where you came from.
'
Temperature_Display_Table_Sub
Temperature_Display_Table:
LOOKDOWN DegF, [noparse][[/noparse]-50,-49,-48,-47,-46,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35,-34,-33,
················ -32,-31,-30,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15,
················· -14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,
·················· 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
··················· 37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,
···················· 62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,
····················· 87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,
······················ 109,110,111,112,113,114,115,116,117,118,119,120], Index1
RETURN································· 'Return to where you came from.
'
Get_Time_Sub
Get_Time:······························ ' DS1302 Burst Read
· HIGH 11······························ ' Select DS1302
· SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
· SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, date, month, day, year]
· LOW· 11······························ ' Deselect DS1302
···· IF mins = $00 AND secs = $00 THEN
···· GOSUB Hourly_Chime
···· ENDIF
· RETURN
'
Show_Time_Sub
Show_Time:
'Diget #1
· index = 1···························· ' Select Digit 1
· d7219 = mins.LOWNIB·················· ' Seconds (Ones Digit)
GOSUB Show_Max_Time
'Diget #2
· Index = 2···························· ' Select Digit 2
· d7219 = mins.HIGHNIB················· ' Seconds (Tens Digit)
GOSUB Show_Max_Time
'Diget #3
· Index = 3···························· ' Select Digit 5
· d7219 = hrs.LOWNIB··················· ' Hours (Ones Digit)
GOSUB Show_Max_Time·················· ' ^ PM Indicator
'Diget #4
·index = 4···························· ' Select Digit 6
· IF(hrs.HIGHNIB = %1011) THEN
· d7219 = 1
· ELSE
· d7219=blank
· ENDIF
· d7219 =d7219························ ' Blank Digit
GOSUB Show_Max_Time
RETURN
'
Show_Max_Time_Sub
Show_Max_Time:
· SHIFTOUT DataIO, Clock, MSBFIRST, [noparse][[/noparse]Index, d7219]
· PULSOUT 12, 5··················· ' Latch Data
RETURN
'
Hourly_Chime_Sub
Hourly_Chime:
··· FREQOUT 3, 100, 3800
··· PAUSE 100
··· FREQOUT 3, 100, 3800
··· PAUSE 100
··· FREQOUT 3, 100, 3800
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
In the Binary Digital Clock Project in the Completed Projects Forum I needed to keep the leading digit on the clock blank for times from 1:00 through 9:00 until it rolled over to 10:00. The code on that page may help you. It is fully documented and commented. I hope this helps. Take care.
http://forums.parallax.com/showthread.php?p=552892
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
So far I have tested Beau Schwabe·code and here are the results.
When I replaced the following code in the reset gosub with my code:
Digit0·=·$010F·'BLANK
Digit1·=·$020F·'BLANK
Digit2·=·$030F·'BLANK
Digit3·=·$040F·'BLANK
I received the following results...
When I turned on the device I initially get [noparse][[/noparse]4] small letter t's across all·[noparse][[/noparse]4] displays.
Then when you hit either player's button the displays blank and you only see a 1 on either of the player's displays... so this example works great BUT...
How do I get the small letter t to not show up on each display when I either hit reset or turn the power on?
I have done some investigating and found that '0F' is the hex equivalent to the small letter t and if I change the 0F value to anything else I get the corresponding display value for that hex code.
Yet... if I put in '00', which is the equivalent to a blank the displays with show zeros when I hit reset or a player button!· Why is this?· And also... why does the display go from a small t to a blank
When I hit the player button?· The·only thing I did was add the above mentioned code and I don't understand who it causes the displays to blank during the player button hits?
Thanks Beau,
I will test the other examples very soon and see what they do to help.
Thanks everyone and I hope this explanation helps.
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“Intellectual growth should commence at birth and cease only at death”
Albert Einstein
Beau, when you say place in your initialization routine, where is it you are talking about?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“Intellectual growth should commence at birth and cease only at death”
Albert Einstein
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
According to the datasheet on page 8, a $0F should be a "blank" not a small 't'
datasheets.maxim-ic.com/en/ds/MAX7219-MAX7221.pdf
"Beau, when you say place in your initialization routine, where is it you are talking about?"
If you look at your original code that you posted, the first lines read...
...which looks correct. If you look further down in your reset routine, the code looks like this...
...which according to the datasheet looks incorrect.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 6/26/2007 10:59:54 PM GMT