Use a switch by change not on/off status.


Results 1 to 17 of 17

Threaded View

  1. #15
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Use a switch by change not on/off status.

    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.
    Code:
    @ __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
    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 operation
    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.

Similar Threads

  1. Toggle switch (latching switch) state
    By craigwb in forum General
    Replies: 4
    Last Post: - 6th November 2011, 14:18
  2. Switch sensor vs. switch PIC pin
    By fratello in forum Schematics
    Replies: 10
    Last Post: - 4th August 2011, 11:17
  3. Interrupt status?
    By circuitpro in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 28th February 2011, 01:27
  4. Replies: 6
    Last Post: - 9th January 2011, 15:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts