main.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _MAIN_H_
  2. #define _MAIN_H_
  3. #if defined(__GNUC__)
  4. # include <avr/io.h>
  5. # include <avr/sleep.h>
  6. # include <avr/interrupt.h>
  7. #elif defined(__ICCAVR__)
  8. # include <ioavr.h>
  9. # include <intrinsics.h>
  10. # include <stdint.h>
  11. #endif
  12. /**
  13. * Global defines
  14. */
  15. #ifndef F_CPU
  16. #define F_CPU 16000000
  17. #endif
  18. #define TIMER0_HZ 1000
  19. #define TIMER0_PRESCALER 64
  20. #define TIMER0_CNT (0x100 - (F_CPU / TIMER0_PRESCALER / TIMER0_HZ))
  21. #define TIMER1_HZ 1
  22. #define TIMER1_PRESCALER 1024
  23. #define TIMER1_CNT (uint16_t)(0x10000 - (F_CPU / TIMER1_PRESCALER / TIMER1_HZ))
  24. /**
  25. * Bitwise macro
  26. */
  27. #define SetBit(x,y) do{ x |= (1 << (y));} while(0)
  28. #define ClrBit(x,y) do{ x &= ~(1 << (y));} while(0)
  29. #define InvBit(x,y) do{(x)^= (1 << (y));} while(0)
  30. #define IsBit(x,y) (x & (1 << (y)))
  31. #define ResBit(reg,bit) (reg &= ~_BV(bit))
  32. /*
  33. Автоматически включается avr/sfr_defs.h, кторый содержит:
  34. _BV(bit) === (1<<(bit))
  35. bit_is_set(sfr, bit)
  36. bit_is_clear(sfr, bit)
  37. loop_until_bit_is_set(sfr, bit)
  38. loop_until_bit_is_clear(sfr, bit)
  39. */
  40. /**
  41. * Global Type defines
  42. */
  43. typedef unsigned char u08;
  44. typedef unsigned short u16;
  45. typedef unsigned long u32;
  46. typedef unsigned long long u64;
  47. typedef signed char s08;
  48. typedef signed short s16;
  49. typedef signed long s32;
  50. typedef signed long long s64;
  51. typedef struct {
  52. uint8_t HH;
  53. uint8_t MM;
  54. uint8_t SS;
  55. } clock_t;
  56. /**
  57. * Interrupt macro
  58. */
  59. static volatile u08 saveRegister;
  60. #if defined(__GNUC__)
  61. #define ENABLE_INTERRUPT do{sei();}while(0)
  62. #define DISABLE_INTERRUPT do{saveRegister = SREG; cli();}while(0)
  63. #elif defined(__ICCAVR__)
  64. #define ENABLE_INTERRUPT do{__enable_interrupt();}while(0)
  65. #define DISABLE_INTERRUPT do{saveRegister = SREG; __disable_interrupt();}while(0)
  66. #endif
  67. #define RESTORE_INTERRUPT do{SREG = saveRegister;}while(0)
  68. //использовать RESTORE только после DISABLE
  69. /**
  70. * Logical values
  71. */
  72. #define TRUE 1
  73. #define FALSE 0
  74. #define HIGH 1
  75. #define LOW 0
  76. #define ON 1
  77. #define OFF 0
  78. #ifndef NULL
  79. #define NULL 0
  80. #endif // NULL
  81. /**
  82. * Maximum values of types
  83. */
  84. #define MAX08U 255
  85. #define MAX16U 65535
  86. #define MAX32U 4294967295
  87. #define MIN08S -128
  88. #define MAX08S 127
  89. #define MIN16S -32768
  90. #define MAX16S 32767
  91. #define MIN32S -2147483648
  92. #define MAX32S 2147483647
  93. /**
  94. * GPIO defention
  95. */
  96. #define HEATER_PORT PORTB
  97. #define HEATER_PIN PB1
  98. /*--------------------------------------------------------------------------*/
  99. #endif /* _MAIN_H_ */