max7219.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #include "board.h"
  19. /* Exported defines ----------------------------------------------------------*/
  20. #define MAX7219_ON 0x01
  21. #define MAX7219_OFF 0x00
  22. #define MAX7219_BRIGHT 0x08
  23. // used LED digits - 1
  24. #define MAX7219_DIGITS 7
  25. /* Exported types ------------------------------------------------------------*/
  26. typedef enum _max7219_reg {
  27. RegNoOp = 0x00,
  28. RegDigit0 = 0x01,
  29. RegDigit1 = 0x07,
  30. RegDigit2 = 0x03,
  31. RegDigit3 = 0x06,
  32. RegDigit4 = 0x05,
  33. RegDigit5 = 0x04,
  34. RegDigit6 = 0x08,
  35. RegDigit7 = 0x02,
  36. RegDecodeMode = 0x09,
  37. RegIntensity = 0x0A,
  38. RegScanLimit = 0x0B,
  39. RegPower = 0x0C,
  40. RegTest = 0x0F
  41. } max7219_reg_t;
  42. // соответсвие бит сегментам
  43. typedef enum _max7219_seg {
  44. SegA = (uint8_t)(1 << 2),
  45. SegB = (uint8_t)(1 << 6),
  46. SegC = (uint8_t)(1 << 5),
  47. SegD = (uint8_t)(1 << 7),
  48. SegE = (uint8_t)(1 << 3),
  49. SegF = (uint8_t)(1 << 4),
  50. SegG = (uint8_t)(1 << 1),
  51. SegDP = (uint8_t)(1 << 0),
  52. } max7219_seg_t;
  53. // symbols без кодирования
  54. typedef enum _max7219_sym {
  55. Sym_0 = SegA | SegB | SegC | SegD | SegE | SegF,
  56. Sym_1 = SegB | SegC,
  57. Sym_2 = SegA | SegB | SegD | SegE | SegG,
  58. Sym_3 = SegA | SegB | SegC | SegD | SegG,
  59. Sym_4 = SegB | SegC | SegF | SegG,
  60. Sym_5 = SegA | SegC | SegD | SegF | SegG,
  61. Sym_6 = SegA | SegC | SegD | SegE | SegF | SegG,
  62. Sym_7 = SegA | SegB | SegC,
  63. Sym_8 = SegA | SegB | SegC | SegD | SegE | SegF | SegG,
  64. Sym_9 = SegA | SegB | SegC | SegD | SegF | SegG,
  65. Sym_A = SegA | SegB | SegC | SegE | SegF | SegG,
  66. Sym_b = SegC | SegD | SegE | SegF | SegG,
  67. Sym_c = SegD | SegE | SegG,
  68. Sym_C = SegA | SegD | SegE | SegF,
  69. Sym_d = SegB | SegC | SegD | SegE | SegG,
  70. Sym_E = SegA | SegD | SegE | SegF | SegG,
  71. Sym_F = SegA | SegE | SegF | SegG,
  72. Sym_i = SegC,
  73. Sym_h = SegC | SegE | SegF | SegG,
  74. Sym_H = SegB | SegC | SegE | SegF | SegG,
  75. Sym_n = SegC | SegE | SegG,
  76. Sym_o = SegC | SegD | SegE | SegG,
  77. Sym_P = SegA | SegB | SegE | SegF | SegG,
  78. Sym_t = SegD | SegE | SegF | SegG,
  79. Sym_u = SegC | SegD | SegE,
  80. Sym_U = SegB | SegC | SegD | SegE | SegF,
  81. Sym_Gradus = SegA | SegB | SegF | SegG,
  82. Sym_Minus = SegG,
  83. Sym_BLANK = 0x00,
  84. Sym_FULL = 0xFF,
  85. Sym_Dot = SegDP
  86. } max7219_sym_t;
  87. /* Exported constants --------------------------------------------------------*/
  88. /* Exported macro ------------------------------------------------------------*/
  89. /* Exported variables --------------------------------------------------------*/
  90. /* Exported functions --------------------------------------------------------*/
  91. void MAX7219_Config(void);
  92. void MAX7219_WriteData(max7219_reg_t reg, uint8_t data);
  93. #endif /* __MAX7219_H */