I'm reading about the AVR microcontroller. In a chapter on I/O ports I've stumbled accross a concept that I have trouble understanding: the pull-up resistor.
Here is a quote from the textbook:
PORT register role in inputting data:
There is a pull-up resistor for each of the AVR pins. If we put s into bits of the PORTx register, the pull-up resistors are activated. In cases in which nothing is connected to the pin or the connected devices have high impedance, the resistor pulls up the pin. See figure 4-4. If we put 0s into the bits of the PORTx register, the pull-up resistor is inactive.
And the associated diagram:
Now, bear with me; it is my understanding that we control the data direction of the ports by writing 1s or 0s in the DDRx register. So if I want to read data from a port I clear the DDRx register (0s) and get my data from the PINx register. Conversely, if I want to write data I set the DDRx register (1s) and write to the PORTx register.
Okay? So the book gives assembly-code examples of how we activate the pull-up resistors of a port. We do this by writing to the PORTx register without setting the DDRx!
What is the function or desired effect of doing this? It is not clear to me, even after having read half of the book.