forked from s23/ht1632c-spin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixLib.spin
82 lines (70 loc) · 1.95 KB
/
matrixLib.spin
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
CON
CMD_HT1632_SYS_DIS = %100000000000
CMD_HT1632_SYS_EN = %100000000010
CMD_HT1632_LED_OFF = %100000000100
CMD_HT1632_LED_ON = %100000000110
CMD_HT1632_BLINK_OFF = %100000010000
CMD_HT1632_BLINK_ON = %100000010010
CMD_HT1632_SLAVE_MODE = %100000100000
CMD_HT1632_MASTER_MODE = %100000110000
CMD_HT1632_EXTCLK = %100000111000
'CMD_HT1632_COMS00 = %100001000000
CMD_HT1632_COMS01 = %100001001000
'CMD_HT1632_COMS10 = %100001010000
'CMD_HT1632_COMS11 = %100001011000
'CMD_HT1632_PWM01 = %100101000000
CMD_HT1632_PWM16 = %100101011110
DAT
PIN_DAT byte 0
PIN_WCLK byte 1
PIN_RCLK byte 2
PIN_CS
PIN_CS1 byte 3
PIN_CS2 byte 4
PIN_CS3 byte 5
PIN_CS4 byte 6
ms byte 4
PUB Init | m
dira[PIN_DAT] := 1
dira[PIN_WCLK] := 1
repeat m from 0 to ms-1
HT1632_Set2416(byte[@PIN_CS][m], m == 0)
PUB numMs
Result := ms
PRI HT1632_Set2416(p_cs,master)
dira[p_cs] := 1
HT1632_Write_Cmd(p_cs,CMD_HT1632_SYS_DIS)
HT1632_Write_Cmd(p_cs,CMD_HT1632_COMS01)
if master
HT1632_Write_Cmd(p_cs,CMD_HT1632_MASTER_MODE)
else
HT1632_Write_Cmd(p_cs,CMD_HT1632_SLAVE_MODE)
HT1632_Write_Cmd(p_cs,CMD_HT1632_SYS_EN)
HT1632_Write_Cmd(p_cs,CMD_HT1632_LED_ON)
HT1632_Write_Cmd(p_cs,CMD_HT1632_PWM16)
PRI HT1632_Tx_Bit(bit)
outa[PIN_DAT] := bit
outa[PIN_WCLK] := 0
outa[PIN_WCLK] := 1
PRI HT1632_Tx_Bits(bits,count)
repeat count
HT1632_Tx_Bit(bits & 1)
bits >>= 1
PRI HT1632_Write_Bits(bits,count)
bits ><= count
HT1632_Tx_Bits(bits, count)
PRI HT1632_Write_Cmd(p_cs,command)
outa[p_cs] := 0
HT1632_Write_Bits(command, 12)
outa[p_cs] := 1
PRI HT1632_Write_Addr(address)
HT1632_Write_Bits(%101, 3)
HT1632_Write_Bits(address & $7F,7)
PUB Draw(data) | m,i
repeat m from 0 to ms-1
outa[byte[@PIN_CS][m]] := 0
HT1632_Write_Addr(0)
repeat i from 0 to 23
HT1632_Tx_Bits(word[data][24*m+i],16)
outa[byte[@PIN_CS][m]] := 1
' EOF