1.5K
#include "main.h" #include "max7219.h" uint8_t disp1ay[38][8]={ {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C}, //0 {0x10,0x30,0x50,0x10,0x10,0x10,0x10,0x7c}, //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 {0x18,0x24,0x42,0x42,0x7E,0x42,0x42,0x42}, //A {0x3C,0x22,0x22,0x3c,0x22,0x22,0x3C,0x0}, //B {0x3C,0x40,0x40,0x40,0x40,0x40,0x40,0x3C}, //C {0x7C,0x22,0x22,0x22,0x22,0x22,0x22,0x7C}, //D {0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C}, //E {0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40}, //F {0x3C,0x40,0x40,0x40,0x4c,0x44,0x44,0x3C}, //G {0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44}, //H {0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C}, //I {0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30}, //J {0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24}, //K {0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C}, //L {0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81}, //M {0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0}, //N {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C}, //O {0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20}, //P {0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D}, //Q {0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21}, //R {0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C}, //S {0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8}, //T {0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C}, //U {0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18}, //V {0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0}, //W {0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41}, //X {0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8}, //Y {0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F}, //Z }; static void write_reg(uint8_t reg, uint8_t value) { uint8_t tx_data[2] = {reg, value }; HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi2, tx_data, sizeof(tx_data),100); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET); } static void max7219_init_8x8MAT() { write_reg(0x09, 0x00); // no decoding write_reg(0x0a, 0x03); // brightness intensity write_reg(0x0b, 0x07); // scan limit = 8 LEDs write_reg(0x0c, 0x01); // power down =0,normal mode = 1 write_reg(0x0f, 0x00); // no test display } int main(void) { HAL_Init() SystemClock_Config(); MX_GPIO_Init(); MX_SPI1_Init(); MX_SPI2_Init(); /* USER CODE BEGIN 2 */ max7219_init_8x8MAT(); HAL_Delay(10); max7219_Init_16SEG(7); max7219_Decode_On(); /* USER CODE END 2 */ while (1) { switch(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0)) { case(GPIO_PIN_SET): { max7219_PrintItos(DIGIT_8,87654321); HAL_Delay(2000); max7219_Clean(); max7219_PrintFtos(DIGIT_8,-3.66,2); HAL_Delay(2000); max7219_Clean(); max7219_PrintNtos(DIGIT_8,9999,4); HAL_Delay(2000); max7219_Clean(); max7219_PrintNtos(DIGIT_8,9999,8); HAL_Delay(2000); max7219_Clean(); }break; case(GPIO_PIN_RESET): { for(int j=0 ; j<38;j++) { for(int i=1;i<9;i++) { write_reg(i, disp1ay[j][i-1]); } HAL_Delay(700); } }break; }}}