Connect with us

dip switch read problem.

Discussion in 'Microcontrollers, Programming and IoT' started by gatoulisss, Feb 4, 2015.

Scroll to continue with content
  1. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015
    hello guys!
    i have this problem... im using 4way dip switch connected to my pic16f88 RB4-RB7 ports... 2 of the swich selecting a sound so i have four sound to select and the other 2 are just on-off switch.
    my problem is that the 2 of the selection switch select only 2 from the four sounds that i have on the programm. im using the proteus as simulation and there everything is ok but in the reallity i have this problem.
    any ideas?
     
  2. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    Sounds like a simple wiring problem.
    Can you post a schematic and picture?
     
    Harald Kapp likes this.
  3. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015
    actually i test the dip switch as on/off... something else is not ok... RB5-RB6 works ok, RB4-RB7 is only ON no mater what i choose on the switch... (i test 3 different dipswitch so is not there the problem also i change and the microcontroller and still the same problem)
     
  4. Harald Kapp

    Harald Kapp Moderator Moderator

    9,637
    2,013
    Nov 17, 2011
    We need to see a diagram of your circuit to evaluate possible problems. As gryd3 asked: show us your circuit diagram. Otherwise we can only wildly guess.
     
  5. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015
    here is the schematic i have the dip swich connected to four pull ups Photo 4-2-15 - 7 25 45 μ.μ..jpg
     
  6. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    This comment and your schematic... Are you sure you correctly programmed RB4-RB7 as inputs?
    Is your microcontroller in a socket? Can it be unplugged?
    You should remove the microcontroller and test the output at the dip switch.
    It could be the MCU holding the pin high, or it could be a poor 'ground' on the dip switch.
     
    KrisBlueNZ likes this.
  7. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015

    here is my connections in the foto and this is my code below


    void main() {
    osccon=0x60;
    ansel=0;
    trisb4_bit=1;
    trisb5_bit=1;
    trisb6_bit=1;
    trisb7_bit=1;
    trisb0_bit=0;
    for (;; ) {
    if (porta.f7==0) { // i change the port here to test what port i want here is the RB7 testing
    portb.f0=1; }
    else {portb.f0=0;}




    }
    }

    i have tryied with other led other dip switch and other microcontroller still same problem.
    Photo 4-2-15 - 7 44 57 μ.μ..jpg
     
  8. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    Thank you for the code snippet, I cannot currently verify it though, It's been far too long since I've programmed PIC.

    Have you tried removing the microcontroller and measuring the output of the dip switch where the microcontroller used to be with a multi-meter?
     
  9. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    The wiring an code both look correct. I suspect your problem is with the rest of the code that you have not shown us.

    Bob
     
  10. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015
    yes i have the out put is 0 or +5
    what you mean? this is all the code
     
  11. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    Oh, okay, and you are saying that switching the switch on RB7 does not change the output on RB0?

    Edit:

    I don't see anything in the posted code that has to do with selecting of of 4 sounds, but this is how you described the problem.

    Please elaborate on how the posted code is failing.

    Bob
     
    Last edited: Feb 4, 2015
  12. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    RB4 and RB7 are being held high... If you have removed the microcontroller and tested the RB4-7 successfully, then it's safe to say the rest of hardware seems to be working correctly.
    At this point, troubleshoot the microcontroller. Make a new very basic program to test if the PIC is correctly reading RB-4-7
     
  13. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    Thanks, I missed that. I see nothing in the code that would cause that problem.

    Bob
     
  14. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015
    i change the main problem by answering this.... that my problem is that the dip switch is not working correctly and thats why i cant choose the sound
     
  15. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    If you have measured high on the pin with the dip switch pulling it to ground, there is something wrong with the dip switch. The output of the PIC cannot possibly pull up a switch to ground.

    Bob
     
    Gryd3 likes this.
  16. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    I never directly asked if the PIC is merely 'reading' RB4 and RB7 as being high... or if the line is actually being held high...
    However, the op has stated that with the PIC removed, the output from the dip switch does indeed toggle from 1 to 0.
    So that would suggest to me that the PIC is damaged, or there is something in the code that is preventing RB4, and RB7 from correctly being inputs, or correctly reading the value... this is why I suggested writing a new program specifically for testing the circuit.
     
  17. Bluejets

    Bluejets

    3,764
    781
    Oct 5, 2014
  18. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    Yep, and for (; ; ) has null parameters and is an endless loop.

    From your link:

    Bob
     
    Bluejets likes this.
  19. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015
    finally i found what was wrong... 90% the breadbord was damaged in that poion... i dissasembe and assemble the circuit again in other position and everything work now. thanks a lot for your help!!
     
    davenn and Gryd3 like this.
  20. BobK

    BobK

    7,673
    1,684
    Jan 5, 2010
    No one expects the bad breadboard (nor the Spanish Inquisition).

    Bob
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-