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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
| / Software SPI configuration
sbit SoftSpi_SDI at RB3_bit;
sbit SoftSpi_SDO at RB4_bit;
sbit SoftSpi_CLK at RB5_bit;
sbit SoftSpi_SDI_Direction at TRISB3_bit;
sbit SoftSpi_SDO_Direction at TRISB4_bit;
sbit SoftSpi_CLK_Direction at TRISB5_bit;
// max7219 LOAD/CS(-) pin configuration// max7219 configuration
void max7219_init1()
{
trisa=0;
Chip_Select = 0; // SELECT MAX
Soft_SPI_Write(0x09); // Disable BCD mode for digit decoding
Soft_SPI_Write(0x00);
Chip_Select = 1; // DESELECT MAX
Chip_Select = 0;
Soft_SPI_Write(0x0A); // Max segment luminosity intensity
Soft_SPI_Write(0x0F);
Chip_Select = 1;
Chip_Select = 0;
Soft_SPI_Write(0x0B);
Soft_SPI_Write(0x07); // Display refresh
Chip_Select = 1;
Chip_Select = 0;
Soft_SPI_Write(0x0C);
Soft_SPI_Write(0x01); // Turn on the display
Chip_Select = 1;
Chip_Select = 0;
Soft_SPI_Write(0x00);
Soft_SPI_Write(0xFF); // No test
Chip_Select = 1;
}
void max7219_init2() {
Chip_Select = 0; // SELECT MAX
Soft_SPI_Write(0x09); // BCD mode for digit decoding
Soft_SPI_Write(0xFF); // using Code-B
Soft_SPI_Write(0x00); // Bypass the 1st Chip
Soft_SPI_Write(0x00);
Chip_Select= 1; // DESELECT MAX
Chip_Select= 0; // SELECT MAX
Soft_SPI_Write(0x0A);
Soft_SPI_Write(0x0F); // Segment luminosity intensity
Soft_SPI_Write(0x00); // Bypass the 1st Chip
Soft_SPI_Write(0x00);
Chip_Select1 = 1; // DESELECT MAX
Chip_Select1 = 0; // SELECT MAX
Soft_SPI_Write(0x0B);
Soft_SPI_Write(0x07); // Display refresh
Soft_SPI_Write(0x00); // Bypass the 1st Chip
Soft_SPI_Write(0x00);
Chip_Select = 1; // DESELECT MAX
Chip_Select= 0; // SELECT MAX
Soft_SPI_Write(0x0C);
Soft_SPI_Write(0x01); // Turn on the display
Soft_SPI_Write(0x00); // Bypass the 1st Chip
Soft_SPI_Write(0x00);
Chip_Select = 1; // DESELECT MAX
Chip_Select1 = 0; // SELECT MAX
Soft_SPI_Write(0x00);
Soft_SPI_Write(0xFF); // No test
Soft_SPI_Write(0x00); // Bypass the 1st Chip
Soft_SPI_Write(0x00);
Chip_Select1 = 1;
}
//Send data function
void Write_Byte(unsigned short myRow, unsigned short myValue)
{
Chip_Select = 0; // select max7219.
Soft_SPI_Write(myRow); // send myRow value to max7219 (digit place).
Soft_SPI_Write(myValue);
Chip_Select = 1; // deselect max7219.
}
void Write_Byte1(unsigned short myRow, unsigned short myValue)
{
Chip_Select = 0;
// select ma7219.
Soft_SPI_Write(myRow);
Soft_SPI_Write(myValue);
Soft_SPI_Write(0x00); // Bypass the 1st Chip
Soft_SPI_Write(0x00);
Chip_Select = 1;
}
//Clear matrix function
void Clear_Matrix(void)
{
unsigned short x;
for(x=1;x<9;x++)
{
Write_Byte(x,0x00);
}
}
unsigned int DisplayBuffer[]={0,0,0,0,0,0,0,0};
unsigned int DisplayBuffer1[]={0,0,0,0,0,0,0,0};
unsigned int speed=10;
short i, l, k, ShiftAmount, scroll, temp,temp1, shift_step=1, StringLength;
char message[]="MIPS LED MATRIX 2014" ;
char index,index1;
void main()
{
Chip_Select_Direction = 0;
Soft_SPI_init();
max7219_init1();
max7219_init2();
Clear_Matrix();
StringLength = strlen(message) ;
while(1)
{
for (k=0; k<StringLength; k++)
{
for (scroll=0; scroll<(8/shift_step); scroll++)
{
for (ShiftAmount=0; ShiftAmount<8; ShiftAmount++)
{
index = message[k];
index1=message[k-1];
temp =CharData[index-32][ShiftAmount];
temp1 =CharData[index-32][ShiftAmount];
DisplayBuffer[ShiftAmount] = (DisplayBuffer[ShiftAmount] << shift_step)| (temp >> ((8-shift_step)-scroll*shift_step));
DisplayBuffer1[ShiftAmount] = (DisplayBuffer1[ShiftAmount] << shift_step)| (temp1 >> ((8-shift_step)-scroll*shift_step));
}
for(l=0; l<5;l++)
{
for (i=0; i<8; i++)
{
Write_Byte(i+1,DisplayBuffer[i]); //Scrolling k character on firt LED Matrix
if(k>0)
Write_Byte1(i+1,DisplayBuffer1[i]);Scrolling k-1 character on second LED Matrix
}
}
}
}
}
} |