Pins with analog inputs are set to analog input mode by default. To read a digital input you must clear the corresponding ANSEL
or ANSELH
bit. RB0
is AN12
, so you need to clear ANS12
(bit 4 in ANSELH
).
Pins set to output mode are not affected by the analog input settings. However a read-modify-write operation may fail if it needs to know the pin state and the pin is set to analog input mode.