Last active
August 24, 2019 15:52
-
-
Save snipsnipsnip/343132 to your computer and use it in GitHub Desktop.
DRY bit manipulation macros (for attiny2313)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ピン番号とポートの名前の対応 (ATTiny2313) */ | |
/* | |
ここにくぼみがある | |
↓ | |
1 20 | |
2 19 | |
3 18 | |
4 17 | |
5 16 | |
6 15 | |
7 14 | |
8 13 | |
9 12 | |
10 11 | |
*/ | |
// 左上の1番はリセット (PA2) | |
#define P2(n,op) ((n ## D) op _BV(0)) | |
#define P3(n,op) ((n ## D) op _BV(1)) | |
#define P4(n,op) ((n ## A) op _BV(1)) | |
#define P5(n,op) ((n ## A) op _BV(0)) | |
#define P6(n,op) ((n ## D) op _BV(2)) | |
#define P7(n,op) ((n ## D) op _BV(3)) | |
#define P8(n,op) ((n ## D) op _BV(4)) | |
#define P9(n,op) ((n ## D) op _BV(5)) | |
// 左下の10番はグランド | |
// 右上の20番は電源 | |
#define P19(n,op) ((n ## B) op _BV(7)) | |
#define P18(n,op) ((n ## B) op _BV(6)) | |
#define P17(n,op) ((n ## B) op _BV(5)) | |
#define P16(n,op) ((n ## B) op _BV(4)) | |
#define P15(n,op) ((n ## B) op _BV(3)) | |
#define P14(n,op) ((n ## B) op _BV(2)) | |
#define P13(n,op) ((n ## B) op _BV(1)) | |
#define P12(n,op) ((n ## B) op _BV(0)) | |
#define P11(n,op) ((n ## D) op _BV(6)) | |
#define ON(pin) pin(PORT,|=) | |
#define OFF(pin) pin(PORT,&=~) | |
#define GET(pin) pin(PIN,&) | |
#define FLIP(pin) pin(PIN,|=) | |
#define IN(pin) pin(DDR,&=~) | |
#define OUT(pin) pin(DDR,|=) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment