max7219.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_P 0xCB
  51. #define SYM_Gradus 0x8B
  52. #define SYM_LGradus 0xE4
  53. #define SYM_Temp 0xE1
  54. #define SYM_Minus 0x80
  55. #define SYM_Plus 0xD1
  56. #define SYM_BLANK 0x00
  57. #define SYM_FULL 0xFF
  58. #define SYM_DOT 0x10
  59. #define MAX7219_ON 0x01
  60. #define MAX7219_OFF 0x00
  61. #define MAX7219_BRIGHT 0x08
  62. // used LED digits - 1
  63. #define MAX7219_DIGITS 7
  64. /* Exported types ------------------------------------------------------------*/
  65. typedef enum _max7219_reg {
  66. RegNoOp = 0x00,
  67. RegDigit0 = 0x03,
  68. RegDigit1 = 0x08,
  69. RegDigit2 = 0x02,
  70. RegDigit3 = 0x01,
  71. RegDigit4 = 0x07,
  72. RegDigit5 = 0x04,
  73. RegDigit6 = 0x06,
  74. RegDigit7 = 0x05,
  75. RegDecodeMode = 0x09,
  76. RegIntensity = 0x0A,
  77. RegScanLimit = 0x0B,
  78. RegPower = 0x0C,
  79. RegTest = 0x0F
  80. } max7219_reg_t;
  81. typedef enum _max7219_seg {
  82. SegA = SEG_A,
  83. SegB = SEG_B,
  84. SegC = SEG_C,
  85. SegD = SEG_D,
  86. SegE = SEG_E,
  87. SegF = SEG_F,
  88. SegG = SEG_G,
  89. SegDP = SEG_DP,
  90. } max7219_seg_t;
  91. typedef enum _max7219_sym {
  92. Sym_0 = SYM_0,
  93. Sym_1 = SYM_1,
  94. Sym_2 = SYM_2,
  95. Sym_3 = SYM_3,
  96. Sym_4 = SYM_4,
  97. Sym_5 = SYM_5,
  98. Sym_6 = SYM_6,
  99. Sym_7 = SYM_7,
  100. Sym_8 = SYM_8,
  101. Sym_9 = SYM_9,
  102. Sym_A = SYM_A,
  103. Sym_b = SYM_b,
  104. Sym_c = SYM_c,
  105. Sym_C = SYM_C,
  106. Sym_d = SYM_d,
  107. Sym_E = SYM_E,
  108. Sym_F = SYM_F,
  109. Sym_P = SYM_P,
  110. Sym_Gradus = SYM_Gradus,
  111. Sym_LGradus = SYM_LGradus,
  112. Sym_Temp = SYM_Temp,
  113. Sym_Minus = SYM_Minus,
  114. Sym_Plus = SYM_P,
  115. Sym_BLANK = SYM_BLANK,
  116. Sym_FULL = SYM_FULL,
  117. Sym_Dot = SYM_DOT
  118. } max7219_sym_t;
  119. /* Exported constants --------------------------------------------------------*/
  120. /* Exported macro ------------------------------------------------------------*/
  121. /* Exported variables --------------------------------------------------------*/
  122. /* Exported functions --------------------------------------------------------*/
  123. void MAX7219_Config(void);
  124. void MAX7219_WriteData(max7219_reg_t reg, uint8_t data);
  125. #endif /* __MAX7219_H */