Hippogriff
Member
Hi all,
Earlier, I had asked about getting a potentiometer working with a PIC16F628a and JAL. I was told it was going to be difficult because the 16F628a doesn't have A to D capabilities, and I was advised to look at the 12F683. I am continuing to do that and have already ported my 16F628a code to the 12F683 successfully.
However, I also had a couple of DIP switches lying around and I thought it could be a good idea to try to use that and see if I could control some program settings from it via digital (on or off) inputs. I've seen a few schematics where the DIP switch input path is connected to +5V via a 10K Ohm resistor, before splitting off to a PIC pin set to read digital input, the other side of the switch goes to ground.
Is that how it must be? Because I set up the following very simple circuit and the LED lights up when I switch the first switch - so power is getting to the LED when I want it to, and not when I don't want it to. This all makes perfect sense to me, too - the LED lights up if it can be reached, but if it can't, it stays off.
**broken link removed**
So, next thought, can I employ the exact same principle with the PIC?
It seems not. When I code up the following very simple JAL program for the 16F628a, which sets pin 7 to be an input, pin 8 to blink an LED every two seconds and pin 9 to light an LED depending upon the switch position, I get some (what I consider) strange results.
I end up with the LED that I think is supposed to be controlled by the DIP switch being on all the time. The LED on pin 8 is blinking every two seconds (as I would expect) but it doesn't seem to matter whether the DIP switch position is up or down for the LED attached to pin 9 - the LED is always on.
**broken link removed**
But the circuit makes sense to me. +5V is going into the DIP switch - if the switch isn't connected then nothing reaches the input pin 7 of the 16F628a, thus (I think) it should read that as a LOW, FALSE or OFF. If the switch is connected, then I'd expect the PIC input pin 7 to read a HIGH, TRUE or ON. Instead, it always seems to be ON.
I think this is pretty basic stuff... and I'm missing something rather obvious, I think. But, as is often the case with these things, you just don't know what you don't know. Is anyone able to take a quick scan at these images and simply tell me - "you're not using the DIP switch in the right way"?
As always, guidance appreciated.
Earlier, I had asked about getting a potentiometer working with a PIC16F628a and JAL. I was told it was going to be difficult because the 16F628a doesn't have A to D capabilities, and I was advised to look at the 12F683. I am continuing to do that and have already ported my 16F628a code to the 12F683 successfully.
However, I also had a couple of DIP switches lying around and I thought it could be a good idea to try to use that and see if I could control some program settings from it via digital (on or off) inputs. I've seen a few schematics where the DIP switch input path is connected to +5V via a 10K Ohm resistor, before splitting off to a PIC pin set to read digital input, the other side of the switch goes to ground.
Is that how it must be? Because I set up the following very simple circuit and the LED lights up when I switch the first switch - so power is getting to the LED when I want it to, and not when I don't want it to. This all makes perfect sense to me, too - the LED lights up if it can be reached, but if it can't, it stays off.
**broken link removed**
So, next thought, can I employ the exact same principle with the PIC?
It seems not. When I code up the following very simple JAL program for the 16F628a, which sets pin 7 to be an input, pin 8 to blink an LED every two seconds and pin 9 to light an LED depending upon the switch position, I get some (what I consider) strange results.
Code:
pin_B1_direction = input -- Pin RB1, Pin 7 (DIP 1)
pin_B2_direction = output -- Pin RB2, Pin 8 (Blue LED)
pin_B3_direction = output -- Pin RB3, Pin 9 (Blue LED)
alias DIP is pin_B1
alias LED1 is pin_B2
alias LED2 is pin_B3
forever loop
LED1 = off
LED2 = DIP
_usec_delay (2000000)
LED1 = on
LED2 = DIP
_usec_delay (2000000)
end loop
I end up with the LED that I think is supposed to be controlled by the DIP switch being on all the time. The LED on pin 8 is blinking every two seconds (as I would expect) but it doesn't seem to matter whether the DIP switch position is up or down for the LED attached to pin 9 - the LED is always on.
**broken link removed**
But the circuit makes sense to me. +5V is going into the DIP switch - if the switch isn't connected then nothing reaches the input pin 7 of the 16F628a, thus (I think) it should read that as a LOW, FALSE or OFF. If the switch is connected, then I'd expect the PIC input pin 7 to read a HIGH, TRUE or ON. Instead, it always seems to be ON.
I think this is pretty basic stuff... and I'm missing something rather obvious, I think. But, as is often the case with these things, you just don't know what you don't know. Is anyone able to take a quick scan at these images and simply tell me - "you're not using the DIP switch in the right way"?
As always, guidance appreciated.