1. Which input conditions cause the IF statement to evaluate as true? (some may be more than 1 input pin)
if ( (PINB & 0x20) != 0 ) EXAMPLE: PB5 = 1
if ( (PINC & 0x80) == 0 )
if ( (PIND & 0x01) != 0 )
if ( (PINB & 0x03) == 0 )
if ( (PINB & 0x06) == 4 )
Write a complete program (without Arduino commands) to toggle LED-PD6 if PB0 is pressed, and toggle LED-PD7 if PB1 is pressed.
Answer :-
if ( (PINB & 0x20) != 0 ) EXAMPLE: PB5 = 1, because 0x20 = 0010_0000 so PB5 must be 1, then only if condition will be true.
if ( (PINC & 0x80) == 0 ) , 0x80 = 1000_0000 so PC7 bit must be 0, then we will get AND operation result as zero. Hence if condition will be true.
if ( (PIND & 0x01) != 0 ), 0x01 = 0000_0001 so PD0 pin must be 1, then AND operation results as 1. Hence if condition will be true.
if ( (PINB & 0x03) == 0 ), 0x03 = 0000_0011 so PB0 and PB1 both should be 0 then AND operation results 0. Hence if condition will be true.
if ( (PINB & 0x06) == 4 ), 0x06 = 0000_0110 so PB1 must be 1 and PB2 must be 0 then AND operation will result 4. Hence if condition will be true.
Dear student, please make me clear about " Not Using Arduino Command". Is it not using arduino functions like "digitalRead() or digitalWrite()". You can comment on this. Thank You.
Get Answers For Free
Most questions answered within 1 hours.