Sorry Bruce, I made both changes, and the results are the same. I get one long pulse on the LED, LED goes off until button is pressed, then short pulse and then off again. Next press of button does nothing.
Sorry Bruce, I made both changes, and the results are the same. I get one long pulse on the LED, LED goes off until button is pressed, then short pulse and then off again. Next press of button does nothing.
Strange. This works precisely as expected. No matter how many times I press/release the
switch.
10K pull-down to ground on GPIO.2 with switch pulling it to Vcc on press.Code:@ DEVICE MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF DEFINE OSCCAL_1K 1 CMCON = 7 TRISIO = %001100 OPTION_REG = %01000000 GPIO = 0 T1CON = 0 'GPIO.0 = 'GPIO.1 = LED HIGH OUT 'GPIO.2 = SWITCH HIGH INPUT 'GPIO.3 = MCLR TIED HIGH 'GPIO.4 = 'GPIO.5 = Main: HIGH GPIO.1 PAUSE 1000 LOW GPIO.1 INTCON.1 = 0 INTCON.4 = 1 FLAGS = 0 @ SLEEP @ NOP INTCON.1 = 0 HIGH GPIO.1 PAUSE 100 LOW GPIO.1 INTCON.1 = 0 INTCON.4 = 1 FLAGS = 0 @ SLEEP @ NOP HIGH GPIO.1 PAUSE 1000 GOTO Main END
Strange indeed. I programmed my part with your program using cut & paste, and my results are the same as they were, no second operation! It must be some sort of hardware anomaly. I will chase it with my scope later.
Try setting bit 7 in OPTION_REG to disable internal pull-ups. WPU powers-up with all internal
pull-ups enabled, and with OPTION_REG = %01000000 you'll have internal pull-ups ON.
I suspect it works on mine due to a slight difference in the internal pull-up. That should cure
it unless you have a problem with your switch circuit.
trying to use "temp = GPIO.2" without declaring the temp variable is probably your syntax error.
"temp var byte" (word whatever) near/at the beginning would solve that.
Thanks for your help, guys! OPTION_REG = %1100000 solves the problem. But why does it work the first time, and not the second time????
Sounds weird to me, have you tried using another chip, is it the same result too?
Bookmarks