ATtiny85 をマイクロコントローラとして使用しています。2 つの入力をそれぞれ約 3 V で読み取り、「オン」入力 (1 V 以上) ごとに 5 V を出力しようとしています。入力には PINB0 と PINB1 を使用し、出力には PINB3 と PINB4 を使用しています。問題は、PINB0 と PINB1 の両方がオンの場合、5 V の出力が 2 つ得られますが、一方のみがオンの場合、2 V しか得られないため、5 V の出力が得られるように修正しようとしています。
これが私のコードです:
#inlude <avr/io.h>
#include <stdint.h>
int main(void)
{
// set pin 0 to input (pi signal 0)
DDRB &= ~(1 << PINB0);
PORTB &= 0 << PINB0;
// set pin 1 to input (pi signal 1)
DDRB &= ~(1 << PINB1);
PORTB &= 0 << PINB1;
//set pin 3 to output of 0
DDRB |= 1 << PINB3;
PORTB &= 0 << PINB3;
//set pin 4 to output of 1
DDRB |= 1 << PINB4;
PORTB &= 0 << PINB4;
while (1)
{
if (bit_is_clear(PINB, 0) && bit_is_clear(PINB, 1))
{
PORTB &= 0 << PINB3; //output zero volts
PORTB &= 0 << PINB4; //output zero volts
}
else if (bit_is_clear(PINB, 0) && !(bit_is_clear(PINB, 1)))
{
PORTB &= 0 << PINB3; //output zero volts
PORTB |= 1 << PINB4; //output 5 volts
}
else if (!(bit_is_clear(PINB, 0)) && bit_is_clear(PINB, 1))
{
PORTB |= 1 << PINB3; //output 5 volts
PORTB &= 0 << PINB4; //output zero volts
}
else
{
PORTB |= 1 << PINB3; //output 5 volts
PORTB |= 1 << PINB4; //output 5 volts
}
}
}