MAX7219 SPI/ 1-Wire LED / 點矩陣 驅動 w/ Sample code
Header File
#ifndef __MAX7219_H_
#define __MAX7219_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "brd.h"
//GPIO A
#define hwMAX7219Clk GPIO_Pin_6
#define portResetMAX7219Clk() GPIOA->BRR = hwMAX7219Clk
#define portSetMAX7219Clk() GPIOA->BSRR = hwMAX7219Clk
//GPIO A
#define hwMAX7219CS GPIO_Pin_5
#define portResetMAX7219CS() GPIOA->BRR = hwMAX7219CS
#define portSetMAX7219CS() GPIOA->BSRR = hwMAX7219CS
//GPIO A
#define hwMAX7219DI GPIO_Pin_4
#define portResetMAX7219DI() GPIOA->BRR = hwMAX7219DI
#define portSetMAX7219DI() GPIOA->BSRR = hwMAX7219DI
#define No_op 0x00
#define Decode 0x09
#define Intensity 0x0A
#define ScanLimit 0x0B
#define Shutdown 0x0C
#define DisplayTest 0x0F
extern const uint8_t DOTARRAY[];
extern const uint8_t map[10];
extern const uint8_t HEART[8];
void vInitMAX7219(void);
void vWriteMax7219(uint8_t ucReg, uint8_t ucData);
#ifdef __cplusplus
}
#endif
#endif
Smaple code
/*******************************************************************************
* Function Name : vInitMAX7219(void)
* Description : Initial MAX7219
* Input : none
* Return : None
*/
void vInitMAX7219(void)
{
WriteMax7219( Decode, 0 ); // 不使用 Decode
WriteMax7219( Intensity , 0 ); // 亮度 0
WriteMax7219( ScanLimit, 7 ); // 开启 0 ~7 位
WriteMax7219( Shutdown, 1 ); // 正常运作
WriteMax7219( DisplayTest, 0 ); // 关闭 TestMode
}
/*******************************************************************************
* Function Name : vWriteMax7219(uint8_t ucReg, uint8_t ucData)
* Description : Serial write to Max7219 16bits data
* Input : ucReg : Command Reg
* : ucData: Data
* Return : None
*/
void vWriteMax7219(uint8_t ucReg, uint8_t ucData)
{
portResetMAX7219Clk();
portResetMAX7219CS(); // Max7219 /CS Enbale
for(uint8_t i=0; i<8; i++)
{
portResetMAX7219Clk();
if( (ucReg & 0x80) > 0 )
{ portSetMAX7219DI(); }
else
{ portResetMAX7219DI(); }
portSetMAX7219Clk();
ucReg <<= 1;
}
for(uint8_t i=0; i<8; i++)
{
portResetMAX7219Clk();
if( ucData & 0x80 )
{ portSetMAX7219DI(); }
else
{ portResetMAX7219DI(); }
portSetMAX7219Clk();
ucData <<= 1;
}
portSetMAX7219CS(); // Max7219 /CS disbale
}
ASC-II 点矩阵字码宣告
const unsigned char DOTARRAY[] = {
3,8,0x00,0x00,0x00,0x00,0x00, // space
3,8,0x00,0x00,0x5F,0x00,0x00, // !
3,8,0x03,0x00,0x03,0x00,0x00, // "
5,8,0x14,0x3E,0x14,0x3E,0x14, // #
4,8,0x24,0x6A,0x2B,0x12,0x00, // $
5,8,0x63,0x13,0x08,0x64,0x63, // %
5,8,0x36,0x49,0x56,0x20,0x50, // &
1,8,0x03,0x00,0x00,0x00,0x00, // '
3,8,0x1C,0x22,0x41,0x00,0x00, // (
3,8,0x41,0x22,0x1C,0x00,0x00, // )
5,8,0x28,0x18,0x0E,0x18,0x28, // *
5,8,0x08,0x08,0x3E,0x08,0x08, // +
2,8,0xB0,0x70,0x00,0x00,0x00, // ,
4,8,0x08,0x08,0x08,0x08,0x00, // -
2,8,0x60,0x60,0x00,0x00,0x00, // .
4,8,0x60,0x18,0x06,0x01,0x00, // /
4,8,0x3E,0x41,0x41,0x3E,0x00, // 0
3,8,0x42,0x7F,0x40,0x00,0x00, // 1
4,8,0x62,0x51,0x49,0x46,0x00, // 2
4,8,0x22,0x41,0x49,0x36,0x00, // 3
4,8,0x18,0x14,0x12,0x7F,0x00, // 4
4,8,0x27,0x45,0x45,0x39,0x00, // 5
4,8,0x3E,0x49,0x49,0x30,0x00, // 6
4,8,0x61,0x11,0x09,0x07,0x00, // 7
4,8,0x36,0x49,0x49,0x36,0x00, // 8
4,8,0x06,0x49,0x49,0x3E,0x00, // 9
2,8,0x50,0x00,0x00,0x00,0x00, // :
2,8,0x80,0x50,0x00,0x00,0x00, // ;
3,8,0x10,0x28,0x44,0x00,0x00, // <
3,8,0x14,0x14,0x14,0x00,0x00, // =
3,8,0x44,0x28,0x10,0x00,0x00, // >
4,8,0x02,0x59,0x09,0x06,0x00, // ?
5,8,0x3E,0x49,0x55,0x5D,0x0E, // @
4,8,0x7E,0x11,0x11,0x7E,0x00, // A
4,8,0x7F,0x49,0x49,0x36,0x00, // B
4,8,0x3E,0x41,0x41,0x22,0x00, // C
4,8,0x7F,0x41,0x41,0x3E,0x00, // D
4,8,0x7F,0x49,0x49,0x41,0x00, // E
4,8,0x7F,0x09,0x09,0x01,0x00, // F
4,8,0x3E,0x41,0x49,0x7A,0x00, // G
4,8,0x7F,0x08,0x08,0x7F,0x00, // H
4,8,0x00,0x41,0x7F,0x41,0x00, // I
4,8,0x30,0x40,0x41,0x3F,0x00, // J
4,8,0x7F,0x08,0x14,0x63,0x00, // K
4,8,0x7F,0x40,0x40,0x40,0x00, // L
5,8,0x7F,0x02,0x0C,0x02,0x7F, // M
5,8,0x7F,0x04,0x08,0x10,0x7F, // N
4,8,0x3E,0x41,0x41,0x3E,0x00, // O
4,8,0x7F,0x09,0x09,0x06,0x00, // P
4,8,0x3E,0x41,0x41,0xBE,0x00, // Q
4,8,0x7F,0x09,0x09,0x76,0x00, // R
4,8,0x46,0x49,0x49,0x32,0x00, // S
5,8,0x01,0x01,0x7F,0x01,0x01, // T
4,8,0x3F,0x40,0x40,0x3F,0x00, // U
5,8,0x0F,0x30,0x40,0x30,0x0F, // V
5,8,0x3F,0x40,0x38,0x40,0x3F, // W
5,8,0x63,0x14,0x08,0x14,0x63, // X
5,8,0x07,0x08,0x70,0x08,0x07, // Y
4,8,0x61,0x51,0x49,0x47,0x00, // Z
2,8,0x7F,0x41,0x00,0x00,0x00, // [
4,8,0x01,0x06,0x18,0x60,0x00, // backslash
2,8,0x41,0x7F,0x00,0x00,0x00, // ]
3,8,0x02,0x01,0x02,0x00,0x00, // hat
4,8,0x40,0x40,0x40,0x40,0x00, // _
2,8,0x01,0x02,0x00,0x00,0x00, // `
4,8,0x20,0x54,0x54,0x78,0x00, // a
4,8,0x7F,0x44,0x44,0x38,0x00, // b
4,8,0x38,0x44,0x44,0x28,0x00, // c
4,8,0x38,0x44,0x44,0x7F,0x00, // d
4,8,0x38,0x54,0x54,0x18,0x00, // e
4,8,0x00,0x04,0x7E,0x05,0x00, // f
4,8,0x98,0xA4,0xA4,0x78,0x00, // g
4,8,0x7F,0x04,0x04,0x78,0x00, // h
4,8,0x00,0x44,0x7D,0x40,0x00, // i
4,8,0x40,0x80,0x84,0x7D,0x00, // j
4,8,0x7F,0x10,0x28,0x44,0x00, // k
4,8,0x00,0x41,0x7F,0x40,0x00, // l
5,8,0x7C,0x04,0x7C,0x04,0x78, // m
4,8,0x7C,0x04,0x04,0x78,0x00, // n
4,8,0x38,0x44,0x44,0x38,0x00, // o
4,8,0xFC,0x24,0x24,0x18,0x00, // p
4,8,0x18,0x24,0x24,0xFC,0x00, // q
4,8,0x7C,0x08,0x04,0x04,0x00, // r
4,8,0x48,0x54,0x54,0x24,0x00, // s
4,8,0x00,0x04,0x3F,0x44,0x00, // t
4,8,0x3C,0x40,0x40,0x7C,0x00, // u
5,8,0x1C,0x20,0x40,0x20,0x1C, // v
5,8,0x3C,0x40,0x3C,0x40,0x3C, // w
5,8,0x44,0x28,0x10,0x28,0x44, // x
4,8,0x9C,0xA0,0xA0,0x7C,0x00, // y
4,8,0x00,0x64,0x54,0x4C,0x00, // z
3,8,0x08,0x36,0x41,0x00,0x00, // {
1,8,0x7F,0x00,0x00,0x00,0x00, // |
3,8,0x41,0x36,0x08,0x00,0x00, // }
4,8,0x08,0x04,0x08,0x04,0x00, // ~
};
点矩阵 8x8 爱心
const uint8_t HEART[8] = { 0x0E, 0x11, 0x21, 0x42, 0x42, 0x21, 0x11,0x0E };
规格书
MAX7219 DS - MAX7219-MAX7221.pdf
#Blog转移
#STM32