no need to set port as input? and pull-up resistor question

Discussion in 'Embedded Systems and Microcontrollers' started by bug13, Apr 14, 2012.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Hi I am new to electronics and uC, here is a tutorial I came across and play around with the code, and I find out:


    • I don't have to set a port as input, and it can still act as an input port;
    • And there is no different if I turn on internal pull-up resistor or not, my program still function as normal

    My program is simply turn a LED on when button is pressed, and turn a LED off again when the button is pressed again, the program is running in a stk500.

    Can someone explains it please? :D

    Code ( (Unknown Language)):
    1. #define INPUT_PORT PORTD
    2. #define INPUT_DDR DDRD
    3. #define INPUT_PIN PIND
    4. #define INPUT_BIT PD0
    5.  
    6. INPUT_DDR &= ~(_BV(INPUT_BIT)); //set as input
    7. INPUT_PORT |= _BV(INPUT_BIT); // turn on internal pull-up resistor for the switch
    full code is attached
     
  2. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    never mind, I found out the answer already :)
     
  3. @android

    Member

    Dec 15, 2011
    178
    9
    Even-though you found the answer you should not have mentioned it. :p It had made your thread DEAD.
     
  4. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Lol thanks for your advice, I thought if I got the answer, then should not waste other peoples time :)
     
  5. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    i disagree with @android.. you should post if you solve it.. but you should say what was wrong with it.
     
  6. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    As request:

    • The pin I was using is set as input by default(AVR at90s8515)
    • There is an external pull up resistor connected to all led at my development board(stk500)
     
  7. MrChips

    Moderator

    Oct 2, 2009
    12,415
    3,354
    Remember that this forum is not just above solving your problem.
    You can contribute valuable community service by explaining how you solved your problem.
     
  8. @android

    Member

    Dec 15, 2011
    178
    9
    Yeah. Of course. He should've explained the cause. Firstly, I entered in this thread to answer it & then I saw him saying 'I found it'. So instead of answering the question I said that.
     
Loading...