max7219.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 5
  21. #define SEG_B 3
  22. #define SEG_C 4
  23. #define SEG_D 1
  24. #define SEG_E 0
  25. #define SEG_F 6
  26. #define SEG_G 7
  27. #define SEG_DP 2
  28. // symbols
  29. // Для BCD
  30. #define MAX7219_CHAR_BLANK 0x0F
  31. #define MAX7219_CHAR_FULL 0x88
  32. // без кодирования
  33. #define SYM_0 0x7B
  34. #define SYM_1 0x18
  35. #define SYM_2 0xAB
  36. #define SYM_3 0xBA
  37. #define SYM_4 0xD8
  38. #define SYM_5 0xF2
  39. #define SYM_6 0xF3
  40. #define SYM_7 0x38
  41. #define SYM_8 0xFB
  42. #define SYM_9 0xFA
  43. #define SYM_A 0xF9
  44. #define SYM_b 0xD3
  45. #define SYM_c 0x83
  46. #define SYM_C 0x63
  47. #define SYM_d 0x9B
  48. #define SYM_E 0xE3
  49. #define SYM_F 0xE1
  50. #define SYM_P 0xE9
  51. #define SYM_Gradus 0xE8
  52. #define SYM_LGradus 0x93
  53. #define SYM_Temp 0xC3
  54. #define SYM_Minus 0x80
  55. #define SYM_BLANK 0x00
  56. #define SYM_FULL 0xFF
  57. #define MAX7219_ON 0x01
  58. #define MAX7219_OFF 0x00
  59. #define MAX7219_BRIGHT 0x08
  60. // used LED digits - 1
  61. #define MAX7219_DIGITS 7
  62. /* Exported types ------------------------------------------------------------*/
  63. typedef enum {
  64. Digit0 = 0x07,
  65. Digit1 = 0x06,
  66. Digit2 = 0x04,
  67. Digit3 = 0x01,
  68. Digit4 = 0x03,
  69. Digit5 = 0x02,
  70. Digit6 = 0x00,
  71. Digit7 = 0x05,
  72. DecodeMode = 0x09,
  73. Intensity = 0x0A,
  74. ScanLimit = 0x0B,
  75. Power = 0x0C,
  76. Test = 0x0F
  77. } max7219_reg_t;
  78. typedef enum {
  79. SegA = 5,
  80. SegB = 3,
  81. SegC = 4,
  82. SegD = 1,
  83. SegE = 0,
  84. SegF = 6,
  85. SegG = 7,
  86. SegDP = 2,
  87. } max7219_seg_t;
  88. typedef enum {
  89. Sym_0 = 0x7B,
  90. Sym_1 = 0x18,
  91. Sym_2 = 0xAB,
  92. Sym_3 = 0xBA,
  93. Sym_4 = 0xD8,
  94. Sym_5 = 0xF2,
  95. Sym_6 = 0xF3,
  96. Sym_7 = 0x38,
  97. Sym_8 = 0xFB,
  98. Sym_9 = 0xFA,
  99. Sym_A = 0xF9,
  100. Sym_b = 0xD3,
  101. Sym_c = 0x83,
  102. Sym_C = 0x63,
  103. Sym_d = 0x9B,
  104. Sym_E = 0xE3,
  105. Sym_F = 0xE1,
  106. Sym_P = 0xE9,
  107. Sym_Gradus = 0xE8,
  108. Sym_LGradus = 0x93,
  109. Sym_Temp = 0xC3,
  110. Sym_Minus = 0x80,
  111. Sym_Plus = 0x98, // C1 ?
  112. Sym_BLANK = 0x00,
  113. Sym_FULL = 0xFF
  114. } max7219_sym_t;
  115. /* Exported constants --------------------------------------------------------*/
  116. /* Exported macro ------------------------------------------------------------*/
  117. /* Exported variables --------------------------------------------------------*/
  118. /* Exported functions --------------------------------------------------------*/
  119. void MAX7219_Init(void);
  120. void MAX7219_WriteData(max7219_reg_t reg, uint8_t data);
  121. #endif /* __MAX7219_H */