Newbie - 16F628A and switch latching


Closed Thread
Results 1 to 40 of 46

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Wrong scenario ...

    Hi, Malc

    as SWset5 is tested AFTER the swset1 ... your condition never can happend, or during so little time, it can't work properly.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    So are you saying its the logic of PBP or my program logic that's not right

    I modified the code to add in a new var for LED3 to test for the condition "swset1=1 and swset2=1 then swset5=1 and it didn't work either

    Code:
    If swset1=1 and swset2=1 then
    swset5=1
    else 
    swset5=0
    endif
    if swset5=1 then
    high led3
    
    endif
    When swset1=1 and LED1 is lit, and swset2=1 and LED2 is lit, LED3 fails to light, ergo swset5 can't =1

    So any ideas on how to do what I want it to do ??

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Talking PbP is right

    YOUR Logic is wrong ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    You ain't going to make this easy for me are you !

    A hint in the right direction would help !!

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    OK following your advice I RTFM and it states

    If (B0 = 10) And (B1 = 20) Then loop
    So I applied the same logic to the code

    If swset1=1 and swset2=1 then occ
    occ:
    high led3
    ie if swset1 and swset2 both =1 then jump to occ, occ simply turns on LED3

    This didn't work. It seems that its ignoring the "and" part of the statement

    I mean this ain't exactly rocket (or should I say space shuttle ) science

  6. #6
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c
    It seems that its ignoring the "and" part of the statement
    Perhaps because you ignored the parentheses?

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink the last ...

    Hi, Malc

    try this:

    CMCON=7
    TRISB=%00000011 'set RB0 & 1 as input and the rest output

    SW1 var PORTB.0 'switch input pin 6 (RB0)
    SW2 var PORTB.1 'switch input pin 7 (RB1)


    LED1 var PORTB.4 'LED1 on pin 10 (RB4)
    LED2 var PORTB.5 'LED1 on pin 11 (RB5)

    Swset1 var bit
    Swset2 var bit

    Swset5 var bit


    low led1
    low led2

    Swset1=0
    Swset2=0

    swset5=0 'Var swset is set low

    Main:

    if SW1=0 then
    'If switch is LOW (Grounded) then

    IF swset5 =1 THEN

    swset1 = 0
    swset2 = 0
    swset5 = 0

    loop: IF sw1=0 then loop 'wait for button release ... Yessss !!!

    GOTO jump

    ENDIF

    Toggle Swset1 'change swset1 from 0 to 1
    pause 500 'debounce delay
    endif


    if SW2=0 then 'If switch is LOW (Grounded) then
    Toggle Swset2 'change swset2 from 0 to 1
    pause 500 'debounce delay
    endif

    Jump:

    If Swset1=1 then 'if swset1 is 1
    high led1 'then turn on RB4 (and hence the LED)
    else
    low led1 'else, LED is off
    endif

    If Swset2=1 then 'if swset2 is 1
    high led2 'then turn on RB5 (and hence the LED)
    else
    low led2 'else, LED is off
    endif

    If swset1=1 and swset2=1 then
    toggle swset5
    endif

    Goto Main
    End

    And now try to understand WHY !!!

    Alain
    Last edited by Acetronics2; - 15th May 2006 at 15:36.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  2. Addressing with Dip Switch or ???
    By tazntex in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th September 2008, 12:19
  3. 16f628a wont wake up
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th August 2008, 14:22
  4. SLEEP mode 16F628A
    By Michael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th April 2006, 17:26
  5. 16F628A using PORTA.4, and it works, but...
    By zx81 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th August 2005, 08:45

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