main.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #ifndef _MAIN_H
  3. #define _MAIN_H
  4. /**
  5. * Битовые макросы
  6. */
  7. #define SetBit(x,y) x |= (1 << (y))
  8. #define ClrBit(x,y) x &= ~(1 << (y))
  9. #define InvBit(x,y) x ^= (1 << (y))
  10. #define IsBit(x,y) (x & (1 << (y)))
  11. #define ResBit(reg,bit) (reg &= ~_BV(bit))
  12. /*
  13. Автоматически включается avr/sfr_defs.h, который содержит:
  14. _BV(bit) === (1<<(bit))
  15. bit_is_set(sfr, bit)
  16. bit_is_clear(sfr, bit)
  17. loop_until_bit_is_set(sfr, bit)
  18. loop_until_bit_is_clear(sfr, bit)
  19. */
  20. /**
  21. * Дефайны
  22. */
  23. /* Port B, puttons, input, pull-up */
  24. #define DHT_PIN _BV(PB0)
  25. #define DHT_PIN_LOW DDRB |= DHT_PIN
  26. #define DHT_PIN_INPUT DDRB &= ~(DHT_PIN)
  27. #define BTN_NUM 3
  28. #define BUTTON1_PIN _BV(PB3)
  29. #define BUTTON2_PIN _BV(PB4)
  30. #define BUTTON3_PIN _BV(PB5)
  31. #define BUTTON_PINS (BUTTON1_PIN | BUTTON2_PIN | BUTTON3_PIN)
  32. #define BUTTON1_STATE (PINB & BUTTON1_PIN)
  33. #define BUTTON2_STATE (PINB & BUTTON2_PIN)
  34. #define BUTTON3_STATE (PINB & BUTTON3_PIN)
  35. #define BUTTONS_STATE (PINB & BUTTON_PINS)
  36. #define BUTTON_STATE(pin) (PINB & pin)
  37. #define BUTTON_PERIOD 10
  38. /* in ms */
  39. #define BTN_SCAN_PERIOD 10
  40. #define BTN_TIME_PAUSE 20
  41. /* все временные константы кнопок кратны периоду опроса кнопок - 10 ms. */
  42. #define BTN_TIME_PRESSED 3
  43. #define BTN_TIME_HOLDED 50
  44. #define BTN_TIME_REPEATED 5
  45. /* Port C, Lamp digits, output */
  46. #define DIGIT_BLANK 0x0F
  47. #define DIGIT_A0 _BV(PC0)
  48. #define DIGIT_A1 _BV(PC1)
  49. #define DIGIT_A2 _BV(PC2)
  50. #define DIGIT_A3 _BV(PC3)
  51. #define DIGIT_PINS (DIGIT_A0 | DIGIT_A1 | DIGIT_A2 | DIGIT_A3)
  52. /* Port D, Lamp anods, Dot, RTC interrupt, UART */
  53. #define DOT_PIN _BV(PD2)
  54. #define ANOD1 _BV(PD4)
  55. #define ANOD2 _BV(PD5)
  56. #define ANOD3 _BV(PD6)
  57. #define ANOD4 _BV(PD7)
  58. #define ANOD_PINS (ANOD1 | ANOD2 | ANOD3 | ANOD4)
  59. typedef struct {
  60. uint8_t time;
  61. es_event_t pressed;
  62. es_event_t holded;
  63. uint8_t pin;
  64. } btn_t;
  65. #endif