Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 10:14 05 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM2: MAX7219 8 digit, 7-segment display

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 04:58am 01 Dec 2014
Copy link to clipboard 
Print this post

If you search for the MAX7219 on ebay and sort by lowest price fairly near the top are some little PCBs with 8 x 7-segment LEDs. Starting price is about £1.63.

These are easy to use and program, bright, and good for many simple display purposes.

This program demonstrates their use. The main "display" subroutine writes a string to the display using "best-fit" approximations of letters and normal 7-segment numbers. I haven't bothered with any cursor positioning, it is easier just to maintain a complete string in your MM program and then output it. The program truncates strings if required to fit the display. The program uses hardware SPI but I'm going to write a cFunction software version unless anyone has already done it?

Another picaxe port done


'
' Example program for using MAX7219 8x 7-segment LED display modules
'
option explicit
option default integer
'
const CS=24 'latch pin for display
'
' MAX7219 Registers
const decode=&H09
const intens=&H0A
const scanlim=&H0B
const shutdwn =&H0C
const digtest=&H0F
' MAX7219 Data Constants
const Set_Off = 0
const Set_On = 1
const No_Digits = 7 ' Scan limit for digits 0 to 3 = 4
const Dec_Digits = 15 ' decode digits 0 to 3 according to "code B"
const Init_Inten = 8 ' 0 (=1/32 PWM on time) to 15 (=31/32 PWM on time)
const DigBlank = 15 '"Code B" value to black a digit
const DecimPnt = 128 ' Add this value to a digit value/code when we want the decimal point illuminated
const Decimal = 10
const Hexadec = 16
' Array of segment codes for numbers and letter approximations
data &H7E, &H30, &H6D, &H79, &H33, &H5B, &H5F, &H70, &H7F, &H7B, &H77, &H1F, &H4E, &H3D, &H4F, &H47, &H5E, &H37
data &H30, &H3C, &H2F, &H0E, &H55, &H15, &H1D, &H67, &H73, &H05, &H5B, &H0F, &H3E, &H1C, &H5C, &H49, &H3B, &H6D
'
INIT:
dim ch(36),i
for i= 0 to 35
read ch(i)
next i
initmax7219
Main:
display("Hello OK") 'test uppercase conversion
pause 3000
display("...HELLO") 'test leading fullstops
pause 3000
display("Hello world, Hello world, Hello world, Hello world") 'test too long string
pause 3000
display(str$(65536,8)) 'Test simple numebr output
pause 3000
display(str$(14.88,6,2)) 'test float output
pause 3000
display(hex$(1234567890,8)) 'test hex output
pause 3000
display("1.2.3.4.5.6.7.8.") 'test max valid string length
end
'
sub initmax7219
setpin cs, dout
pin(cs)=0
SPI OPEN 1000000,3,16
sendcommand(decode,0) 'we want straight access to the elements of the LEDs
sendcommand(intens,Init_Inten)
sendcommand(scanlim,No_Digits)
sendcommand(Shutdwn, Set_on)
sendcommand(DigTest, Set_Off)
clearMAX7219
end sub
'
sub sendcommand(register, command)
local i = SPI((register<<8)+command)
pulse CS,0.005
end sub
'
sub display(textin$)
local text$
text$=ucase$(textin$)
local i,j,k=0,buff(16)
for i=0 to 7
buff(i)=0
endif
for i=1 to len(text$)
j=asc(mid$(text$,i,1))
if j=32 then
buff(k)=0
else
if j=46 then 'handle the special case of fullstops/decimal points
if k<>0 then
if (buff(k-1) and 128)=0 then
k=k-1
buff(k)=buff(k) or 128 'set the decimal point on the previous character
else
buff(k)=128
endif
else
buff(k)=128
endif
else
j=j-48 'convert ascii
if j>9 then j=j-7
if j>=0 and j<=35 then
buff(k)=ch(j)
else
buff(k)=0
endif
endif
endif
k=k+1
if k>=10 then exit for
next i
for i=1 to 8
sendcommand(i,buff(8-i))
next i
end sub
'
sub clearMAX7219
for i=1 to 8
sendcommand(i,0) 'blank the display
next i
end sub
'

 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 07:27am 01 Dec 2014
Copy link to clipboard 
Print this post

Hi Matherp, this is good stuff. Really appreciated. These code examples are really becoming a great addition to MMbasic "libraries" that I keep saving for use in different projects. AWESOME!!!

Have you ever used the max7219 with the 8x8 led matrix? This was messed with a while ago on this forum here but never really went too far like creating a scrolling text using 5 or so of these units. I am guessing that with the use of cfuntions, this could actually be a reality. Is this something you could take a look at and see what you think...

Thanks again, you are slaying it!!!
 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 10:52am 01 Dec 2014
Copy link to clipboard 
Print this post

I used the AS1107 when did some testing a while back on 8x8 matrix.. (Maximite V3.2)

The link to that thread is here .

The chips are similar in output and control. I even got the 3 chips for free as a sample.

A small video is in that thread.. [edit] but doesn't work anymore [/edit]
AussieWombatEdited by MM_Wombat 2014-12-02
Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 12:32pm 01 Dec 2014
Copy link to clipboard 
Print this post

Members may also be interested in this posting re 7219's. http://www.thebackshed.com/forum/forum_posts.asp?TID=6685&KW =boss

Peter
The only Konstant is Change
 
Oldbitcollector

Senior Member

Joined: 16/05/2014
Location: United States
Posts: 172
Posted: 05:55pm 01 Dec 2014
Copy link to clipboard 
Print this post

Amazing! (and in MMBASIC no less!)

Is someone maintaining a reference to all these great hardware threads? (MMREFERENCE.COM are you still there?) I'll probably start a sticky on the Propellerpowered forums, maybe a thread here is a good idea here as well?

Jeff

My Propeller/Micromite mini-computer project.
 
aargee
Senior Member

Joined: 21/08/2008
Location: Australia
Posts: 255
Posted: 08:22pm 01 Dec 2014
Copy link to clipboard 
Print this post

Great point, I was wondering that myself.

Matherp is a bit of a powerhouse... good on you!

From Geoffs site (http://geoffg.net/maximite.html )

"The library is managed by Hugh Buckle and is a great resource for beginners and experts alike. If you have written a program for MMBasic and you believe that it is worth sharing, please send it to Hugh at mmlib@geoffg.net and he will add it in. You should also include a description of what the program does for the library index."

The latest update is from the 1st Nov, so it looks like it is still active.
For crying out loud, all I wanted to do was flash this blasted LED.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 10:23pm 01 Dec 2014
Copy link to clipboard 
Print this post


The MMBasic library on Geoff's site contains MMBasic Maximite programs, not Micromite, but I totally agree, a library for MMBasic Micromite code is needed. A couple of days ago, similar points were made in relation to a CFunction library in another thread, as below. It would be nice if both could be in the same place but that may not be workable for the "librarian(s)".

Greg

  paceman said  
  G8JCF said  As for a common CFunction library, I am more than happy to act as editor for CFunctions, and to provide a repository for them. If one refers to page 63,64,65 of the CFunction tutorial document, it describes how CFunctions could be published.

Sounds excellent to me, and having an "editor" that understands the process would be a major plus. What do others think, and I wonder what Geoff feels about this? There's already the MMBasic library that Hugh Buckle maintains on Geoff's website for the Maximite programs, but this would be a pretty different sort of animal.

  Quote  Perhaps I should open up a new thread specifically dedicated to the topic of CFunctions ?

I think a single thread on how CFunctions are produced, which could include discussion about the Tutorial, would be a good idea but not for the whole range of CFunctions. A single "CFunction" thread would have to have, sort of, subsections to cover the threads for different functions and would just complicate the board.

What might work to separate CFunction threads from the normal MMBasic threads (if that's needed at all) is to put, say (CF) as a prefix to the thread's subject heading as we used to do with (MM) or (DM) to designate a Maximite or Duinomite thread. That way people will immediately know that it will contain some "C" discussion. (Note: we don't use that MM/DM thing anymore because the whole issue has faded away, but Glenn introduced it for good reason a couple of years ago.)

I don't think we need to separate CFunction threads. There's a lot of information that's important in them anyway (or just plain interesting) for those who will never want to write one but probably will want to use them.

What do others think?

Greg
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 04:05am 03 Dec 2014
Copy link to clipboard 
Print this post

There are 2 kinds of Library

1) A Collection of things, eg programs, useful functions etc, and this is the kind of library established by Hugh Buckle. There is just 1 library.

2) A software library, eg LCD driver library, and this is the kind of Library which I think we need for stuff like CFunctions, and uMite code. There are many s/w libraries.

The distinction between 1) and 2) is that in 1), the librarian acts to collect, store and catalogue what is held in the Library. In 2), the Librarian makes sure that as well as Cataloguing, & storing items, the Librarian also acts to eliminate Name-Space clashes, standardises how the library is documented, standardises calling sequences/methods, standardises use of Global variables etc, ie more Editor than Librarian/Curator. The key purpose being that someone can then take a library off-the shelf, read the documentation, then add it to their program, and be confident that for example the library's use of a Global variable does not clash with the user's program's use of a Global variable, or that the library hasn't set OPTION DEFAULT INTEGER, when the user's program wants to set OPTION DEFAULT FLOAT, ie s/w libraries need to be as neutral as possible.

Question : Is this type of library facility, ie 2), required by the Community ?

Peter
The only Konstant is Change
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 05:07pm 03 Dec 2014
Copy link to clipboard 
Print this post


I'd certainly think so Peter but it would be good to hear other's opinions, especially Geoff's. Unfortunately I'm very much an amateur on software (hardware too for that matter) so my opinion here is from a limited base.

The "Library" subject should definitely have a separate thread anyway so I've PM'd Glenn (Gizmo), our Administartor and asked if he would move the posts from OBC's at 1:55pm on the 2/12/14 to your post above, into a new thread called "Micromite Library" or somesuch. I don't know how else to do this, or if Glenn is available at the moment to do it for us.

Greg
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 09:58am 04 Dec 2014
Copy link to clipboard 
Print this post

Hi Greg

As you say, it will be interesting to hear from others.

Peter
The only Konstant is Change
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 04:41pm 04 Dec 2014
Copy link to clipboard 
Print this post

I very much agree also, we do need a library for Micromite programs and "snippets". I believe that it should hold all forms of code (MMBasic as well as CFunctions).

Hugh Buckle has done a great job of managing the Maximite library and it involves a lot of work. He has tested most programs and he chases up details (when necessary) from people who have submitted code. He also classifies submissions and indexes them.

For the Micromite it would be better if we had a more automated method where people could submit code along with a description and a classification and it would be automatically listed in a database. However, this would take a lot of work to setup.

To my mind any library would be worthwhile - even if it is not perfect.

I would be the logical person to maintain such a library but these days I am always running out of time and if I took it on I know that I would fail miserably. And I would prefer to spend my time polishing MMBasic.

So, we need ideas. Is there someone who wants to take on the job of maintaining a library? Or is there a better way to maintain a library without it being labour intensive?

Geoff
Geoff Graham - http://geoffg.net
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 05:07pm 04 Dec 2014
Copy link to clipboard 
Print this post

i could setup a page that can hold code samples and library functions.
it would be in a folder type structure where things could be categorized easily.
i would prefer that code would be posted through email to prevent spammers.
posting directly would be possible but that needs to be behind a login. the info can still be available for anyone, a login would allow trusted people to upload directly without moderation.

i already have something setup internally to store datasheets, mostly microchip and parts often used with microcontrollers. the structure can hold other info easily so it would not be too much work.


Edited by TZAdvantage 2014-12-06
Microblocks. Build with logic.
 
akashh
Senior Member

Joined: 19/01/2014
Location: India
Posts: 115
Posted: 03:42pm 08 Dec 2014
Copy link to clipboard 
Print this post

What about a git repository? They seem to have everything needed for this type of sharing, plus files are easily viewable online, so not everyone needs to download the entire repository to get the snippet he needs. Just a thought.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 07:36pm 08 Dec 2014
Copy link to clipboard 
Print this post

Current discussion of this thread has been moved to the thread "Micromite Library".

Greg
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024