尽管Wio终端提供了强大的液晶屏显示功能,但这也不妨碍我们用它的扩展接口来进行驱动串行点阵模块的测试。 串行点阵模块共有5个引脚,除2个电源引脚外,另3个引脚分别是片选引脚CS、数据引脚DIN及时钟引脚CLK。 该模块与Wio终端的连接关系如下: CLK ---PIN_SPI_MOSI DIN ---PIN_SPI_MISO CS --- PIN_SPI_SCK 故可将引脚定义为: #define CLK PIN_SPI_MOSI #define DIN PIN_SPI_MISO #define CS PIN_SPI_SCK 由于串行点阵模块所用的控制芯片为Max7219,故为其配置的初始化函数为: - void Init_MAX7219(void)
- {
- Write_Max7219(0x0b, 0x07);
- Write_Max7219(0x0c, 0x01);
- Write_Max7219(0x0f, 0x00);
- }
复制代码
辅助串行发送数据的函数为: - void Write_Max7219_byte(unsigned char DATA)
- {
- unsigned char i;
- digitalWrite(CS, LOW);
- for(i=8;i>=1;i--) {
- digitalWrite(CLK, LOW);
- if(DATA&0x80) digitalWrite(DIN, HIGH);
- else digitalWrite(DIN, LOW);
- DATA=DATA<<1;
- digitalWrite(CLK, HIGH);
- }
- }
- void Write_Max7219(char address,char dat)
- {
- digitalWrite(CS, LOW);
- Write_Max7219_byte(address);
- Write_Max7219_byte(dat);
- digitalWrite(CS, HIGH);
- }
复制代码
供显示所构建的字库其存储结果如下: unsigned chardisp[38][8]={ {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C}, //0 {0x10,0x30,0x50,0x10,0x10,0x10,0x10,0x10},//1 {0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E}, //2 ... {0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8}, //Y {0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F}, //Z {0x8,0x7F,0x49,0x49,0x7F,0x8,0x8,0x8}, //中 {0xFE,0xBA,0x92,0xBA,0x92,0x9A,0xBA,0xFE}, //国 }; 实现显示效果的程序其上传结果见图1所示,运行后的效果如图2所示。 图1 程序上传 图2 演示效果
|