/** ****************************************************************************** * @file Project/main.c * @author "Vladimir N. Shilov" * @version v.0.1 * @date 08-July-2019 * @brief Main program body ****************************************************************************** * @attention * * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Shilov V.N. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm8s.h" #include "max7219.h" /* Private defines -----------------------------------------------------------*/ const static max7219_reg_t digitPosition[8] = { RegDigit0, RegDigit1, RegDigit2, RegDigit3, RegDigit4, RegDigit5, RegDigit6, RegDigit7 }; const static uint8_t digitValue[16] = { Sym_0, Sym_1, Sym_2, Sym_3, Sym_4, Sym_5, Sym_6, Sym_7, Sym_8, Sym_9, Sym_A, Sym_b, Sym_c, Sym_d, Sym_E, Sym_F }; /* Private function prototypes -----------------------------------------------*/ static void boardInit(void); /* Private functions ---------------------------------------------------------*/ void main(void) { boardInit(); MAX7219_Config(); uint8_t i; for (i=1; i<9; i++) { MAX7219_WriteData(digitPosition[i], digitValue[i]); } /* Infinite loop */ while (1) { } } /* Private functions ---------------------------------------------------------*/ static void boardInit(void) { /* Насколько я понял, для частот выше 16МГц нужно вводить задержку при работе с FLASH: - Before using the HSE clock make sure that the "Flash_Wait_States" is set to 1. - To do so : - with STVD (menu: Debug Instrument -> MCU configuration -> Options) - with EWSTM8 (menu: ST-LINK -> Option bytes ->Flash_Wait_States: 1) */ ErrorStatus status = ERROR; CLK_DeInit(); /* Configure the Fcpu to DIV1*/ CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1); /* Configure the HSI prescaler to the optimal value */ CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1); /* Output Fcpu on CLK_CCO pin */ CLK_CCOConfig(CLK_OUTPUT_CPU); /* Configure the system clock to use HSE clock source and to run at Crystal Mhz */ status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); if (status == ERROR) { /* Configure the system clock to use HSI clock source and to run at 16Mhz */ status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); // set FLAG for } } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval : None */ void assert_failed(u8* file, u32 line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif /************************ (C) COPYRIGHT Shilov V.N. *****END OF FILE****/