Help with Maxim Ibutton "IF THEN ELSE" statements please


Closed Thread
Results 1 to 39 of 39

Hybrid View

  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Unhappy Help with Maxim Ibutton "IF THEN ELSE" statements please

    Hi thanks for reading this...

    Am attempting to sort out some Ibutton DS1990 security code.... I have this:-

    OWOUT iButton,1,[$33]
    PAUSE 100
    OWIN iButton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]]

    IF Serial[1]=$15 AND Serial[2]=$D3 AND Serial[3]=$7D AND Serial[4]=$16 AND Serial[5]=$00 AND Serial[6]=$00THEN correct1
    IF Serial[1]=$68 AND Serial[2]=$36 AND Serial[3]=$4F AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00THEN correct2
    IF Serial[1]=$1E AND Serial[2]=$1A AND Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00THEN correct3
    'else gosub wrong
    'endif
    GOTO mainloop

    This works fine for the correct1,correct2, and correct3 labels.....

    What I am attempting to do is; If the code doesn't see one of the three detailed Ibuttons it runs error label "wrong"


    I know it must be easy (should be) but not seeing it !

    My Picbasic 2.50C

    Help welcome.......Please. !!!

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Quote Originally Posted by andybarrett1 View Post
    Hi thanks for reading this...

    Am attempting to sort out some Ibutton DS1990 security code.... I have this:-

    OWOUT iButton,1,[$33]
    PAUSE 100
    OWIN iButton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]]

    IF Serial[1]=$15 AND Serial[2]=$D3 AND Serial[3]=$7D AND Serial[4]=$16 AND Serial[5]=$00 AND Serial[6]=$00THEN correct1
    IF Serial[1]=$68 AND Serial[2]=$36 AND Serial[3]=$4F AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00THEN correct2
    IF Serial[1]=$1E AND Serial[2]=$1A AND Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00THEN correct3
    'else gosub wrong
    'endif
    GOTO mainloop

    This works fine for the correct1,correct2, and correct3 labels.....

    What I am attempting to do is; If the code doesn't see one of the three detailed Ibuttons it runs error label "wrong"


    I know it must be easy (should be) but not seeing it !

    My Picbasic 2.50C

    Help welcome.......Please. !!!
    Your if correct then labels construction can not be in one line format.

    so for example

    IF Serial[1]=$15 AND Serial[2]=$D3 AND Serial[3]=$7D AND Serial[4]=$16 AND Serial[5]=$00 AND Serial[6]=$00THEN
    correct1
    else
    gosub wrong
    endif

    Obviously you need to allow for the three "correct" options.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Hi,
    Since your IF-THEN statements are actually GOTOs (if evaluated true) all you need to do is add GOSUB (or GOTO) WRONG after the three IF statements.
    Code:
    IF Serial[1]=$15 AND Serial[2]=$D3 AND Serial[3]=$7D AND Serial[4]=$16 AND Serial[5]=$00 AND Serial[6]=$00 THEN correct1    '<----This will GOTO correct1
    IF Serial[1]=$68 AND Serial[2]=$36 AND Serial[3]=$4F AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 THEN correct2
    IF Serial[1]=$1E AND Serial[2]=$1A AND Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 THEN correct3
    GOSUB WRONG
    GOTO mainloop
    Now the WRONG subroutine will only execute if none of the three IF statements evalutate true.

    /Henrik.

  4. #4
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Henrik

    You mean :-

    Now the WRONG subroutine will only execute if none of the three IF statements evalutate FALSE.

    Not near the units so cant try at moment !

    Thank you for reading

  5. #5
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Quote Originally Posted by andybarrett1 View Post
    Henrik

    You mean :-

    Now the WRONG subroutine will only execute if none of the three IF statements evalutate FALSE.

    Not near the units so cant try at moment !

    Thank you for reading
    No he means:-

    Now the WRONG subroutine will only execute if ALL of the three IF statements evalutate FALSE.
    Last edited by EarlyBird2; - 8th May 2014 at 09:31.

  6. #6
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Quote Originally Posted by EarlyBird2 View Post
    No he means:-

    Now the WRONG subroutine will only execute if ALL of the three IF statements evalutate FALSE.
    So its like a :-

    IF NOT THEN

    Sorry for being so dim.....Thank you for help !

  7. #7
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Not what was meant.

    All you need to do is change this

    else gosub wrong
    endif

    to this

    gosub wrong

    in your code

  8. #8
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Henrik,

    That is neat! Although I do not like using goto statements as they can make the program logic difficult to follow.

  9. #9
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    All good....

    Will try later and advise

    Thank you for help.....

    In Sunny Scunthorpe on Monday/Tuesday

    Wonderful BOS Plant at Tata !!!

  10. #10
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Code
    mainloop: Owout ibutton,1,[$33]
    pause 100
    owin ibutton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]]

    If Serial[1]=$15 and Serial[2]=$D3 and Serial[3]=$7D AND Serial[4]=$16 AND Serial[5]=$00 AND Serial[6]=$00 then correct1
    If Serial[1]=$68 and Serial[2]=$36 and Serial[3]=$4F AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then correct2
    If Serial[1]=$1E and Serial[2]=$1A and Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then correct3
    If Serial[1]=$F0 and Serial[2]=$66 and Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then nocache
    gosub wrong
    Goto mainloop
    Hi all...

    Tried the above and variants of it....It is now just going staight to the gosub routine (wrong) I suspect because with no Ibutton in place the "Serial Number" is after all wrong!!

    Help........!!!!
    Last edited by andybarrett1; - 8th May 2014 at 20:24. Reason: Typo

  11. #11
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Steve

    Could this be the Presence Pulse.. It mentions this in the Datasheet but no command. I Know the 1990R has it the 1990A has not .... I am using a "R"

    Read Rom [33h] or [0Fh]
    Search [F0h]
    Match [55h]
    Skip [CCh]

    Presence [??h]

    Searching around on a phone internet at moment so limited on resources!

    BR
    Andy

  12. #12
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Could you use the value in S0 as a check. What value does it have with no button and what value with a button? There is also S7 CRC value that could be used in the same way.

    You may need to reset S0 on each loop say to $0 then run owout owin and test the new value.

    Just ideas nothing is tested

  13. #13
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Update:-

    Just found this thread from a whilst back....

    http://www.picbasic.co.uk/forum/showthread.php?t=9375

    Seems am not the only one with these issues !

  14. #14
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Brilliant there is you answer thanks to Darrel.

    Start:
    OWOUT IBUTTON, 1, [$33], start ; Detect if OW device is present
    .
    .
    .

  15. #15
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    mainloop:
    Start:
    OWOUT IBUTTON, 1, [$33], start ; Detect if OW device is present
    Owout ibutton,1,[$33]
    pause 100
    owin ibutton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]]
    Edited this from phone so might be dodgy..... Maybe the solution ?

  16. #16
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Code

    mainloop:
    High led
    pause 250
    low led
    pause 250

    Owout ibutton,1,[$33],mainloop
    pause 100
    owin ibutton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]]
    'If Serial[1]=$15 and Serial[2]=$D3 and Serial[3]=$7D AND Serial[4]=$16 AND Serial[5]=$00 AND Serial[6]=$00 then correct1
    'If Serial[1]=$68 and Serial[2]=$36 and Serial[3]=$4F AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then correct2
    'If Serial[1]=$1E and Serial[2]=$1A and Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then correct3
    'If Serial[1]=$F0 and Serial[2]=$66 and Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then nocache
    If Serial[7]=$E6 then correct1
    If Serial[7]=$90 then nocorrect
    gosub wrong
    Goto mainloop
    We seem to be getting there.... My issue now has changed, I suspect a timing issue.

    It loves the "wrong" gosub...if I hold the button on the contacts all good but the slightest slip and I am in the wrong gosub!

    I have tried just minimising the code to the CRC of the serial and using that but the same results... putting delays in not helping...

    I am hoping it is not the debounce on the contacts.... though we could fix that ??

    Any Ideas anyone

    Thank you ...Andy

  17. #17
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Change this

    Owout ibutton,1,[$33],mainloop
    pause 100
    owin ibutton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]]

    to this

    Owout ibutton,1,[$33]
    owin ibutton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]],mainloop

    or this

    Owout ibutton,1,[$33],mainloop
    owin ibutton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]],mainloop

  18. #18
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    I am curious as to how many ibuttons and "doors" you expect to have in your system.

    I have developed an entry system in the past which had many entry points and swipe cards. Hard coding the serial numbers into the program is not the way to go, for all but the smallest systems.

  19. #19
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Thumbs up Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    Quote Originally Posted by EarlyBird2 View Post
    I am curious as to how many ibuttons and "doors" you expect to have in your system.

    I have developed an entry system in the past which had many entry points and swipe cards. Hard coding the serial numbers into the program is not the way to go, for all but the smallest systems.
    Only three Buttons (One Door or in this case Gate)

    The data sheet suggests the pause 100… So that good.
    Have already tried the mainloop label on the Owin as well as the Owout !! (I did read the manual…again!)

    Also seems to be no difference in operation between DS1990R device and DS1990A Device…. The "R" has the Presence…. But Datasheets are sparse !!!

    I am still pondering over timing issues…..I know hardcoding serial numbers is not ideal but it is only small ,,
    Having said that I just made the change from 1k to 2k memory..627 to 628 !

    Also wondering "IF" I can shorten the VAR ARRAYS any!

    Learning a lot here ….. Thank you!

  20. #20
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with Maxim Ibutton "IF THEN ELSE" statements please

    You could set up a retry loop.

    mainloop:
    High led
    pause 250
    low led
    pause 250

    for I=1 to 5 'or anything you like
    Owout ibutton,1,[$33],mainloop
    pause 100
    owin ibutton,0,[Serial[0],Serial[1],Serial[2],Serial[3],Serial[4],Serial[5],Serial[6],Serial[7]]
    If Serial[1]=$15 and Serial[2]=$D3 and Serial[3]=$7D AND Serial[4]=$16 AND Serial[5]=$00 AND Serial[6]=$00 then correct1
    If Serial[1]=$68 and Serial[2]=$36 and Serial[3]=$4F AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then correct2
    If Serial[1]=$1E and Serial[2]=$1A and Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then correct3
    Next i
    'If Serial[1]=$F0 and Serial[2]=$66 and Serial[3]=$2C AND Serial[4]=$17 AND Serial[5]=$00 AND Serial[6]=$00 then nocache
    gosub wrong
    Goto mainloop

    change the value of I to test for optimum performance.

Similar Threads

  1. Replies: 0
    Last Post: - 14th November 2013, 03:32
  2. Replies: 3
    Last Post: - 15th October 2012, 08:06
  3. Replies: 8
    Last Post: - 3rd March 2011, 22:20
  4. Replies: 5
    Last Post: - 28th February 2011, 15:33
  5. Replies: 1
    Last Post: - 16th February 2005, 20:05

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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