So I have written some functions to achieve it.
If they are useful to someone, I am satisfied.
Code: [Local Link Removed for Guests]
' MAX7219 7 segments
modules = 4 ' total chained modules
bufferSize = (modules*8) - 1 ' define size output buffer
dim buffer(bufferSize)
dim dot(bufferSize)
' load character map for seven-segment display
dim pattern(63)
for i = 0 to 63
READ n : pattern(i) = n
next i
CS = 15
pin.mode CS, output
' ********** DEMO ***********
initMAX 0
printMAX "01234567", 1 ' load data into module one buffer
printMAX "89ABCDEF", 4 ' load data into module two buffer
printMAX "GHIJKLMN", 3
printMAX "OPQRSTUV", 2
refreshMAX ' send buffer to display
refreshMAX
pause 2000
timer0 1000, hour
wait
END
' ---------------------------------
SUB initMAX(brightness)
LOCAL module
spi.setup 1000000
pin(CS) = 1
for module = 1 to modules
writeMAX &H09, 0, module ' 6H09 = MAX7219DECODE
writeMAX &H0A, brightness, module ' &H0A = MAX7219INTENSITY
writeMAX &H0B, 7, module ' &H0B = MAX7219SCANLIMIT
writeMAX &H0F, 0, module ' &H0F = MAX7219TEST; 0 = TESTMODEOFF
writeMAX &H0C, 1, module ' &H0C = MAX7219SHUTDOWN; 1 = MAX7219ON
next module
END SUB
' ---------------------------------
SUB clearMAX
LOCAL index
for index = 0 to bufferSize
buffer(index) = 0
dot(index) = 0
next index
END SUB
' ---------------------------------
SUB writeMAX(opcode, value, module)
LOCAL i, r
pin(CS) = 0
for i = 1 to modules
if i = module then
r = spi.byte(opcode)
r = spi.byte(value)
else
r = spi.byte(0) ' MAX7219NOOP
r = spi.byte(0)
endif
pin(CS) = 1
next i
END SUB
' ---------------------------------
SUB refreshMAX
LOCAL module, digit, position, value
for module = 1 to modules
for digit = 1 to 8
position = (8*module) - digit
value = buffer(position)
if dot(position) = 1 then value = value OR &H80 ' turn on the decimal point
writeMAX digit, value, module
next digit
next module
END SUB
' ---------------------------------
SUB printMAX(text$, module)
LOCAL index, offset, value, dots
text$ = uCase$(text$)
offset = ( 8 * (module - 1)) - 1
' saves the position of the decimal points
' and removes them from the string
dots = 0
for index = 1 to len(text$)
if mid$(text$, index, 1) = "." then
dot(offset+index-1-dots) = 1
dots = dots + 1
endif
next index
text$ = replace$(text$, ".", "")
for index = 1 to len(text$)
value = asc(mid$(text$, index, 1)) - 32
buffer(index+offset) = pattern(value)
next index
END SUB
' ----------------------
SUB numInt(number, txt$)
LOCAL temp$, dp1$, dp2$
txt$ = "OUTRANGE"
if (number > 99999999) OR (number < -9999999) then EXIT SUB
temp$ = str$(cint(number))
txt$ = space$(8-len(temp$)) + temp$
dp1$ = "" : dp2$ = ""
temp$ = mid$(txt$, 2, 1)
if temp$ <> " " AND temp$ <> "-" then dp1$ = "."
temp$ = mid$(txt$, 5, 1)
if temp$ <> " " AND temp$ <> "-" then dp2$ = "."
txt$ = left$(txt$, 2) + dp1$ + mid$(txt$, 3, 3) + dp2$ + right$(txt$, 3)
END SUB
' ========================================================================
DATA &H00,&HA0,&H22,&H36,&H4B,&H5A,&H6F,&H02,&H4E,&H78,&H63,&H07,&H18,&H01
DATA &H80,&H25,&H7E,&H30,&H6D,&H79,&H33,&H5B,&H5F,&H70,&H7F,&H7B,&H09,&H19
DATA &H43,&H41,&H61,&H65,&H7D,&H77,&H1F,&H4E,&H3D,&H4F,&H47,&H5E,&H37,&H30,
DATA &H38,&H57,&H0E,&H54,&H76,&H7E,&H67,&H73,&H66,&H5B,&H0F,&H3E,&H3A,&H2A
DATA &H37,&H3B,&H69,&H4E,&H13,&H78,&H62,&H08,&H02
' ========================================================================
' ********** DEMO ***********
hour:
clearMAX
printMAX replace$(time$, ":", " "), 1
' printMAX replace$(date$, "/", "-"), 2
txt_RND$ = ""
numInt rnd(99999999)/10, txt_RND$
printMAX txt_RND$, 2
txt_millis$ = ""
numInt millis, txt_millis$
printMAX txt_millis$, 4
tExt = (rnd(600)/10) - 10
tExt$ = str$(tExt, "%2.1f")
if len(tExt$) < 4 then tExt$ = space$(1) + tExt$
tInt = rnd(500) / 10
tInt$ = str$(tInt, "%2.1f")
if len(tInt$) < 4 then tInt$ = space$(1) + tInt$
temperatures$ = tExt$ + "*" + tInt$ + "*"
printMAX temperatures$, 3
refreshMAX
refreshMAX
return
' NOTES
' -----
' Pin DIN = 13 (D7)
' Pin CLK = 14 (D5)
' Pin CS = 15 (D8)
' module1 = To ESP8266
' module2 = To module1
' etc. ....
' maximum consumption (eight eights) according to brightness
' brightness mA
' ---------- ---
' 0 12
' 1 24
' 2 36
' 3 48
' 4 60
' 5 72
' 6 82
' 7 93
' 8 104
' 9 115
' 10 125
' 11 135
' 12 145
' 13 154
' 14 164
' 15 173