Combinaton Gate access


Closed Thread
Results 1 to 40 of 48

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    could be replace by the single line bellow.
    Code:
    LOOKUP ByteA,[0,1,2,3,"A",4,5,6,"B",7,8,9,"C","*",0,"#","D"],ByteA
    Or store the table in the EEPROM, then read from it..
    Code:
    DATA @1,1,2,3,"A",4,5,6,"B",7,8,9,"C","*",0,"#","D"
    '
    '
    '
    '
    '
    Read ByteA, ByteA
    ALLRIGHTY THEN,
    Hi Steve, Darrel and all,
    For starters . . . Lookup table listed will do the kepad remapping of my long and convouluted code? Cool, I must learn more about this, also how to set up eprom, as I have never figured that out.
    Darrel, you said my code never went to gosub, . . . the if bytea != 0 then gosub combo, will not do it?
    before you and Steve posted, but after skimask did I wrote the following
    Code:
    @MyConfig = _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF 
    @MyConfig = MyConfig & _BODEN_OFF 
    @ __config  MyConfig
    '@ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON  & _LVP_OFF & _CP_OFF
    Define PIC16F877A
    @ errorlevel -230
    CMCON  = 7  
    ADCON1 = 7 
    define OSC 20
    TrisD = %00000000
    
    DEFINE LCD_DREG PORTA
        DEFINE LCD_DBIT 0
        DEFINE LCD_RSREG PORTA
        DEFINE LCD_RSBIT 5
        DEFINE LCD_EREG PORTA
        DEFINE LCD_EBIT 4
        DEFINE LCD_BITS 4
        DEFINE LCD_LINES 4
    
        include "keypad.bas"
    pause 1000
    lcdout 254,1
    lcdout 254,128,"PIC Self Test"
    pause 1000
        
        DEFINE KEYPAD_ROW        4        ' 4 ROW keypad       
        DEFINE KEYPAD_ROW_PORT   PORTB    ' ROW port = PORTB
        DEFINE KEYPAD_ROW_BIT    4        ' ROW0 = PORTB.4
        DEFINE KEYPAD_COL        4        ' 3 COL keypad
        DEFINE KEYPAD_COL_PORT   PORTB    ' COL port = PORTB
        DEFINE KEYPAD_COL_BIT    0        ' COL0 = PORTB.1
        DEFINE KEYPAD_DEBOUNCEMS 50       ' debounce delay = 50 mSec
        DEFINE SCAN_ONCE         1
    
        OPTION_REG.7 = 0        ' Enable internal crap pull-up :D
    
        PORTB = 0             '  
        TRISB = %11110000     '
        Flags = 0  
        ByteA var byte         '
        Combocount var byte 
            INTCON = %10001000    ' Enable global interrupt
                              ' Enable interrupt on PORTB change
        on interrupt goto KeypadInt
        CLEAR
    lcdout 254,128," Initializing"
    LCDOUT 254,192,"System"
    pause 1000
    Portd.2 = 0
    combocount = 0
    
    Init:    
        lcdout $FE,1
        LCDOUT 254,128,"AUTHORIZATION"
        LCDOUT 254,192,"REQUIRED TO OPEN"
        LCDOUT 254,153,"THIS GATE"
        LCDOUT 254,212,"KEY ENTRY CODE"
     disable
    KeypadINT:    
    @ READKEYPAD _ByteA
        TRISB=%11110000
        PORTB=0
        INTCON.0=0
        resume
    enable   
        
        
    Start:
        if ByteA then
        If ByteA = 4  then ByteA = "A"
        if ByteA = 5  then ByteA = 4
        if ByteA = 6  then ByteA = 5
        if ByteA = 7  then ByteA = 6
        if ByteA = 8  then ByteA = "B"
        if ByteA = 9  then ByteA = 7
        if ByteA = 10 then ByteA = 8
        if ByteA = 11 then ByteA = 9
        if ByteA = 12 then ByteA = "C"
        if ByteA = 13 then ByteA = "*"
        if ByteA = 14 then ByteA = 0
        if ByteA = 15 then ByteA = "#"
        if ByteA = 16 then ByteA = "D"
        if ByteA != 0 then  gosub combo
            
            ByteA = 0
            pause 1000
            goto init
            'else
               
    else   
    endif
    goto start
    
             
    
    
    combo:
    LCDOUT $FE,1,"Key=",dec ByteA
    if ((ByteA = 7) and (combocount = 0)) then
    combocount = %00000001
    pause 1000
    else
    combocount = 0
    endif
    if ((ByteA = 8) and (combocount = %00000001)) then
     combocount = %00000011
    pause 1000
    else
    combocount = 0
    endif
    if ((ByteA = 65) and (combocount = %00000011)) then
    combocount = %00000111
    pause 1000
    else
    combocount = 0
    endif
    if ((ByteA = 5) and (combocount = %00000111)) then  
    combocount = %000011111
    pause 1000
    else
    combocount = 0
    endif
    if ((ByteA =68) and (combocount = %00001111)) then  
    combocount = %00011111
    pause 1000
    else
    combocount = 0
    endif
    if combocount = %00011111 then  PortD.2 = 1
    lcdout 254,1
    pause 10 
    lcdout 254,128,"Gate Opening" : pause 30000
    lcdout 254,1
    pause 10
    lcdout 254,192,"Gate Closing" : pause 30000 : ByteA = 0 : combocount = 0
    lcdout 254,1
    PortD.2 = 0
    'endif
    goto init ' Combination 78A5D
    
    
    end
    and it opened the gate with the push of any button, well almost, really it lied and said the gate was opening, and I have not had time to redress this issue.
    I even played with another asm. code file emailed to me, that was fun learning how to use mpasm in windows, and editing the asm file without actual Knowledge of assembly, but I got it to compile and, you guessed it, it didn't work as expected either, just outputted a few strings all over the lcd. So here i am looking at the examples you and Steve have provided, thinking I will figure this out, likely not today
    JS
    edit1:Well I haven't learned all the lessons here, but the code works really well, Thanks!
    edit2:Wow now I see how eprom works! Thanks again Darrel!
    edit3: Thanks Steve for lookup table, now that makes sense too!
    Just modified code to work as alarm console too, cool!
    Last edited by Archangel; - 12th February 2007 at 11:05.
    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.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Darrel, you said my code never went to gosub, . . . the if bytea != 0 then gosub combo, will not do it?
    In the first post, that IF statement was After a GOTO statement. So it never gets executed. I see you've moved it in the latest version. But the rest ruined it.

    I had actually addressed this problem earlier, then realized I was answering skimasks post instead of the original one. I guess I get to say it again.

    First off, when you see a whole buch of IF statements one after the other, each one trying to catch a certain set of circumstances, it's probably the wrong way to do it. And this one is a prime example.

    Let's say that the first keypress is a seven. The first IF statement works fine.
    Code:
    if ((ByteA = 7) and (combocount = 0)) then
        combocount = %00000001
        pause 1000
    else
        combocount = 0
    endif
    It recognizes the first digit of the combination, and sets combocount to 1

    Then it continues on to the next IF statement...
    Code:
    if ((ByteA = 8) and (combocount = %00000001)) then
        combocount = %00000011
        pause 1000
    else
        combocount = 0
    endif
    At this point ByteA does not equal 8 (it's still 7), so it goes to the ELSE clause where it zero's combocount and starts everything from scratch again. It'll never recognize more than 1 digit.

    Then after all the IF's are done, there's nothing to stop it from opening the gate, even though it only received 1 keypress.

    But from the sound of it, it did exactly what you told it to.
    <br>
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hello Joe,

    It already works your I code?.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    @ Joe,

    in your previous example, you should move your ISR or jump over
    Code:
    Init:    
        lcdout $FE,1
        LCDOUT 254,128,"AUTHORIZATION"
        LCDOUT 254,192,"REQUIRED TO OPEN"
        LCDOUT 254,153,"THIS GATE"
        LCDOUT 254,212,"KEY ENTRY CODE"
    
        '    ----> goto start:
     disable
    KeypadINT:    
    @ READKEYPAD _ByteA
        TRISB=%11110000
        PORTB=0
        INTCON.0=0
        resume
    enable   
    Start:
    What happen here is that it meet a RESUME, which do something close to a RETURN. Having nothing is the stack, it jump somewhere you don't know and execute the code at the top again and again... and again...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Leonardo, sorry i don't have Proteus, will be faster if you tell me wich PIC and how your keypad is attach to it.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    @ Joe,

    in your previous example, you should move your ISR or jump over
    [code]
    Dough! . . . thanks Steve that does make sense. This project has been hugely successful, not only do I have working code now but more importantly I have learned enough to keep me busy understanding what I learned for weeks!
    THANKS GUYS !
    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.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    sweet!

    Pump up the volume...

    <embed src="http://www.mister-e.org/Wav/yehaw.wav" autostart=false loop=false>
    Last edited by mister_e; - 12th February 2007 at 21:33.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Then it continues on to the next IF statement...
    Code:
    if ((ByteA = 8) and (combocount = %00000001)) then
        combocount = %00000011
        pause 1000
    else
        combocount = 0
    endif
    At this point<b> ByteA does not equal 8 (it's still 7), so it goes to the ELSE clause where it zero's combocount and starts everything from scratch again.</b> It'll never recognize more than 1 digit.
    <b>
    Then after all the IF's are done, there's nothing to stop it from opening the gate, even though it only received 1 keypress.
    </b>

    But from the sound of it, it did exactly what you told it to.
    <br>
    Is that because it has not gone back to the scan routine? Should I have used goto and resume or just put return after each if...then statement? I ask this <b>not </b>ignoring your statement I should not have done it this way in the first place.<br>
    <b> Could you explain in more detail as to why? How does combocount get to the correct status to open the gate?</b>
    <b>I really appreciate it Darrel.</b>
    JS
    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.

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Is that because it has not gone back to the scan routine? Should I have used goto and resume or just put return after each if...then statement?
    None of the above.
    It's because it's the Wrong Logic for the job.

    With an IF ELSE ENDIF, there are only 2 possibilities. True or False.
    And that result is based entirely on 1 expression ... (ByteA = 7) and (combocount=0)

    So essentially, you're asking it if the Whole combination is correct, by looking at just one keypress.

    Then by stacking up 5 IF ELSE ENDIF's together, since they can't ALL be true at the same time, there will always be 4 of them saying the combination is Wrong.

    Much like in real life, decisions aren't always as easy as True or False.
    Usually, you'll have to consider several different things Before making a decision.
    And those "things" may happen at different times, so you may not be able to make a decision until more information is available.

    So instead of just the True or False, Black or White. Here's the answer.
    You also need to be able to say "I don't know yet".

    This is where just IF THEN is more useful.
    Instead of only the 2 possibilities, IF THEN has Infinite possibilities.
    Granted, It's either TRUE, or it's NOT, but by not taking action when it's not true, it's the same as saying "I don't know".

    So now you can stack those up if you want, because they won't be interfering with each other by making their own decisions independently.
    They only act on what they KNOW to be TRUE.

    Here's what I mean...Still not the way I would do it, but for the sake of argument...
    Code:
    combo:
        IF (combocount = 0) and (ByteA = 7)   then GoodKey
        IF (combocount = 1) and (ByteA = 8)   then GoodKey
        IF (combocount = 2) and (ByteA = "A") then GoodKey
        IF (combocount = 3) and (ByteA = 5)   then GoodKey
        IF (combocount = 4) and (ByteA = "D") then GoodKey
        combocount = 0 ; invalid keypress
    return
    
    GoodKey:
        combocount = combocount + 1
        if combocount = 5 then GrantAccess
    return
    DT

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


    Did you find this post helpful? Yes | No

    Default Ohhhh

    Quote Originally Posted by Darrel Taylor View Post
    None of the above.
    It's because it's the Wrong Logic for the job.

    With an IF ELSE ENDIF, there are only 2 possibilities. True or False.
    And that result is based entirely on 1 expression ... (ByteA = 7) and (combocount=0)

    So essentially, you're asking it if the Whole combination is correct, by looking at just one keypress.

    Then by stacking up 5 IF ELSE ENDIF's together, since they can't ALL be true at the same time, there will always be 4 of them saying the combination is Wrong.

    Much like in real life, decisions aren't always as easy as True or False.
    Usually, you'll have to consider several different things Before making a decision.
    And those "things" may happen at different times, so you may not be able to make a decision until more information is available.

    So instead of just the True or False, Black or White. Here's the answer.
    You also need to be able to say "I don't know yet".

    This is where just IF THEN is more useful.
    Instead of only the 2 possibilities, IF THEN has Infinite possibilities.
    Granted, It's either TRUE, or it's NOT, but by not taking action when it's not true, it's the same as saying "I don't know".

    So now you can stack those up if you want, because they won't be interfering with each other by making their own decisions independently.
    They only act on what they KNOW to be TRUE.

    Here's what I mean...Still not the way I would do it, but for the sake of argument...
    Code:
    combo:
        IF (combocount = 0) and (ByteA = 7)   then GoodKey
        IF (combocount = 1) and (ByteA = 8)   then GoodKey
        IF (combocount = 2) and (ByteA = "A") then GoodKey
        IF (combocount = 3) and (ByteA = 5)   then GoodKey
        IF (combocount = 4) and (ByteA = "D") then GoodKey
        combocount = 0 ; invalid keypress
    return
    
    GoodKey:
        combocount = combocount + 1
        if combocount = 5 then GrantAccess
    return
    I Get it, Thanks Darrel, then If you were inclined to code that way, would this be a place for select case? It seems as though the THEN Goodkey scenerio would make the combination work if out of sequence? Or would the loop cancel before combocount reaches 5 ? Oh your code works SWEET! Thanks Again.
    Joe
    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.

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    would this be a place for select case?
    You could, but it just uses more code space. It's pretty much a Select Case the way the last example is shown. But here's a Select Case version...
    Code:
    combo:
        Select CASE combocount
            Case 0 : if ByteA = 7   then GoodKey
            Case 1 : if ByteA = 8   then GoodKey
            Case 2 : if ByteA = "A" then GoodKey
            Case 3 : if ByteA = 5   then GoodKey
            Case 4 : if ByteA = "D" then GoodKey
        END SELECT
        combocount = 0
    return
        
    GoodKey:
        combocount = combocount + 1
        if combocount = 5 then GrantAccess
    return
    Or, just to keep things nice and confusing, you could also do this...
    Code:
    Combo:
        Lookup  combocount,[7,8,"A",5,"D"], NextDigit
        if ByteA = NextDigit then 
            combocount = combocount + 1
            if combocount = 5 then GrantAccess
        else
            combocount = 0
        endif
    return
    It seems as though the THEN Goodkey scenerio would make the combination work if out of sequence?
    Nope, that can't happen. You should run the program in MCSP debugger and watch what happens. After watching debuggers for awhile, you'll be able to see it in your mind, and programming will go a lot smoother. And eventually, you won't even need the debugger anymore, or the PIC. It'll run inside your head.

    Oh your code works SWEET! Thanks Again.
    No Problemo!
    DT

  12. #12


    Did you find this post helpful? Yes | No

    Talking

    Hello to all,

    I have followed east subject and it seems to me excellent, my english is not very good but treatment for understanding what you say.

    This it is a interesting project, I am working to record the data in eeprom, when it has ready the code send.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    You should run the program in MCSP debugger and watch what happens. After watching debuggers for awhile, you'll be able to see it in your mind, and programming will go a lot smoother. And eventually, you won't even need the debugger anymore, or the PIC. It'll run inside your head.
    I will have to make that purchase, as I have only the freebie version which was included with PBP, as you recommend it, it must be worthwhile.
    Do you relize the power of this project? I am using it to operate the alarm on my mother's garage, another user here, for whom this was all about is using it for his gate, and it occured to me it is a useful tool to secure the table saw, bandsaw etc . . . from the children, or even adults! So since I do not have an address to send you some beer, i give you this, the knowledge that your efforts may save some little fingers.
    JS
    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. A logic gate chip with 1 ea XOR and 2 ea AND gates?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 5th August 2009, 06:29
  2. Access to sim memu
    By sahin5002 in forum GSM
    Replies: 2
    Last Post: - 16th June 2009, 12:57
  3. truck gate
    By Melros in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 13th October 2007, 14:23
  4. 18f2550 'access is denied' USB error?
    By Giulio in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 30th December 2006, 15:29
  5. FYI - How to Access individual bytes in Word Arrays
    By Melanie in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th July 2003, 22:56

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