[51 MCU Study Notes FOUR]---16*16LED dot matrix

Publisher:WanderlustGlowLatest update time:2020-06-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. LED dot matrix luminescence principle


The structure diagram of 8*8 monochrome microcontroller is as follows:

It is easy to see from the circuit diagram that if you want to turn on a certain LED lamp in the array, you just need to make the row where the lamp is located output a high level and the column where the lamp 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. In fact, it is composed of 4 8*8 small dot matrices. Its structure is as follows:


1 2

3 4

Here is just a simple illustration... Each of the four blocks is connected to a corresponding 74HC595. Each 74HC595 is cascaded, with only one input. We need to input the corresponding row and column levels 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,

[1] [2] [3]
Reference address:[51 MCU Study Notes FOUR]---16*16LED dot matrix

Previous article:C51 MCU Learning - 8×8LED dot matrix screen learning notes
Next article:Teach you to learn 51 single chip microcomputer step by step: variable advanced and dot matrix LED

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号