max7219.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "stm8l15x.h"
  18. /* Exported defines ----------------------------------------------------------*/
  19. // соответсвие бит сегментам
  20. #define SEG_A 1
  21. #define SEG_B 3
  22. #define SEG_C 2
  23. #define SEG_D 5
  24. #define SEG_E 6
  25. #define SEG_F 0
  26. #define SEG_G 7
  27. #define SEG_DP 4
  28. // symbols
  29. // Для BCD
  30. #define MAX7219_CHAR_BLANK 0x0F
  31. #define MAX7219_CHAR_FULL 0x88
  32. // без кодирования
  33. #define SYM_0 0x6F
  34. #define SYM_1 0x0C
  35. #define SYM_2 0xEA
  36. #define SYM_3 0xAE
  37. #define SYM_4 0x8D
  38. #define SYM_5 0xA7
  39. #define SYM_6 0xE7
  40. #define SYM_7 0x0E
  41. #define SYM_8 0xEF
  42. #define SYM_9 0xAF
  43. #define SYM_A 0xCF
  44. #define SYM_b 0xE5
  45. #define SYM_c 0xE0
  46. #define SYM_C 0x63
  47. #define SYM_d 0xEC
  48. #define SYM_E 0xE3
  49. #define SYM_F 0xC3
  50. #define SYM_H 0xCD
  51. #define SYM_h 0xC5
  52. #define SYM_P 0xCB
  53. #define SYM_t 0xE1
  54. #define SYM_Gradus 0x8B
  55. #define SYM_LGradus 0xE4
  56. #define SYM_Temp 0xE1
  57. #define SYM_Minus 0x80
  58. #define SYM_Plus 0xD1
  59. #define SYM_BLANK 0x00
  60. #define SYM_FULL 0xFF
  61. #define SYM_DOT 0x10
  62. #define MAX7219_ON 0x01
  63. #define MAX7219_OFF 0x00
  64. #define MAX7219_BRIGHT 0x08
  65. // used LED digits - 1
  66. #define MAX7219_DIGITS 7
  67. /* Exported types ------------------------------------------------------------*/
  68. typedef enum _max7219_reg {
  69. RegNoOp = 0x00,
  70. RegDigit0 = 0x03,
  71. RegDigit1 = 0x08,
  72. RegDigit2 = 0x02,
  73. RegDigit3 = 0x01,
  74. RegDigit4 = 0x07,
  75. RegDigit5 = 0x04,
  76. RegDigit6 = 0x06,
  77. RegDigit7 = 0x05,
  78. RegDecodeMode = 0x09,
  79. RegIntensity = 0x0A,
  80. RegScanLimit = 0x0B,
  81. RegPower = 0x0C,
  82. RegTest = 0x0F
  83. } max7219_reg_t;
  84. typedef enum _max7219_seg {
  85. SegA = SEG_A,
  86. SegB = SEG_B,
  87. SegC = SEG_C,
  88. SegD = SEG_D,
  89. SegE = SEG_E,
  90. SegF = SEG_F,
  91. SegG = SEG_G,
  92. SegDP = SEG_DP,
  93. } max7219_seg_t;
  94. typedef enum _max7219_sym {
  95. Sym_0 = SYM_0,
  96. Sym_1 = SYM_1,
  97. Sym_2 = SYM_2,
  98. Sym_3 = SYM_3,
  99. Sym_4 = SYM_4,
  100. Sym_5 = SYM_5,
  101. Sym_6 = SYM_6,
  102. Sym_7 = SYM_7,
  103. Sym_8 = SYM_8,
  104. Sym_9 = SYM_9,
  105. Sym_A = SYM_A,
  106. Sym_b = SYM_b,
  107. Sym_c = SYM_c,
  108. Sym_C = SYM_C,
  109. Sym_d = SYM_d,
  110. Sym_E = SYM_E,
  111. Sym_h = SYM_h,
  112. Sym_H = SYM_H,
  113. Sym_F = SYM_F,
  114. Sym_P = SYM_P,
  115. Sym_t = SYM_t,
  116. Sym_Gradus = SYM_Gradus,
  117. Sym_LGradus = SYM_LGradus,
  118. Sym_Temp = SYM_Temp,
  119. Sym_Minus = SYM_Minus,
  120. Sym_Plus = SYM_P,
  121. Sym_BLANK = SYM_BLANK,
  122. Sym_FULL = SYM_FULL,
  123. Sym_Dot = SYM_DOT
  124. } max7219_sym_t;
  125. /* Exported constants --------------------------------------------------------*/
  126. /* Exported macro ------------------------------------------------------------*/
  127. /* Exported variables --------------------------------------------------------*/
  128. /* Exported functions --------------------------------------------------------*/
  129. void MAX7219_Config(void);
  130. void MAX7219_WriteData(max7219_reg_t reg, uint8_t data);
  131. #endif /* __MAX7219_H */