led.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #ifndef LED_H
  3. #define LED_H
  4. // time to show one led digit, ms
  5. #define LED_ONE_PERIOD 2
  6. #define LED_DIGITS_NUM 8
  7. /* LED segments pins
  8. AAA
  9. F B
  10. F B
  11. GGG
  12. E C
  13. E C
  14. DDD P
  15. */
  16. #define LED_SEG_CG_ODR GPIOA->ODR
  17. #define LED_SEG_C GPIO_PIN_1
  18. #define LED_SEG_G GPIO_PIN_2
  19. #define LED_SEG_CG (LED_SEG_C | LED_SEG_G)
  20. #define LED_SEG_CG_ON(a) LED_SEG_CG_ODR &= ~(a)
  21. #define LED_SEG_DH_ODR GPIOB->ODR
  22. #define LED_SEG_H GPIO_PIN_4
  23. #define LED_SEG_D GPIO_PIN_5
  24. #define LED_SEG_DH (LED_SEG_D | LED_SEG_H)
  25. #define LED_SEG_DH_ON(a) LED_SEG_DH_ODR &= ~(a)
  26. #define LED_SEG_BE_ODR GPIOC->ODR
  27. #define LED_SEG_B GPIO_PIN_6
  28. #define LED_SEG_E GPIO_PIN_7
  29. #define LED_SEG_BE (LED_SEG_B | LED_SEG_E)
  30. #define LED_SEG_BE_ON(a) LED_SEG_BE_ODR &= ~(a)
  31. #define LED_SEG_AF_ODR GPIOD->ODR
  32. #define LED_SEG_A GPIO_PIN_1
  33. #define LED_SEG_F GPIO_PIN_2
  34. #define LED_SEG_AF (LED_SEG_A | LED_SEG_F)
  35. #define LED_SEG_AF_ON(a) LED_SEG_AF_ODR &= ~(a)
  36. /* LED symbols */
  37. #define LED_OUT_OFF {LED_SEG_CG_ODR |= LED_SEG_CG; LED_SEG_DH_ODR |= LED_SEG_DH; LED_SEG_BE_ODR |= LED_SEG_BE; LED_SEG_AF_ODR |= LED_SEG_AF;}
  38. #define LED_OUT_DP LED_SEG_DH_ON(LED_SEG_H)
  39. #define LED_OUT_MM LED_SEG_CG_ON(LED_SEG_G)
  40. #define LED_OUT_0 LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_BE_ON(LED_SEG_BE); LED_SEG_CG_ON(LED_SEG_C); LED_SEG_DH_ON(LED_SEG_D)
  41. #define LED_OUT_1 LED_SEG_BE_ON(LED_SEG_B); LED_SEG_CG_ON(LED_SEG_C)
  42. #define LED_OUT_2 LED_SEG_AF_ON(LED_SEG_A); LED_SEG_BE_ON(LED_SEG_BE); LED_SEG_CG_ON(LED_SEG_G); LED_SEG_DH_ON(LED_SEG_D)
  43. #define LED_OUT_3 LED_SEG_AF_ON(LED_SEG_A); LED_SEG_BE_ON(LED_SEG_B); LED_SEG_CG_ON(LED_SEG_CG); LED_SEG_DH_ON(LED_SEG_D)
  44. #define LED_OUT_4 LED_SEG_BE_ON(LED_SEG_B); LED_SEG_AF_ON(LED_SEG_F); LED_SEG_CG_ON(LED_SEG_CG)
  45. #define LED_OUT_5 LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_CG_ON(LED_SEG_CG); LED_SEG_DH_ON(LED_SEG_D)
  46. #define LED_OUT_6 LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_BE_ON(LED_SEG_E); LED_SEG_CG_ON(LED_SEG_CG); LED_SEG_DH_ON(LED_SEG_D)
  47. #define LED_OUT_7 LED_SEG_AF_ON(LED_SEG_A); LED_SEG_BE_ON(LED_SEG_B); LED_SEG_CG_ON(LED_SEG_C)
  48. #define LED_OUT_8 LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_CG_ON(LED_SEG_CG); LED_SEG_BE_ON(LED_SEG_BE); LED_SEG_DH_ON(LED_SEG_D)
  49. #define LED_OUT_9 LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_BE_ON(LED_SEG_B); LED_SEG_CG_ON(LED_SEG_CG); LED_SEG_DH_ON(LED_SEG_D)
  50. #define LED_OUT_H LED_SEG_BE_ON(LED_SEG_BE); LED_SEG_AF_ON(LED_SEG_F); LED_SEG_CG_ON(LED_SEG_CG)
  51. #define LED_OUT_PL LED_SEG_BE_ON(LED_SEG_B); LED_SEG_CG_ON(LED_SEG_CG)
  52. #define LED_OUT_O LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_BE_ON(LED_SEG_B); LED_SEG_CG_ON(LED_SEG_G);
  53. #define LED_OUT_U LED_SEG_AF_ON(LED_SEG_F); LED_SEG_BE_ON(LED_SEG_BE); LED_SEG_CG_ON(LED_SEG_C); LED_SEG_DH_ON(LED_SEG_D)
  54. #define LED_OUT_A LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_BE_ON(LED_SEG_BE); LED_SEG_CG_ON(LED_SEG_CG)
  55. #define LED_OUT_B LED_SEG_AF_ON(LED_SEG_F); LED_SEG_BE_ON(LED_SEG_E); LED_SEG_CG_ON(LED_SEG_CG); LED_SEG_DH_ON(LED_SEG_D)
  56. #define LED_OUT_C LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_BE_ON(LED_SEG_E); LED_SEG_DH_ON(LED_SEG_D)
  57. #define LED_OUT_D LED_SEG_BE_ON(LED_SEG_BE); LED_SEG_CG_ON(LED_SEG_CG); LED_SEG_DH_ON(LED_SEG_D)
  58. #define LED_OUT_E LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_BE_ON(LED_SEG_E); LED_SEG_CG_ON(LED_SEG_G); LED_SEG_DH_ON(LED_SEG_D)
  59. #define LED_OUT_F LED_SEG_AF_ON(LED_SEG_AF); LED_SEG_BE_ON(LED_SEG_E); LED_SEG_CG_ON(LED_SEG_G)
  60. /* shift register control pins */
  61. #define SPI_PORT GPIOC
  62. #define SPI_SCK GPIO_PIN_5
  63. #define SPI_DATA GPIO_PIN_3
  64. typedef enum {
  65. led_A = 0xa,
  66. led_B = 0xb,
  67. led_C = 0xc,
  68. led_D = 0xd,
  69. led_E = 0xe,
  70. led_F = 0xf,
  71. led_H = 0x11,
  72. led_U = 0x12,
  73. led_Plus = 0x21,
  74. led_Minus = 0x22,
  75. led_O = 0x23, /* gradus */
  76. led_Off = 0xff
  77. } led_sym_t;
  78. extern uint8_t LedDigits[];
  79. extern uint8_t LedPoint[];
  80. void led_OutputValue(void);
  81. #endif // LED_H