Code: [Local Link Removed for Guests]
' Dot set / reset by X/Y co-ords for MAX7219 Dot Matrix Displays.
' 0,0 is top left.
' N.B. This is incompatible with Annex built-in scrolling functions.
wlog "Start"
iobuff.dim(0,8)
iobuff.dim(1,64)
SPI.CSPIN 15
SPI.SETUP 10000000
DDat$ = ""
InitDisplay
do
x = rnd(32) : y = rnd(8) : z = rnd(2)
Dot x,y,z
loop
end
' SUBROUTINES
' ===========
' Usage Dot(X position, Y position, on/off)
' 1 = on, 0 = off
' Origin is 0,0 at top left corner. Bottom right is 31,7
' (Unless you invert the display, of course :¬)
sub Dot(xx,yy,sr)
c1 = (xx \ 8) ' Integer part gives disp no. (0 to 3)
c2 = (xx mod 8) ' gives dot offset in byte (0 to 7)
r1 = (yy mod 8) ' gives row (0 to 7)
r2 = (yy \ 4) ' gives dot offset in byte (0 to 7)
DPtr = (((r1*4)+c1)*4)+3 ' Position of data byte in output string
newbyte = &h80 >> c2
oldbyte = val("&H"+mid$(DDat$,DPtr,2)) ' Existing byte from output string
if sr = 1 then
newhex$ = right$("00" + hex$(newbyte OR oldbyte),2)
else
newhex$ = right$("00" + hex$((NOT newbyte) AND oldbyte),2)
endif
DDat$ = left$(DDat$,DPtr-1) + newhex$ + right$(DDat$,128-DPtr-1)
UpdateDisplay
end sub
sub ClearBuff
DDat$="01000100010001000200020002000200030003000300030004000400040004000500050005000500060006000600060007000700070007000800080008000800"
end sub
sub UpdateDisplay
' Dump Display Data string to SPI buffer
for cnt = 0 to 8
iobuff.fromhex(1,DDat$)
SPI.WRITE_IOBUFF(1,cnt*8,8)
next cnt
end sub
sub InitDisplay
' Reg &H01 - Shutdown mode - Enable displays
cdat$ = string$(4,"0C01")
iobuff.fromhex(0,cdat$)
SPI.WRITE_IOBUFF(0)
' Reg &H09 - Decode mode - No decode
cdat$ = string$(4,"0900")
iobuff.fromhex(0,cdat$)
SPI.WRITE_IOBUFF(0)
' Reg &H0B - Scan limit - 8 rows
cdat$ = string$(4,"0B07")
iobuff.fromhex(0,cdat$)
SPI.WRITE_IOBUFF(0)
' Reg &H0A - Intensity - Range &H00 to &H0F
Int$ = "01"
cdat$ = string$(4,"0A" + Int$)
iobuff.fromhex(0,cdat$)
SPI.WRITE_IOBUFF(0)
ClearBuff
UpdateDisplay
end sub
' Layout of display data string.
' ==============================
' Top left of first display is 0180xxxxxxxxxxxx
' Bottom right of last display is xxxxxxxxxxxx0801
' ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
'Disp D1 D2 D3 D4 D1 D2 D3 D4 D1 D2 D3 D4 D1 D2 D3 D4 D1 D2 D3 D4 D1 D2 D3 D4 D1 D2 D3 D4 D1 D2 D3 D4
'Row R1 R1 R1 R1 R2 R2 R2 R2 R3 R3 R3 R3 R4 R4 R4 R4 R5 R5 R5 R5 R6 R6 R6 R6 R7 R7 R7 R7 R8 R8 R8 R8
'#DNum 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
'#DPos 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 101 105 109 113 117 121 125
'