main.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. ******************************************************************************
  3. * @file Project/main.c
  4. * @author "Vladimir N. Shilov" <shilow@ukr.net>
  5. * @version v.0.1
  6. * @date 08-July-2019
  7. * @brief Main program body
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * "THE BEER-WARE LICENSE" (Revision 42):
  12. * <shilow@ukr.net> wrote this file. As long as you retain this notice you
  13. * can do whatever you want with this stuff. If we meet some day, and you think
  14. * this stuff is worth it, you can buy me a beer in return. Shilov V.N.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Includes ------------------------------------------------------------------*/
  19. #include "stm8s.h"
  20. #include "max7219.h"
  21. /* Private defines -----------------------------------------------------------*/
  22. const static max7219_reg_t digitPosition[8] = {
  23. RegDigit0, RegDigit1, RegDigit2, RegDigit3,
  24. RegDigit4, RegDigit5, RegDigit6, RegDigit7
  25. };
  26. const static uint8_t digitValue[16] = {
  27. Sym_0, Sym_1, Sym_2, Sym_3, Sym_4, Sym_5, Sym_6, Sym_7,
  28. Sym_8, Sym_9, Sym_A, Sym_b, Sym_c, Sym_d, Sym_E, Sym_F
  29. };
  30. /* Private function prototypes -----------------------------------------------*/
  31. static void boardInit(void);
  32. /* Private functions ---------------------------------------------------------*/
  33. void main(void)
  34. {
  35. boardInit();
  36. MAX7219_Config();
  37. uint8_t i;
  38. for (i=1; i<9; i++) {
  39. MAX7219_WriteData(digitPosition[i], digitValue[i]);
  40. }
  41. /* Infinite loop */
  42. while (1)
  43. {
  44. }
  45. }
  46. /* Private functions ---------------------------------------------------------*/
  47. static void boardInit(void) {
  48. /* Íàñêîëüêî ÿ ïîíÿë, äëÿ ÷àñòîò âûøå 16ÌÃö íóæíî ââîäèòü çàäåðæêó ïðè ðàáîòå ñ FLASH:
  49. - Before using the HSE clock make sure that the "Flash_Wait_States" is set to 1.
  50. - To do so :
  51. - with STVD (menu: Debug Instrument -> MCU configuration -> Options)
  52. - with EWSTM8 (menu: ST-LINK -> Option bytes ->Flash_Wait_States: 1)
  53. */
  54. ErrorStatus status = ERROR;
  55. CLK_DeInit();
  56. /* Configure the Fcpu to DIV1*/
  57. CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
  58. /* Configure the HSI prescaler to the optimal value */
  59. CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
  60. /* Output Fcpu on CLK_CCO pin */
  61. CLK_CCOConfig(CLK_OUTPUT_CPU);
  62. /* Configure the system clock to use HSE clock source and to run at Crystal Mhz */
  63. status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
  64. if (status == ERROR) {
  65. /* Configure the system clock to use HSI clock source and to run at 16Mhz */
  66. status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
  67. // set FLAG for
  68. }
  69. }
  70. #ifdef USE_FULL_ASSERT
  71. /**
  72. * @brief Reports the name of the source file and the source line number
  73. * where the assert_param error has occurred.
  74. * @param file: pointer to the source file name
  75. * @param line: assert_param error line source number
  76. * @retval : None
  77. */
  78. void assert_failed(u8* file, u32 line)
  79. {
  80. /* User can add his own implementation to report the file name and line number,
  81. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  82. /* Infinite loop */
  83. while (1)
  84. {
  85. }
  86. }
  87. #endif
  88. /************************ (C) COPYRIGHT Shilov V.N. *****END OF FILE****/