接下來就是介紹8x8矩陣LED驅動的Source code介紹。
void All_ROW_H(void) { LED_ROW_A_H(); LED_ROW_B_H(); LED_ROW_C_H(); LED_ROW_D_H(); LED_ROW_E_H(); LED_ROW_F_H(); LED_ROW_G_H(); LED_ROW_H_H(); } void All_ROW_L(void) { LED_ROW_A_L(); LED_ROW_B_L(); LED_ROW_C_L(); LED_ROW_D_L(); LED_ROW_E_L(); LED_ROW_F_L(); LED_ROW_G_L(); LED_ROW_H_L(); } void All_COL_H(void) { LED_COL_A_H(); LED_COL_B_H(); LED_COL_C_H(); LED_COL_D_H(); LED_COL_E_H(); LED_COL_F_H(); LED_COL_G_H(); LED_COL_H_H(); } void All_COL_L(void) { LED_COL_A_L(); LED_COL_B_L(); LED_COL_C_L(); LED_COL_D_L(); LED_COL_E_L(); LED_COL_F_L(); LED_COL_G_L(); LED_COL_H_L(); } void Select_Turn_On_LED(uint8_t ROW,uint8_t COL) { All_ROW_L(); All_COL_H(); switch(ROW) { case 1 : LED_ROW_A_H(); break; case 2 : LED_ROW_B_H(); break; case 3 : LED_ROW_C_H(); break; case 4 : LED_ROW_D_H(); break; case 5 : LED_ROW_E_H(); break; case 6: LED_ROW_F_H(); break; case 7 : LED_ROW_G_H(); break; case 8 : LED_ROW_H_H(); break; default : break; } switch(COL) { case 1 : LED_COL_A_L(); break; case 2 : LED_COL_B_L(); break; case 3 : LED_COL_C_L(); break; case 4 : LED_COL_D_L(); break; case 5 : LED_COL_E_L(); break; case 6: LED_COL_F_L(); break; case 7 : LED_COL_G_L(); break; case 8 : LED_COL_H_L(); break; default : break; } Wait_delay(100); } void Smile_Face(void) { Select_Turn_On_LED(1,4); Select_Turn_On_LED(1,5); Select_Turn_On_LED(2,1); Select_Turn_On_LED(2,2); Select_Turn_On_LED(2,5); Select_Turn_On_LED(2,6); Select_Turn_On_LED(3,1); Select_Turn_On_LED(3,2); Select_Turn_On_LED(3,6); Select_Turn_On_LED(3,7); Select_Turn_On_LED(4,6); Select_Turn_On_LED(4,7); Select_Turn_On_LED(5,6); Select_Turn_On_LED(5,7); Select_Turn_On_LED(6,1); Select_Turn_On_LED(6,2); Select_Turn_On_LED(6,6); Select_Turn_On_LED(6,7); Select_Turn_On_LED(7,1); Select_Turn_On_LED(7,2); Select_Turn_On_LED(7,5); Select_Turn_On_LED(7,6); Select_Turn_On_LED(8,4); Select_Turn_On_LED(8,5); } void main(void) { HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM2_Init(); while(1) { Smile_Face(); } } |