Set port status in start up code to " your safe off status" set interrupts off until pic is stable then enable interrupts. Whatever status toggle switch is in initally is irrelevant as changing it triggers the interrupt.
Set port status in start up code to " your safe off status" set interrupts off until pic is stable then enable interrupts. Whatever status toggle switch is in initally is irrelevant as changing it triggers the interrupt.
Just a thought. I did something like this for a LDR to act as a motion detector. It should work for a switch.
checkswitch var bit
compare var bit
clear 'bits are 0
low portb.0 'output pin off
start:
let checkswitch = porta.0 'toggle switch
pause 50
let compare = porta.0
if compare <> checkswitch then toggle portb.0 : clear: goto start
goto start
I have used the following on a few occasions quite successfully:
Lets say the switch is on portc.3
SW VAR PORTC.3
WHILE SW = 0 : WEND 'THIS WILL CONTINUALLY LOOP AS LONG AS THE INPUT IS LOW, MAKE IT SW = 1 TO DETECT
'GOING LOW.
' ASSUMES THAT ALL YOU ARE DOING IS WAITING FOR A SWITCH CHANGE
'ACCORDING TO THE MANUAL THIS LOOP CHECKS ABOUT 50 TIMES A SECOND
'SO IT SHOULD SEE THE CHANGE WITHIN 1/50 OF A SECOND.
DO SOMETHING HERE 'THIS IS WHAT YOU WANT TO DO AT THE SWITCH CHANGE
Last edited by muddy0409; - 22nd November 2014 at 12:16.
Peter Moritz.
Up the bush, Western Plains,
New South Wales,
Australia.
Ok, a JK FlipFlop is a 2 input one output device.
I am guessing you are using a latching relay which
changes states every time it is energised, is
this correct?
If so you need to read 2 pins to check switch state.
Tested with 16F690 demo board. Weak pullups did not work, had to use real resistors, likely because the PICKit2 was still connected. LEDs were enabled to verify operationCode:@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF DEFINE OSC 4 TrisA = %00000011 TRISC = %00000000 PortC = %00000000 ANSEL=0 ANSELH=0 ADCON0 = 0 ADCON1 = 0 Option_Reg = %00000000 ; enable RABPU WPUA = %00000011 ;Set RABPU Main: If PortA.0 = 0 then portc.2 = 1 pause 500 ; 1/2 seconds of power out portc.2 = 0 else goto main endif goto Impatient ; wait for microswitch to zero Impatient: while PortA.1 = 1 portc.3 = 1 pause 100 portc.3 = 0 pause 100 wend if PortA.1 = 0 then goto main end
Last edited by Archangel; - 23rd November 2014 at 11:43.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks