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.

Basic Electronics » Two Wrongs Make it Right

March 16, 2013
by therealmitchconnors
therealmitchconnors's Avatar

I have a background in computer programming and found the nerdkit tutorials to be a bit slow after the tempsensor one, as they focused on very basic programming concepts. So, I decided to write my own combo program with dip switch math, the temp sensor, and led to prove to myself that I got the concepts before moving to something more advanced. Along the way I made two critical mistakes, but then found that my program worked anyways. Can anyone tell me why? Here are my mistakes:

First, instead of setting DDRC & DDRB pins to 0 for input (for reading the dip switches), I set them to output (1).

Second , instead of wiring the dip switches to GND, I wired them to +5V. (not on purpose)

I then proceeded to read from PINC & PINB and my program worked as expected... what is going on? How can I read from PINC and PINB reliably when DDR for those pins is 1? Is there any risk to my board in keeping it this way?


March 16, 2013
by Noter
Noter's Avatar

Sure you can read the state when the pin is configured for output but you should already know the state in that case. I suppose you could overpower the output driver and force the pin polarity opposite it's output setting but that probably draws a lot of current and could damage the port so definitely don't leave it that way.

May 22, 2013
by meltbox360
meltbox360's Avatar

I just made one of my microcontrollers pop by setting it to output on accident and having no resistor between the pin and ground. Don't program when your tired and avoid using &= when you should use == because the pin state does change and it makes you unhappy. Alternatively always place a lowish value resistor between the pin and ground and insure yourself for when you make a mistake like that.

Post a Reply

Please log in to post a reply.

Did you know that you can build a circuit to convert the "dit" and "dah" of Morse code back into letters automatically? Learn more...