Advertisement
ind03

Heiko.h Macros

Aug 26th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #ifndef HEIKO_H
  2. #define HEIKO_H 1
  3.  
  4. #define INLINE __attribute__((always_inline));
  5.  
  6. #define NOP()   asm volatile ("nop")
  7. #define NOP2()  asm volatile ("rjmp 1f\n 1:")
  8.  
  9. typedef unsigned char byte;
  10. typedef unsigned int uint;
  11. typedef unsigned long ulong;
  12.  
  13. typedef union
  14. {
  15.   struct
  16.     {
  17.         byte low;
  18.         byte high;
  19.     };
  20.     uint word;
  21. } WORD;
  22.  
  23.  
  24. #define nullptr ((void*) 0)
  25.  
  26. // Highbyte / Lowbyte of variables
  27. #define LOW_BYTE(var)       (((unsigned char *)&(var))[0])
  28. #define HIGH_BYTE(var)      (((unsigned char *)&(var))[1])
  29. #define MK_WORD(low,high)   (low | (high<<8))
  30.  
  31. //______________________________________________________
  32. #define S(bit)          (1<<bit)
  33. #define R(bit)          (~(1<<bit))
  34. #define C(bit)          (~(1<<bit))
  35.  
  36. //____ Bit functions __________________________________
  37. #define BM(bit)             (1<<bit)
  38. #define BS(bit)             (1<<bit)
  39. #define BC(bit)             (0<<bit)
  40. #define IsSET(port,bit)     ((port & BM(bit)) != 0)
  41. #define IsCLEAR(port,bit)   ((port & BM(bit)) == 0)
  42. #define SetBit(port,bit)    port |= BM(bit)
  43. #define ClearBit(port,bit)  port &= ~BM(bit)
  44.  
  45.  
  46. //____ Port functions __________________________________
  47.  
  48. #define DDR(port)           __CONCAT(DDR, port)
  49. #define PIN(port)           __CONCAT(PIN, port)
  50. #define PORT(port)          __CONCAT(PORT, port)
  51.  
  52.  
  53. #define DIRIN(port,bit)     __CONCAT(DDR, port) &= (byte) ~BM(bit)
  54. #define DIROUT(port,bit)    __CONCAT(DDR, port) |= (byte) BM(bit)
  55. #define SETHIGH(port,bit)   __CONCAT(PORT, port) |= (byte) BM(bit)
  56. #define SETLOW(port,bit)    __CONCAT(PORT, port) &= (byte) ~BM(bit)
  57. #define TOGGLE(port,bit)    __CONCAT(PIN, port) |= (byte) BM(bit)
  58. #define ISHIGH(port,bit)    ((__CONCAT(PIN, port) & BM(bit)) != 0)
  59. #define ISLOW(port,bit)     ((__CONCAT(PIN, port) & BM(bit)) == 0)
  60. #define PULLUPON(port,bit)  __CONCAT(PORT, port) |= (byte) BM(bit)
  61. #define PULLUPOFF(port,bit) __CONCAT(PORT, port) &= (byte) ~BM(bit)
  62.  
  63. //____ Open Collector assumes a 0 at the pins_________
  64. #define OCHIGH(port,bit)    __CONCAT(DDR, port) &= ~BM(bit)
  65. #define OCLOW(port,bit)     __CONCAT(DDR, port) |= BM(bit)
  66.  
  67.  
  68. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement