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

Thread Starter

bug13

Joined Feb 13, 2012
2,002
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

Rich (BB code):
#define INPUT_PORT PORTD
#define INPUT_DDR DDRD
#define INPUT_PIN PIND
#define INPUT_BIT PD0

INPUT_DDR &= ~(_BV(INPUT_BIT)); //set as input
INPUT_PORT |= _BV(INPUT_BIT); // turn on internal pull-up resistor for the switch
full code is attached
 

Attachments

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Lol thanks for your advice, I thought if I got the answer, then should not waste other peoples time :)
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
i disagree with @android.. you should post if you solve it.. but you should say what was wrong with it.
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)
 

@android

Joined Dec 15, 2011
178
i disagree with @android.. you should post if you solve it.. but you should say what was wrong with it.
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.
 
Top