added test macro in readme
This commit is contained in:
35
README.md
35
README.md
@@ -79,3 +79,38 @@ avrdude: safemode: Fuses OK (E:00, H:00, L:00)
|
|||||||
|
|
||||||
avrdude done. Thank you.
|
avrdude done. Thank you.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## test macros
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
// // stringify
|
||||||
|
#define STRINGIFY_HELPER(x) #x
|
||||||
|
#define STRINGIFY(x) STRINGIFY_HELPER(x)
|
||||||
|
|
||||||
|
#define CONCAT_HELPER(x, y) x ## y
|
||||||
|
#define CONCAT(x, y) CONCAT_HELPER(x, y)
|
||||||
|
|
||||||
|
// get argument at nth position
|
||||||
|
#define ARG_1(v1, v2) v1
|
||||||
|
#define ARG_2(v1, v2) v2
|
||||||
|
#define GET_PORT(args) ARG_1 args
|
||||||
|
#define GET_BIT(args) ARG_2 args
|
||||||
|
|
||||||
|
// actions on registers
|
||||||
|
#define SET(register, bit) register |= 1 << bit
|
||||||
|
|
||||||
|
// actions on ports
|
||||||
|
#define MODE_OUTPUT(elem) SET(CONCAT(DDR, GET_PORT(elem)), GET_BIT(elem))
|
||||||
|
|
||||||
|
// elements
|
||||||
|
#define LED1 (B, 0)
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
MODE_OUTPUT(LED1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user