Advertisement
Guest User

Untitled

a guest
May 11th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2. /**
  3.  * Copyright (c) 2017-2018, Łukasz Marcin Podkalicki <lpodkalicki@gmail.com>
  4.  *
  5.  * This is ATtiny13/25/45/85 library for 4-Digit LED Display based on TM1637 chip.
  6.  *
  7.  * Features:
  8.  * - display raw segments
  9.  * - display digits
  10.  * - display colon
  11.  * - display on/off
  12.  * - brightness control
  13.  *
  14.  * References:
  15.  * - library: https://github.com/lpodkalicki/attiny-tm1637-library
  16.  * - documentation: https://github.com/lpodkalicki/attiny-tm1637-library/README.md
  17.  * - TM1637 datasheet: https://github.com/lpodkalicki/attiny-tm1637-library/blob/master/docs/TM1637_V2.4_EN.pdf
  18.  */
  19.  
  20.  
  21.  
  22. #include <stdint.h>
  23.  
  24. // Main Settings
  25.  
  26. #define TM1637_DELAY_US         (5)
  27. #define TM1637_BRIGHTNESS_MAX       (7)
  28. #define TM1637_POSITION_MAX     (4)
  29.  
  30. // TM1637 commands
  31. #define TM1637_CMD_SET_DATA     0x40
  32. #define TM1637_CMD_SET_ADDR     0xC0
  33. #define TM1637_CMD_SET_DSIPLAY      0x80
  34.    
  35.  
  36. // TM1637 data settings (use bitwise OR to contruct complete command)
  37. #define TM1637_SET_DATA_WRITE       0x00 // write data to the display register
  38. #define TM1637_SET_DATA_READ        0x02 // read the key scan data
  39. #define TM1637_SET_DATA_A_ADDR      0x00 // automatic address increment
  40. #define TM1637_SET_DATA_F_ADDR      0x04 // fixed address
  41. #define TM1637_SET_DATA_M_NORM      0x00 // normal mode
  42. #define TM1637_SET_DATA_M_TEST      0x10 // test mode
  43.  
  44. // TM1637 display control command set (use bitwise OR to consruct complete command)
  45. #define TM1637_SET_DISPLAY_OFF      0x00 // off
  46. #define TM1637_SET_DISPLAY_ON       0x08 // on
  47.  
  48.  
  49. /**
  50.  * Initialize TM1637 display driver.
  51.  * Clock pin (TM1637_CLK_PIN) and data pin (TM1637_DIO_PIN)
  52.  * are defined at the top of this file.
  53.  */
  54. void TM1637_init(const uint8_t enable, const uint8_t brightness);
  55.  
  56. /**
  57.  * Turn display on/off.
  58.  * value: 1 - on, 0 - off
  59.  */
  60. void TM1637_enable(const uint8_t value);
  61.  
  62. /**
  63.  * Set display brightness.
  64.  * Min value: 0
  65.  * Max value: 7
  66.  */
  67. void TM1637_set_brightness(const uint8_t value);
  68.  
  69. /**
  70.  * Display raw segments at position (0x00..0x03)
  71.  *
  72.  *      bits:
  73.  *        -- 0 --
  74.  *       |       |
  75.  *       5       1
  76.  *       |       |
  77.  *        -- 6 --
  78.  *       |       |
  79.  *       4       2
  80.  *       |       |
  81.  *        -- 3 --
  82.  *
  83.  * Example segment configurations:
  84.  * - for character 'H', segments=0b01110110
  85.  * - for character '-', segments=0b01000000
  86.  * - etc.
  87.  */
  88. void TM1637_display_segments(const uint8_t position, const uint8_t segments);
  89.  
  90. /**
  91.  * Display digit ('0'..'9') at position (0x00..0x03)
  92.  */
  93. void TM1637_display_digit(const uint8_t position, const uint8_t digit);
  94.  
  95. /**
  96.  * Display colon on/off.
  97.  * value: 1 - on, 0 - off
  98.  */
  99. void TM1637_display_colon(const uint8_t value);
  100.  
  101. /**
  102.  * Clear all segments (including colon).
  103.  */
  104. void TM1637_clear(void);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement