embedded-systems-labs/prekol-display/tm1637.h
2025-12-25 11:09:27 +03:00

41 lines
1.3 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef TM1637_H
#define TM1637_H
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "main.h"
// TM1637 pins (порт A)
#define TM1637_CLK_PIN 6 // PA6
#define TM1637_DIO_PIN 7 // PA7
#define TM1637_CMD1 0x40 // автоинкремент адреса
#define TM1637_CMD2 0xC0 // установка стартового адреса
#define TM1637_CMD3 0x8F // дисплей вкл., макс. яркость
// Низкоуровневые функции
void tm1637_init(void);
void tm1637_start(void);
void tm1637_stop(void);
void tm1637_write_byte(uint8_t byte);
void tm1637_display_digit(uint8_t digit, uint8_t data);
void tm1637_clear(void);
void delay_us(uint32_t us);
// Высокоуровневые функции вывода
void tm1637_display_number(int number); // десятичное число (0..9999)
void tm1637_display_hex(uint8_t value); // 8-битное число в HEX
void tm1637_display_channel_state(uint8_t ch, uint8_t state); // "N - h"/"N - 0"
void tm1637_display_raw(uint8_t d3, uint8_t d2,
uint8_t d1, uint8_t d0); // сырые сегменты
// Остались для совместимости с шаблоном
void tm1637_update(void);
extern uint32_t last_display_update;
extern uint16_t counter;
#endif