Maker Pro
Maker Pro

dip switch read problem.

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
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?
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
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?
Sounds like a simple wiring problem.
Can you post a schematic and picture?
 

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
Sounds like a simple wiring problem.
Can you post a schematic and picture?

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)
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,726
Joined
Nov 17, 2011
Messages
13,726
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.
 

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
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.
here is the schematic i have the dip swich connected to four pull ups Photo 4-2-15 - 7 25 45 μ.μ..jpg
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
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)
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.
 

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
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.


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
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
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?
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
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
 

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
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?

yes i have the out put is 0 or +5
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

what you mean? this is all the code
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Oh, okay, and you are saying that switching the switch on RB7 does not change the output on RB0?

Edit:

my problem is that the 2 of the selection switch select only 2 from the four sounds that i have on the programm
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:

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
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
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
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Thanks, I missed that. I see nothing in the code that would cause that problem.

Bob
 

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
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
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)

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
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
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

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
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
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.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Yep, and for (; ; ) has null parameters and is an endless loop.

From your link:

Use as infinite loops[edit]
This C-style for loop is commonly the source of an infinite loop since the fundamental steps of iteration are completely in the control of the programmer. In fact, when infinite loops are intended, this type of for loop can be used (with empty expressions), such as:
for (; ; )
//loop body
This style is used instead of infinite while(1) loops to avoid a warning in Visual C++.[3]
Bob
 

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
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!!
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
No one expects the bad breadboard (nor the Spanish Inquisition).

Bob
 
Top