// Arduino の空き端子処理関数 20200528uuPinSetup.ino // uuPinOutputLow, uuPinOutputHigh, uupinInputPullup, uuPinInput // 2020/05/28 ラジオペンチ void setup() { // Serial.begin(115200); // pinMode(13, OUTPUT); uuPinOutputLow(0b01111111111100, 0b111111); // 未使用ピンをLOW出力に設定 // uuPinOutputHigh(0b01111111111100, 0b111111); // 未使用ピンをHIGH出力に設定 // uuPinInputPullup(0b01111111111100, 0b111111); // 未使用ピンを入力プルアップに設定 // uuPinInput(0b01111111111100, 0b111111); // 未使用ピンを入力に設定(デフォルトに戻す) } void loop() { } void uuPinOutputLow(unsigned int d, unsigned int a) { // 指定ピンを出力/LOWに設定(un used Pin set to Output Low) // ビットパターンで該当ピンを指定(1で有効)。d:D13-D0, a:A5-A0 // PORTx =0, DDRx=1 unsigned int x; x = d & 0x00FF ; PORTD &= ~x; DDRD |= x; // D0-7 x = (d >> 8) & 0x3F; PORTB &= ~x; DDRB |= x; // D8-13 x = a & 0x003F ; PORTC &= ~x; DDRC |= x; // A0-5 } void uuPinOutputHigh(unsigned int d, unsigned int a) { // 未使用ピンを出力/HIGHに設定(un used Pin set to Output High) // ビットパターンで該当ピンを指定(1で有効)。d:D13-D0, a:A5-A0 // PORTx =1, DDRx=1 unsigned int x; x = d & 0x00FF ; PORTD |= x; DDRD |= x; // D0-7 x = (d >> 8) & 0x3F; PORTB |= x; DDRB |= x; // D8-13 x = a & 0x003F ; PORTC |= x; DDRC |= x; // A0-5 } void uuPinInputPullup(unsigned int d, unsigned int a) { // 未使用ピンを入力/PULLUPに設定(un used Pin set to Input Pullup) // ビットパターンで該当ピンを指定(1で有効)。d:D13-D0, a:A5-A0 // PORTx =1, DDRx=0 unsigned int x; x = d & 0x00FF ; PORTD |= x; DDRD &= ~x; // D0-7 x = (d >> 8) & 0x3F; PORTB |= x; DDRB &= ~x; // D8-13 x = a & 0x003F ; PORTC |= x; DDRC &= ~x; // A0-5 } void uuPinInput(unsigned int d, unsigned int a) { // 未使用ピンを入力(Hi-Z)に設定(un used Pin set to Input) // ビットパターンで該当ピンを指定(1で有効)。d:D13-D0, a:A5-A0 // PORTx =0, DDRx=0 unsigned int x; x = d & 0x00FF ; PORTD &= ~x; DDRD &= ~x; // D0-7 x = (d >> 8) & 0x3F; PORTB &= ~x; DDRB &= ~x; // D8-13 x = a & 0x003F ; PORTC &= ~x; DDRC &= ~x; // A0-5 }