PDA

View Full Version : Rotary Hex Dip Switch Code???



dangill
- 13th March 2008, 07:30
Can someone give me an idea what the code should look like for reading this type of rotary dip switch. I've looked everywhere and can't find any examples in PBP. The tech. sheets with the switch isn't much help either. I'm using a 16f690 chip and the switch is connected to the 4 port B pins.

Thanks,

Dan

Kamikaze47
- 13th March 2008, 13:30
This is how I would do it:

- Connect the common (C) pin to +5v
- Connect the 4 other pins to PORTB.4-PORTB.7
- Use 10k resistors to pull each of those pins to ground.

Now all you have to do is this:

some_variable = ( PORTB & $F0 ) >> 4

now, some_variable should be equal to the position of your switch.