main.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /**
  22. * Bitwise macro
  23. */
  24. #define SetBit(x,y) do{ x |= (1 << (y));} while(0)
  25. #define ClrBit(x,y) do{ x &= ~(1 << (y));} while(0)
  26. #define InvBit(x,y) do{(x)^= (1 << (y));} while(0)
  27. #define IsBit(x,y) (x & (1 << (y)))
  28. #define ResBit(reg,bit) (reg &= ~_BV(bit))
  29. /*
  30. Автоматически включается avr/sfr_defs.h, кторый содержит:
  31. _BV(bit) === (1<<(bit))
  32. bit_is_set(sfr, bit)
  33. bit_is_clear(sfr, bit)
  34. loop_until_bit_is_set(sfr, bit)
  35. loop_until_bit_is_clear(sfr, bit)
  36. */
  37. /**
  38. * Global Type defines
  39. */
  40. typedef unsigned char u08;
  41. typedef unsigned short u16;
  42. typedef unsigned long u32;
  43. typedef unsigned long long u64;
  44. typedef signed char s08;
  45. typedef signed short s16;
  46. typedef signed long s32;
  47. typedef signed long long s64;
  48. /**
  49. * Interrupt macro
  50. */
  51. static volatile u08 saveRegister;
  52. #if defined(__GNUC__)
  53. #define ENABLE_INTERRUPT do{sei();}while(0)
  54. #define DISABLE_INTERRUPT do{saveRegister = SREG; cli();}while(0)
  55. #elif defined(__ICCAVR__)
  56. #define ENABLE_INTERRUPT do{__enable_interrupt();}while(0)
  57. #define DISABLE_INTERRUPT do{saveRegister = SREG; __disable_interrupt();}while(0)
  58. #endif
  59. #define RESTORE_INTERRUPT do{SREG = saveRegister;}while(0)
  60. //использовать RESTORE только после DISABLE
  61. /**
  62. * Logical values
  63. */
  64. #define TRUE 1
  65. #define FALSE 0
  66. #define HIGH 1
  67. #define LOW 0
  68. #define ON 1
  69. #define OFF 0
  70. #ifndef NULL
  71. #define NULL 0
  72. #endif // NULL
  73. /**
  74. * Maximum values of types
  75. */
  76. #define MAX08U 255
  77. #define MAX16U 65535
  78. #define MAX32U 4294967295
  79. #define MIN08S -128
  80. #define MAX08S 127
  81. #define MIN16S -32768
  82. #define MAX16S 32767
  83. #define MIN32S -2147483648
  84. #define MAX32S 2147483647
  85. /**
  86. * GPIO defention
  87. */
  88. #define HEATER_PORT PORTB
  89. #define HEATER_PIN PB1
  90. /*--------------------------------------------------------------------------*/
  91. #endif /* _MAIN_H_ */