-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax7212.c
145 lines (125 loc) · 4.56 KB
/
max7212.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#use delay (clock=40M)
/*
*******************************************************************************
* Module : MAX7219.C
* Author : Joe DiMeglio
* Description: MAX7219 LED Display Driver Routines
*
* The host communicates with the MAX7219 using three signals: DATA, CLK, and LOAD using SPI.
*
******************************************************************************/
// CONSTANTS //
#define Chip_Select PIN_D0 //this is the pin on the PIC that connects to LOAD
#define Chip_Select_Direction TRIS_D
#define scanLimitAmount 0x07
// - Mode Selection
#define nop 0x00
#define decode 0x09
#define brightness 0x0A
#define scanLimit 0x0B
#define shutDown 0x0C
#define dispTest 0x0F
// FOR more space, we don't need byte 0 and byte 7.
// We have stripped them out, IF/when we have a need and a bigger PIC,
// then we can put them back IF we want.
// Here we define row values FOR each of the six columns corresponding to the
// Alphabet, from A through Z.
byte Alphabet[156]=
{
0x7f, 0x88, 0x88, 0x88, 0x88, 0x7f, // A
0xff, 0x91, 0x91, 0x91, 0x91, 0x6e, // B
0x7e, 0x81, 0x81, 0x81, 0x81, 0x42, // C
0xff, 0x81, 0x81, 0x81, 0x81, 0x7e, // D
0x81, 0xff, 0x91, 0x91, 0x91, 0x91, // E
0x81, 0xff, 0x91, 0x90, 0x90, 0x80, // F
0x7e, 0x81, 0x81, 0x89, 0x89, 0x4e, // G
0xff, 0x10, 0x10, 0x10, 0x10, 0xff, // H
0x00, 0x81, 0xff, 0xff, 0x81, 0x00, // I
0x06, 0x01, 0x81, 0xfe, 0x80, 0x00, // J
0x81, 0xff, 0x99, 0x24, 0xc3, 0x81, // K
0x81, 0xff, 0x81, 0x01, 0x01, 0x03, // L
0xff, 0x60, 0x18, 0x18, 0x60, 0xff, // M
0xff, 0x60, 0x10, 0x08, 0x06, 0xff, // N
0x7e, 0x81, 0x81, 0x81, 0x81, 0x7e, // O
0x81, 0xff, 0x89, 0x88, 0x88, 0x70, // P
0x7e, 0x81, 0x85, 0x89, 0x87, 0x7e, // Q
0xff, 0x98, 0x98, 0x94, 0x93, 0x61, // R
0x62, 0x91, 0x91, 0x91, 0x91, 0x4e, // S
0xc0, 0x81, 0xff, 0xff, 0x81, 0xc0, // T
0xfe, 0x01, 0x01, 0x01, 0x01, 0xfe, // U
0xfc, 0x02, 0x01, 0x01, 0x02, 0xfc, // V
0xff, 0x02, 0x04, 0x04, 0x02, 0xff, // W
0xc3, 0x24, 0x18, 0x18, 0x24, 0xc3, // X
0xc0, 0x20, 0x1f, 0x1f, 0x20, 0xc0, // Y
0xc3, 0x85, 0x89, 0x91, 0xa1, 0xc3, // Z
};
byte Symbols[114] =
{
0x00, 0x3c, 0x42, 0x81, 0x00, 0x00, // (
0x00, 0x00, 0x81, 0x42, 0x3c, 0x00, // )
0x00, 0x00, 0xff, 0x81, 0x00, 0x00, // [
0x00, 0x00, 0x81, 0xff, 0x00, 0x00, // ]
0x00, 0x18, 0xe7, 0x81, 0x00, 0x00, //
0x00, 0x00, 0x81, 0xe7, 0x18, 0x00, //
0x00, 0x18, 0x24, 0x42, 0x81, 0x00, // <
0x00, 0x81, 0x42, 0x24, 0x18, 0x00, // >
0x00, 0x03, 0x0c, 0x30, 0xc0, 0x00, // /
0x00, 0xc0, 0x30, 0x0c, 0x03, 0x00, // \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0xfd, 0xfd, 0x00, 0x00, // !
0x60, 0x80, 0x8d, 0x8d, 0x90, 0x60, // ?
0x42, 0x24, 0xff, 0xff, 0x24, 0x42, // *
0x24, 0xff, 0x24, 0x24, 0xff, 0x24, // #
0x62, 0x91, 0xff, 0xff, 0x91, 0x4e, // $
0x66, 0x99, 0x99, 0x66, 0x09, 0x00, // &
0x42, 0xa4, 0x48, 0x12, 0x25, 0x42, // %
0x20, 0x3f, 0x20, 0x20, 0x3e, 0x21, // pi
};
// latch the bits into the MAX
VOID pulseCS(void)
{
output_bit (Chip_Select, 1);
delay_us (2) ;
output_bit (Chip_Select, 0);
}
//send data to MAX
VOID send7219 (byte address, byte data)
{
//make a 16 bit variable address byte high, data byte low
Int16 SerialData;
SerialData = make16 (address, data);
spi_xfer (SerialData); //transfer using spi software
pulseCS ();
}
//Init MAX
VOID InitMax7219 (void)
{
output_bit (Chip_Select, 0); // Set RD0 pin as hight
set_tris_d(0x00) ;
//configure properly
send7219 (decode, 0x00); //no decoding (MSB)
send7219 (brightness, 0x09); //Segment luminosity intensity
send7219 (scanLimit, scanLimitAmount); //Scan all 7 digits
send7219 (shutDown, 0x01); //No Shutdown reg.
send7219 (dispTest, 0x00); // No test
}
// This is clear matrix function.
VOID Clear7219 (void)
{
byte Addr;
FOR (Addr = 1; Addr < scanLimitAmount+1; Addr++)
{
send7219 (Addr, 0x00) ;
}
}
//Write CHAR to the screen
VOID WriteChar7219 (byte myChar)
{
byte Column, Start_Byte;
Start_Byte = (myChar - 65) * 6; // 65 represents the letter "A" in ASCII code.
// We are using only columns from 2 through 7 FOR displaying the character.
FOR (Column = 7; Column > 1; Column--)
{
send7219 (Column, Alphabet[Start_Byte++]);
}
}