main.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #define LAMP_NUM 6
  24. /* Port B, puttons, input, pull-up */
  25. #define DHT_PIN _BV(PB0)
  26. #define DHT_PIN_LOW DDRB |= DHT_PIN
  27. #define DHT_PIN_INPUT DDRB &= ~(DHT_PIN)
  28. #define BTN_NUM 3
  29. #define BUTTON1_PIN _BV(PB3)
  30. #define BUTTON2_PIN _BV(PB4)
  31. #define BUTTON3_PIN _BV(PB5)
  32. #define BUTTON_PINS (BUTTON1_PIN | BUTTON2_PIN | BUTTON3_PIN)
  33. #define BUTTON1_STATE (PINB & BUTTON1_PIN)
  34. #define BUTTON2_STATE (PINB & BUTTON2_PIN)
  35. #define BUTTON3_STATE (PINB & BUTTON3_PIN)
  36. #define BUTTONS_STATE (PINB & BUTTON_PINS)
  37. #define BUTTON_STATE(pin) (PINB & pin)
  38. #define BUTTON_PERIOD 10
  39. /* in ms */
  40. #define BTN_SCAN_PERIOD 10
  41. #define BTN_TIME_PAUSE 20
  42. /* все временные константы кнопок кратны периоду опроса кнопок - 10 ms. */
  43. #define BTN_TIME_PRESSED 3
  44. #define BTN_TIME_HOLDED 50
  45. #define BTN_TIME_REPEATED 5
  46. /* Port C, Lamp digits, output */
  47. #define DIGIT_BLANK 0x0F
  48. #define DIGIT_A0 _BV(PC0)
  49. #define DIGIT_A1 _BV(PC1)
  50. #define DIGIT_A2 _BV(PC2)
  51. #define DIGIT_A3 _BV(PC3)
  52. #define DIGIT_PINS (DIGIT_A0 | DIGIT_A1 | DIGIT_A2 | DIGIT_A3)
  53. /* Port D, Lamp anods, Dot, RTC interrupt, UART */
  54. #define A123_PORT PORTD
  55. #define DOT_PIN _BV(PD4)
  56. #define ANOD1 _BV(PD5)
  57. #define ANOD2 _BV(PD6)
  58. #define ANOD3 _BV(PD7)
  59. #define ANODD_PINS (ANOD1 | ANOD2 | ANOD3)
  60. /* Port B, Lamp anods, BTNs */
  61. #define A456_PORT PORTB
  62. #define ANOD4 _BV(PB0)
  63. #define ANOD5 _BV(PB1)
  64. #define ANOD6 _BV(PB2)
  65. #define ANODB_PINS (ANOD4 | ANOD5 | ANOD6)
  66. typedef struct {
  67. uint8_t time;
  68. es_event_t pressed;
  69. es_event_t holded;
  70. uint8_t pin;
  71. } btn_t;
  72. #endif