Basic stamp, MAX7219, 7 segment display and custom characters, how?
CuriousOne
Posts: 931
Hello.
I want to be able to display on 4 segment LED connected to BS2 via MAX7219 not only digits, but also some letters, which can be displayed, say A,C, H, L, P, E and some others. How should I?
I know that MAX7219 has so called "no decode" mode, which I already enabled, I'm using the code below for this:
The code, as posted, displays "1234". However, despite my attempts, I was not able to make it display any other chars. Only when I enable no decode mode and assign various digits to SWHi and SWLo, several random segments come on, but MAX7219 stucks after that, and I have to cycle power to make it responsive again.
I want to be able to display on 4 segment LED connected to BS2 via MAX7219 not only digits, but also some letters, which can be displayed, say A,C, H, L, P, E and some others. How should I?
I know that MAX7219 has so called "no decode" mode, which I already enabled, I'm using the code below for this:
' {$STAMP BS2} ' {$PBASIC 2.5} Clk PIN 10 DIN PIN 12 CS PIN 11 SWord VAR Word 'word which is shifted out to 7219 SWHi VAR SWord.HIGHBYTE SWLo VAR SWord.LOWBYTE Digit VAR Word cukuna VAR Word begin: HIGH CS 'normally not selected LOW CLK 'make these outputs LOW DIN SWord = $0C01 'shutdown register, normal operation GOSUB DMX7219 SWord = $09ff 'decode register, decode GOSUB DMX7219 SWord = $0B07 'scan limit, all rows GOSUB DMX7219 SWord = $0A05 'intensity register, medium GOSUB DMX7219 Drive: 'display seven thru zero FOR Digit = 0 TO 3 'go from right to left SWHi = (digit+1) SWLo = digit GOSUB DMX7219 NEXT END DMX7219: 'drive MX 7219 LOW CS 'enable SHIFTOUT DIN, CLK, MSBFIRST, [SWord \16] 'shift out 16 bits HIGH CS 'it loads and executes RETURN
The code, as posted, displays "1234". However, despite my attempts, I was not able to make it display any other chars. Only when I enable no decode mode and assign various digits to SWHi and SWLo, several random segments come on, but MAX7219 stucks after that, and I have to cycle power to make it responsive again.
Comments
You really need to study the MX7219 data sheet to understand how to program the chip. Here is a pointer to a page that will take you to it.
http://www.maximintegrated.com/en/products/power/display-power-control/MAX7219.html
Go to that page now, find the data sheet, download it and print it out. Do that now, before you continue with this message.
OK, got the data sheet in from of you? Look at Table 2 on page seven. This corresponds to SWHI in your code fragment. It specifies what register in the chip you are writing to. Addresses xxxx_0001 thru xxxx_1000 specify one of the eight digits.
Now look at table 6 on page 8. This corresponds to SWLO. In no-decode mode, each bit directly controls one segment (or DP).
So to write a "P" to digit three, I would program
[code]
SWHI = $03
SWLO = %01100111 'segments A, B, F, G, E
GOSUB DMX7219
1. It displays two additional segments in 4th digit
2. To update display, I have to turn off power, wait some time for capacitor discharge and then run code again. If not, then display won't get updated and it'll stuck.
As to extra segments, they may well be left over from before you turned decode off or however the MX7219 powered up. Here is a re-do of the code fragment that clears the display for sure and then programs four digits to letters. I'm sure you will know when it works.
I see we have parallel threads on two forums. I am continuing on just this thread; the other will naturally go away.
Also, I changed the labels on the two halves of SWORD to make them a little more mnemonic.
1. FONT
Google "seven-segment font images" to get a look at the various attempts to build recognizable characters. Some look just fine, like numerics and "ACEFHLP"; some letters are lower case, like "bdgjnr"; some are just horrible, like "mn"; and some are ambiguous "IOKZ". I think my take-away is "A lot of people won't like it". The characters in my font are in ASCII order except I replaced the punctuation between "9" and "@" with the hex characters "A..F" which appear twice.
2. MX7219 Control
I think the MX7219 can very easily come up in a very bad state. I have a pullup on CS AND a pull-down on DataIn and it still likes to come up in lamp test. I have very carefully coded it to get out of lamp test and that appears to work reliably. Here is a pointer to a demo. As always, the video is over-exposed.
https://www.youtube.com/watch?v=X8szESJvHAw&feature=youtu.be
Here is the code, including the font:
Oddly enough, I struggled with the circular buffer. For a while I had convinced myself that, with such a short buffer, it was more efficient to actually shift the contents than to keep recomputing the output pointer.