max7219.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* MAX7219 Header file
  2. * ---------------------------
  3. * For more information see
  4. * http://www.adnbr.co.uk/articles/max7219-and-7-segment-displays
  5. * ----------------------------------------------------------------------------
  6. * "THE BEER-WARE LICENSE" (Revision 42):
  7. * <shilow@ukr.net> wrote this file. As long as you retain this notice you
  8. * can do whatever you want with this stuff. If we meet some day, and you think
  9. * this stuff is worth it, you can buy me a beer in return. Shilov V.N.
  10. * ----------------------------------------------------------------------------
  11. */
  12. /* Define to prevent recursive inclusion -------------------------------------*/
  13. #pragma once
  14. #ifndef __MAX7219_H
  15. #define __MAX7219_H
  16. /* Includes ------------------------------------------------------------------*/
  17. #include "stm8s.h"
  18. /* Exported defines ----------------------------------------------------------*/
  19. #define SPI_PORT GPIOC
  20. #define SPI_SCK GPIO_PIN_5
  21. #define SPI_MOSI GPIO_PIN_6
  22. #define SPI_PINS (SPI_SCK|SPI_MOSI)
  23. #define SPI_LOAD_PORT GPIOD
  24. #define SPI_LOAD GPIO_PIN_3
  25. #define MAX7219_ON 0x01
  26. #define MAX7219_OFF 0x00
  27. #define MAX7219_BRIGHT 0x08
  28. // used LED digits - 1
  29. #define MAX7219_DIGITS 7
  30. /* Exported types ------------------------------------------------------------*/
  31. typedef enum _max7219_reg {
  32. RegNoOp = 0x00,
  33. RegDigit0 = 0x01,
  34. RegDigit1 = 0x07,
  35. RegDigit2 = 0x03,
  36. RegDigit3 = 0x06,
  37. RegDigit4 = 0x05,
  38. RegDigit5 = 0x04,
  39. RegDigit6 = 0x08,
  40. RegDigit7 = 0x02,
  41. RegDecodeMode = 0x09,
  42. RegIntensity = 0x0A,
  43. RegScanLimit = 0x0B,
  44. RegPower = 0x0C,
  45. RegTest = 0x0F
  46. } max7219_reg_t;
  47. // соответсвие бит сегментам
  48. typedef enum _max7219_seg {
  49. SegA = (uint8_t)(1 << 2),
  50. SegB = (uint8_t)(1 << 6),
  51. SegC = (uint8_t)(1 << 5),
  52. SegD = (uint8_t)(1 << 7),
  53. SegE = (uint8_t)(1 << 3),
  54. SegF = (uint8_t)(1 << 4),
  55. SegG = (uint8_t)(1 << 1),
  56. SegDP = (uint8_t)(1 << 0),
  57. } max7219_seg_t;
  58. // symbols без кодирования
  59. typedef enum _max7219_sym {
  60. Sym_0 = SegA | SegB | SegC | SegD | SegE | SegF,
  61. Sym_1 = SegB | SegC,
  62. Sym_2 = SegA | SegB | SegD | SegE | SegG,
  63. Sym_3 = SegA | SegB | SegC | SegD | SegG,
  64. Sym_4 = SegB | SegC | SegF | SegG,
  65. Sym_5 = SegA | SegC | SegD | SegF | SegG,
  66. Sym_6 = SegA | SegC | SegD | SegE | SegF | SegG,
  67. Sym_7 = SegA | SegB | SegC,
  68. Sym_8 = SegA | SegB | SegC | SegD | SegE | SegF | SegG,
  69. Sym_9 = SegA | SegB | SegC | SegD | SegF | SegG,
  70. Sym_A = SegA | SegB | SegC | SegE | SegF | SegG,
  71. Sym_b = SegC | SegD | SegE | SegF | SegG,
  72. Sym_c = SegD | SegE | SegG,
  73. Sym_C = SegA | SegD | SegE | SegF,
  74. Sym_d = SegB | SegC | SegD | SegE | SegG,
  75. Sym_E = SegA | SegD | SegE | SegF | SegG,
  76. Sym_F = SegA | SegE | SegF | SegG,
  77. Sym_i = SegC,
  78. Sym_h = SegC | SegE | SegF | SegG,
  79. Sym_H = SegB | SegC | SegE | SegF | SegG,
  80. Sym_n = SegC | SegE | SegG,
  81. Sym_o = SegC | SegD | SegE | SegG,
  82. Sym_P = SegA | SegB | SegE | SegF | SegG,
  83. Sym_t = SegD | SegE | SegF | SegG,
  84. Sym_u = SegC | SegD | SegE,
  85. Sym_U = SegB | SegC | SegD | SegE | SegF,
  86. Sym_Gradus = SegA | SegB | SegF | SegG,
  87. Sym_Minus = SegG,
  88. Sym_BLANK = 0x00,
  89. Sym_FULL = 0xFF,
  90. Sym_Dot = SegDP
  91. } max7219_sym_t;
  92. /* Exported constants --------------------------------------------------------*/
  93. /* Exported macro ------------------------------------------------------------*/
  94. /* Exported variables --------------------------------------------------------*/
  95. /* Exported functions --------------------------------------------------------*/
  96. void MAX7219_Config(void);
  97. void MAX7219_WriteData(max7219_reg_t reg, uint8_t data);
  98. #endif /* __MAX7219_H */