NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Need help, is there a problem with my DIP switch?
July 15, 2012 by TheFed |
So i finished my dip_arithmetic project and decided to expand it a little to try out my new-found knowledge of electronics. Here's my idea: I decided that i would try represent each digit from one number with LED's (the binary ones, so like 101 would be: red-LEDoff-green), and then use the DIP switch to alternate between the two different numbers (the ones you add up). Here's what I did: So I attached a LED into PB1, PB2 and PB3 Then i wired my DIP switch (which has 8 switches instead of 6, like in the manual) so that additionally to: DP1 -> MCU pin 23 DP2 -> MCU pin 24 DP3 -> MCU pin 25 DP4 -> MCU pin 26 DP5 -> MCU pin 27 DP6 -> MCU pin 28 I had DP7 -> MCU pin 18 and of course wired it to the GND Here's my code, and its the first C code i've written by myself so there's bound to be some awefull mistakes. =============================================================================
============================================================================= So, thats it. Now what happens to me is that when i change from one number to the other, the LED change too, but then after a while they change back and then back again and so forth. Also if i push on the DIP switch it tends to work properly. I have rewritten my code and tried different approaches but the same thing keeps happening. So is my DIP switch partly broken or have i made some mistake in the code or in my circuit? (1 through 6 work fine). |
---|---|
July 15, 2012 by TheFed |
Im going away for a week, so i cant answer any questions then... |
July 15, 2012 by TheFed |
But please do post them! |
July 15, 2012 by pcbolt |
Hi Fedde - Try enabling the pull-up resistor on PB4.
|
July 15, 2012 by TheFed |
Im sorry that i double posted this thread, will not do so in the future. And thanks pcbolt i cant believed i mist something like that. It works great now! |
Please log in to post a reply.
Did you know that the microcontroller's crystal oscillator can be used to keep accurate time? Learn more...
|