Using AVR Internal Pull up for push button controlling

Hello all,

I need to use internal pullup of an AVR mcu for controlling push buttons without using extra 10k resistors. In arduino, it can be easily used by setting pinMode(pinNumber, INPUT_PULLUP), but I need to implement this code in pure avr program. I've looked for a while and no luck.

Any useful links, comments, advice or codes will be greatly appreciated.

Note: I am using ATmega8A for the project, I also have an ATmega328P [SMD] Breakout with chip and an ATmega32A.

Thanks in advance.

Set bit in port register to 1 while ddr is set input

@DrAzzy, sorry for my ignorance. I did not understand your reply. Thanks for your response.

DrAzzy is saying that you have to manipulate the DDRx and PORTx port registers. The former sets ports as inputs (0) or outputs (1), while the latter controls logic levels for outputs and toggles the internal pull-up resistors for inputs (which are enabled when the relevant bit is 1).

Datasheet

Info, Section 13.2.1
Sample code, page 53.

Thanks a lot everyone. :smiley: