123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #pragma once
- #ifndef _MAIN_H
- #define _MAIN_H
- /**
- * Битовые макросы
- */
- #define SetBit(x,y) x |= (1 << (y))
- #define ClrBit(x,y) x &= ~(1 << (y))
- #define InvBit(x,y) x ^= (1 << (y))
- #define IsBit(x,y) (x & (1 << (y)))
- #define ResBit(reg,bit) (reg &= ~_BV(bit))
- /*
- Автоматически включается avr/sfr_defs.h, который содержит:
- _BV(bit) === (1<<(bit))
- bit_is_set(sfr, bit)
- bit_is_clear(sfr, bit)
- loop_until_bit_is_set(sfr, bit)
- loop_until_bit_is_clear(sfr, bit)
- */
- /**
- * Дефайны
- */
- /* Port B, puttons, input, pull-up */
- #define DHT_PIN _BV(PB0)
- #define DHT_PIN_LOW DDRB |= DHT_PIN
- #define DHT_PIN_INPUT DDRB &= ~(DHT_PIN)
- #define BTN_NUM 3
- #define BUTTON1_PIN _BV(PB3)
- #define BUTTON2_PIN _BV(PB4)
- #define BUTTON3_PIN _BV(PB5)
- #define BUTTON_PINS (BUTTON1_PIN | BUTTON2_PIN | BUTTON3_PIN)
- #define BUTTON1_STATE (PINB & BUTTON1_PIN)
- #define BUTTON2_STATE (PINB & BUTTON2_PIN)
- #define BUTTON3_STATE (PINB & BUTTON3_PIN)
- #define BUTTONS_STATE (PINB & BUTTON_PINS)
- #define BUTTON_STATE(pin) (PINB & pin)
- #define BUTTON_PERIOD 10
- /* in ms */
- #define BTN_SCAN_PERIOD 10
- #define BTN_TIME_PAUSE 20
- /* все временные константы кнопок кратны периоду опроса кнопок - 10 ms. */
- #define BTN_TIME_PRESSED 3
- #define BTN_TIME_HOLDED 50
- #define BTN_TIME_REPEATED 5
- /* Port C, Lamp digits, output */
- #define DIGIT_BLANK 0x0F
- #define DIGIT_A0 _BV(PC0)
- #define DIGIT_A1 _BV(PC1)
- #define DIGIT_A2 _BV(PC2)
- #define DIGIT_A3 _BV(PC3)
- #define DIGIT_PINS (DIGIT_A0 | DIGIT_A1 | DIGIT_A2 | DIGIT_A3)
- /* Port D, Lamp anods, Dot, RTC interrupt, UART */
- #define DOT_PIN _BV(PD2)
- #define ANOD1 _BV(PD4)
- #define ANOD2 _BV(PD5)
- #define ANOD3 _BV(PD6)
- #define ANOD4 _BV(PD7)
- #define ANOD_PINS (ANOD1 | ANOD2 | ANOD3 | ANOD4)
- typedef struct {
- uint8_t time;
- es_event_t pressed;
- es_event_t holded;
- uint8_t pin;
- } btn_t;
- #endif
|