【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十:轮流显示数字 “1 - 9” 以及中文 “中”,“国”
实验开源代码
- /*
- 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
- 实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
- 项目三十:轮流显示数字 “1 - 9” 以及中文 “中”,“国”
- 接脚连线:
- MAX7219 UNO
- VCC →→→→→ 5V
- GND →→→→→ GND
- DIN →→→→→ D12(数据,数据接收引脚)
- CS →→→→→ D11(负载,命令接收引脚)
- CLK →→→→→ D10(时钟,时钟引脚)
- */
-
- int clk = 10;
- int cs = 11;
- int din = 12;
-
- unsigned char disp1[12][8] = {
- {0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C}, //0
- {0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08}, //1
- {0x7E, 0x2, 0x2, 0x7E, 0x40, 0x40, 0x40, 0x7E}, //2
- {0x3E, 0x2, 0x2, 0x3E, 0x2, 0x2, 0x3E, 0x0}, //3
- {0x8, 0x18, 0x28, 0x48, 0xFE, 0x8, 0x8, 0x8}, //4
- {0x3C, 0x20, 0x20, 0x3C, 0x4, 0x4, 0x3C, 0x0}, //5
- {0x3C, 0x20, 0x20, 0x3C, 0x24, 0x24, 0x3C, 0x0}, //6
- {0x3E, 0x22, 0x4, 0x8, 0x8, 0x8, 0x8, 0x8}, //7
- {0x0, 0x3E, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x3E}, //8
- {0x3E, 0x22, 0x22, 0x3E, 0x2, 0x2, 0x2, 0x3E}, //9
- {0x08, 0x7F, 0x49, 0x49, 0x7F, 0x08, 0x08, 0x08}, //中
- {0xFE, 0xFE, 0x92, 0xFE, 0x9A, 0xFE, 0x82, 0xFE}, //国
- };
-
- void setup() {
- //设置引脚为输出
- pinMode(cs, OUTPUT);
- pinMode(clk, OUTPUT);
- pinMode(din, OUTPUT);
-
- //初始化MAX7219
- Init_MAX7219();
- }
-
- void loop() {
- char i, j;
-
- //字体扫描显示
- for (j = 0; j < 12; j++)
- {
- for (i = 1; i < 9; i++)
- {
- Write_Max7219(i, disp1[j][i - 1]);
- delay(20);
- }
- delay(50);
- }
-
- }
-
- void Write_Max7219_byte(char DATA)
- {
- char i;
- digitalWrite(cs, 0);
- for (i = 8; i >= 1; i--)
- {
- digitalWrite(clk, 0);
- if ((DATA & 0x80) > 0) {
- digitalWrite(din, 1);
- } else {
- digitalWrite(din, 0);
- }
- //提取最高位给DIN端口
- DATA = DATA << 1; //左移一位
- digitalWrite(clk, 1);
- }
- }
- void Write_Max7219(char address, char dat)
- {
- digitalWrite(cs, 0);
- Write_Max7219_byte(address); //写入地址,编号
- Write_Max7219_byte(dat); //写入数据,即显示数字
- digitalWrite(cs, 1);
- }
- void Init_MAX7219(void)
- {
- Write_Max7219(0x09, 0x00); //译码方式:BCD码
- Write_Max7219(0x0a, 0x01); //亮度
- Write_Max7219(0x0b, 0x07); //扫描界限;显示
- Write_Max7219(0x0c, 0x01); //掉电模式:0,普通模式:1
- Write_Max7219(0x0f, 0x00);
- delay(50); //显示测试:1;测试结束,正常显示:0
- }
复制代码
|