NOTE:
(Update: Now, if I'da just read Tahmid's intro from the start, as well as all the way through its first section, then I'da saved a LOT of time!)
Summary: Put this early-on in your code!
//Pins which are shared with Analog peripherals default to ANALOG by
//default... This causes all READS from PORTx to be 0
//Set ANSELx bits to 0 for PORTx reads to be valid!
//Below takes care of PORTA inputs, use ANSELB, etc. for PORTB...
ANSELA = 0x0000;
Frankly, the documentation is downright confusing at times. Somewhere I'm sure I read that the defaults result in the GPIO pins defaulting to inputs.
But, no... That's not enough... Because if you're *not* planning on using the ADC, you *still* need to look into it... Because later down-the-line it also says something like GPIO pins that are shared with analog peripherals default to ANALOG mode. Which, apparently, explicitly *disables* PORT [input] reads on those pins... So, even if you're *not* planning to use any analog stuff, and just want to read a pushbutton on a pin, you *still* need to acknowledge (and learn the intricate details regarding) the fact that the pin is shared with an analog peripheral... even though those analog peripherals default to OFF.
It took me two days to figure this one out.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.