1. LED dot matrix luminescence principle
If you want to light up a certain LED in the array, you only need to make the row where the LED is located output a high level and the column where the LED is located output a low level.
2. Dot Scanning Experiment
1 /***********************************************
2 Experiment Name: Dot Scanning
3 Experimental instructions: Scan each LED light to check whether the dot matrix is intact
4 Experimental time: 2014/12/24
5 ***************************************************/
6 #include
7 #include
8
9 #define uchar unsigned char
10 #define uint unsigned int
11
12 sbit MOSIO = P3^4; // input port
13 sbit R_CLK = P3^5; // latch clock
14 sbit S_CLK = P3^6; // shift register clock
15
16 //data3: right half column data; data2: left half column data
17 //data1: lower half row data; data0: upper half row data
18 void HC595Pro(uchar data3,uchar data2,uchar data1,uchar data0);
19
20 void main()
twenty one {
22 uint i,j;
23 uchar d;
twenty four
25 while(1)
26 {
27 //Full brightness
28 HC595Pro(0x00,0x00,0xFF,0xFF);
29 for(i=0;i<40000;i++); //Delay 40ms
30
31 /*Line scan*/
32 // Scan the upper half of the block
33 d = 0x01;
34 for(i=0;i<8;i++)
35 {
36 HC595Pro(0x00,0x00,0x00,d);
37 d <<= 1;
38 for(j=0;j<20000;j++); //Delay 20ms
39 }
40 // Scan the lower half of the block
41 d = 0x01;
42 for(i=0;i<8;i++)
43 {
44 HC595Pro(0x00,0x00,d,0x00);
45 d <<= 1;
46 for(j=0;j<20000;j++); //Delay 20ms
47 }
48
49 /* Column scan */
50 //Left half fast column scan
51 d = 0xFE;
52 for(i=0;i<8;i++)
53 {
54 HC595Pro(0xFF,d,0xFF,0xFF);
55 //If you still want to use the same format as line scanning, see the comment line at the bottom of main()
56 d = _crol_(d,1); //Circular shift left
57 for(j=0;j<20000;j++); //Delay 20ms
58 }
59 //Right half block column scan
60 d = 0xFE;
61 for(i=0;i<8;i++)
62 {
63 HC595Pro(d,0xFF,0xFF,0xFF);
64 d = _crol_(d,1);
65 for(j=0;j<20000;j++); //Delay 20ms
66 }
67 /******************************************************
68 b1 = 0x01;
69 for(i = 0; i<8; i++)
70 {
71 HC595Pro(0xFF, ~b1, 0xFF, 0xFF);
72 b1 <<= 1;
73 for(j=0; j<20000; j++);
74 }
75
76 b1 = 0x01;
77 for(i = 0; i<8; i++)
78 {
79 HC595Pro(~b1, 0xFF, 0xFF, 0xFF);
80 b1 <<= 1;
81 for(j=0; j<20000; j++);
82 }
83 **********************************************************/
84 }
85 }
86
87 void HC595Pro(uchar data3,uchar data2,uchar data1,uchar data0)
88 {
89 uchar i;
90 //The first data will be pushed to the next 595 by the data that is moved in later, so data3 needs to be moved in first
91 for(i=0;i<8;i++)
92 {
93 // First shift in the high bit and then the low bit. The first bit shifted into the shift register is the highest bit of the output.
94 MOSIO = data3 >> 7;
95 data3 <<= 1;
96 S_CLK = 0; //Give a rising edge, shift
97 S_CLK = 1;
98 }
99 for(i=0;i<8;i++)
100 {
101 MOSIO = data2 >> 7;
102 data2 <<= 1;
103 S_CLK = 0;
104 S_CLK = 1;
105 }
106 for(i=0;i<8;i++)
107 {
108 MOSIO = data1 >> 7;
109 data1 <<= 1;
110 S_CLK = 0;
111 S_CLK = 1;
112 }
113 for(i=0;i<8;i++)
114 {
115 MOSIO = data0 >> 7;
116 data0 <<= 1;
117 S_CLK = 0;
118 S_CLK = 1;
119 }
120
121 //When the rising edge occurs, the shift register data is moved to the latch for display. Normally, it is kept at a low level and the data remains unchanged.
122 R_CLK = 0;
123 R_CLK = 1;
124 R_CLK = 0;
125
126 }
Here I use a 16*16 dot matrix, which is actually composed of 4 8*8 small dot matrices.
Each of the four blocks is connected to a corresponding 74HC595. Each 74HC595 is cascaded and has only one input. We need to input the corresponding row and column level to control the on and off of the LED.
According to the structure of 74HC595, the input data is input 8 bits at a time. The first 8 bits of data will be pushed to the fourth 74HC595 by the following input data.
So when actually inputting, you first enter the column data of 2 and 4, then the column data of 1 and 3, then the row data of 3 and 4, and finally the row data of 1 and 2.
3. 16*16 dot matrix countdown
1 /***********************************************************************
2 Experiment name: 16*16 dot matrix digital countdown
3 Experimental time: 2014/12/26
4 **************************************************************************/
5 #include
6 #include
7
8 #define uchar unsigned char
9 #define uint unsigned int
10
11 sbit MOSIO = P3^4;
12sbit R_CLK = P3^5;
13 sbit S_CLK = P3^6;
14
15 void HC595Pro(uchar data3,uchar data2,uchar data1,uchar data0);
16
17 void main()
18 {
19 uint i,c;
20 uchar j;
21 i = 100;
twenty two
23 while(1)
twenty four {
25 //Display the number 10
26 for(c=i;c>0;c--)//delay
27 for(j=0;j<16;j++)
28 {
29 //The data taken out of the font template is opposite to the actual data required, so it needs to be inverted.
30 //The parameters corresponding to the function represent column 2, column 1, row 2, row 1 respectively
31 HC595Pro(~tab1[2*j+1],~tab1[2*j],tab0[2*j],tab0[2*j+1]);
32 }
33 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
34
35 //Display number 09
36 for(c=i;c>0;c--)
37 for(j=0;j<16;j++)
38 {
39 HC595Pro(~tab2[2*j+1],~tab2[2*j],tab0[2*j],tab0[2*j+1]);
40 }
41 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
42
43 //Display number 08
44 for(c=i;c>0;c--)
45 for(j=0;j<16;j++)
46 {
47 HC595Pro(~tab3[2*j+1],~tab3[2*j],tab0[2*j],tab0[2*j+1]);
48 }
49 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
50
51 //Display number 07
52 for(c=i;c>0;c--)
53 for(j=0;j<16;j++)
54 {
55 HC595Pro(~tab4[2*j+1],~tab4[2*j],tab0[2*j],tab0[2*j+1]);
56 }
57 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
58
59 //Display number 06
60 for(c=i;c>0;c--)
61 for(j=0;j<16;j++)
62 {
63 HC595Pro(~tab5[2*j+1],~tab5[2*j],tab0[2*j],tab0[2*j+1]);
64 }
65 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
66
67 //Display number 05
68 for(c=i;c>0;c--)
69 for(j=0;j<16;j++)
70 {
71 HC595Pro(~tab6[2*j+1],~tab6[2*j],tab0[2*j],tab0[2*j+1]);
72 }
73 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
74
75 //Display number 04
76 for(c=i;c>0;c--)
77 for(j=0;j<16;j++)
78 {
79 HC595Pro(~tab7[2*j+1],~tab7[2*j],tab0[2*j],tab0[2*j+1]);
80 }
81 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
82
83 //Display number 03
84 for(c=i;c>0;c--)
85 for(j=0;j<16;j++)
86 {
87 HC595Pro(~tab8[2*j+1],~tab8[2*j],tab0[2*j],tab0[2*j+1]);
88 }
89 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
90
91 //Display number 02
92 for(c=i;c>0;c--)
93 for(j=0;j<16;j++)
94 {
95 HC595Pro(~tab9[2*j+1],~tab9[2*j],tab0[2*j],tab0[2*j+1]);
96 }
97 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
98
99 //Display number 01
100 for(c=i;c>0;c--)
101 for(j=0;j<16;j++)
102 {
103 HC595Pro(~tab10[2*j+1],~tab10[2*j],tab0[2*j],tab0[2*j+1]);
104 }
105 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
106
107 //Display number 00
108 for(c=i;c>0;c--)
109 for(j=0;j<16;j++)
110 {
111 HC595Pro(~tab11[2*j+1],~tab11[2*j],tab0[2*j],tab0[2*j+1]);
112 }
113 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
114
115 //Display the letter GO
116 for(c=i;c>0;c--)
117 for(j=0;j<16;j++)
118 {
119 HC595Pro(~tab12[2*j+1],~tab12[2*j],tab0[2*j],tab0[2*j+1]);
120 }
121 HC595Pro(0xFF,0xFF,0x00,0x00); //Clear screen
122 }
123 }
124
125 void HC595Pro(uchar data3,uchar data2,uchar data1,uchar data0)
126 {
127 uchar i;
128 //The first data will be pushed to the next 595 by the data that is moved in later, so data3 needs to be moved in first
129 for(i=0;i<8;i++)
130 {
131 // First shift in the high bit and then the low bit. The first bit shifted into the shift register is the highest bit of the output.
132 MOSIO = data3 >> 7;
133 data3 <<= 1;
134 S_CLK = 0; //Give a rising edge, shift
135 S_CLK = 1;
136 }
137 for(i=0;i<8;i++)
138 {
139 MOSIO = data2 >> 7;
140 data2 <<= 1;
141 S_CLK = 0;
142 S_CLK = 1;
143 }
144 for(i=0;i<8;i++)
145 {
146 MOSIO = data1 >> 7;
147 data1 <<= 1;
148 S_CLK = 0;
149 S_CLK = 1;
150 }
151 for(i=0;i<8;i++)
152 {
153 MOSIO = data0 >> 7;
154 data0 <<= 1;
155 S_CLK = 0;
156 S_CLK = 1;
157 }
158
159 //When the rising edge occurs, the shift register data is moved to the latch for display. Normally, the low level is maintained and the data remains unchanged.
160 R_CLK = 0;
161 R_CLK = 1;
162 R_CLK = 0;
163 }
The array.h header file is as follows:
1 //Dot matrix display array
2 //For line scanning
3 unsigned char code tab0[] = {0x00, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80,
4 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80, 0x00};
5 //1 The font of the number 10
6 unsigned char code tab1[] = {0, 0, 0, 0, 0, 0, 8, 24, 14, 36, 8, 66, 8, 66, 8, 66,
7 8, 66, 8, 66, 8, 66, 8, 36, 62, 24, 0, 0, 0, 0, 0, 0};
8 //Font of the number 09
9 unsigned char code tab2[] = {0, 0, 0, 0, 0, 0, 24, 24, 36, 36, 66, 66, 66, 66, 66,
10 66, 66, 100, 66, 88, 66, 64, 66, 64, 36, 36, 24, 28, 0, 0, 0, 0};
11 //Font of number 08
12 unsigned char code tab3[] = {0, 0, 0, 0, 0, 0, 24, 60, 36, 66, 66, 66, 66, 66, 36,
13 66, 24, 66, 36, 66, 66, 66, 36, 66, 24, 60, 0, 0, 0};
14 //Font of number 07
15 unsigned char code tab4[] = {0, 0, 0, 0, 0, 0, 24, 126, 36, 34, 66, 34, 66, 16, 66, 16,
16 66, 8, 66, 8, 66, 8, 66, 8, 36, 8, 24, 8, 0, 0, 0, 0};
17 //Font of number 06
18 unsigned char code tab5[] = {0, 0, 0, 0, 0, 0, 24, 56, 36, 36, 66, 2, 66, 2, 66, 26, 66,
19 38, 66, 66, 66, 66, 66, 36, 36, 24, 24, 0, 0, 0, 0};
20 //Font of number 05
21 unsigned char code tab6[] = {0, 0, 0, 0, 0, 0, 24, 126, 36, 2, 66, 2, 66, 2, 66, 26, 66,
22 38, 66, 64, 66, 64, 66, 66, 36, 34, 24, 28, 0, 0, 0, 0};
23 //Font of number 04
24 unsigned char code tab7[] = {0, 0, 0, 0, 0, 0, 24, 32, 36, 48, 66, 40, 66, 36, 66, 36, 66,
25 34, 66, 34, 66, 126, 66, 32, 36, 32, 24, 120, 0, 0, 0, 0};
26 //Font of number 03
27 unsigned char code tab8[] = {0, 0, 0, 0, 0, 0, 24, 60, 36, 66, 66, 66, 66, 32, 66, 24, 66,
28 32, 66, 64, 66, 64, 66, 66, 36, 34, 24, 28, 0, 0, 0, 0};
29 //Font of number 02
30 unsigned char code tab9[] = {0, 0, 0, 0, 0, 0, 24, 60, 36, 66, 66, 66, 66, 66, 32, 66,
31 32, 66, 16, 66, 8, 66, 4, 36, 66, 24, 126, 0, 0, 0, 0};
32 //Font of number 01
33 unsigned char code tab10[] = {0, 0, 0, 0, 0, 0, 24, 8, 36, 14, 66, 8, 66, 8, 66, 8, 66, 8, 66,
34 8, 66, 8, 66, 8, 36, 8, 24, 62, 0, 0, 0, 0};
Previous article:51 MCU Development Series 1602 Character LCD Display
Next article:51 MCU RS232 serial communication code analysis
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- 【E840-DTU】Evaluation Summary
- Problems with display of characters and numbers in LCD?
- 【ST NUCLEO-G071RB Review】TIM-PWM
- How to determine the frequency of sine wave collected by microcontroller AD?
- Answer the questions to win prizes! ADI Technology Express - Automotive Application Entertainment and Information Interaction Solutions
- [NXP Rapid IoT Review] Hello World project reads sensor values that are always 0
- A few questions for help
- Introduction to 5G Small Cells
- 【GD32L233C-START Review】Three Power Consumption
- Which wireless method is the fastest for transferring files between mobile phones and computers?