NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Activating Pull-up Resistor on ATMega I/O Port

September 11, 2012
by jlaskowski
jlaskowski's Avatar

According to the ATMega doc, "If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated."

There is nothing currently connected to PC2, and when I run this code, it shows PC2 as high. When I take out the line that activates the pull-up resistor, it shows PC2 as low.

    // configure Port C2 as input
    DDRC &= ~(1<<DDC2);

    // activate the pull-up resistor on Port C2
    PORTC |= (1<<PC2);

    unsigned char pc2_value = PORTC & (1<<PC2);
    if (pc2_value > 0) {
        turn_on_green();
    } else {
        turn_on_yellow();
    }
Shouldn't it always be low once it is configured as an input pin until it's external connection pulls it high?
September 11, 2012
by jlaskowski
jlaskowski's Avatar

Never mind. I realize now that it's the job of the pull up resistor to pull the voltage up to 1 when it's connected to nothing.

Post a Reply

Please log in to post a reply.

Did you know that reading a double floating point variable with scanf requires "%lf" for "long float"? Learn more...