Re: KeyPad Lock made from a 16F84A trouble

From: Michael (NoSpam_at_att.net)
Date: 07/16/04


Date: Fri, 16 Jul 2004 11:56:11 GMT

Cason wrote:
>
> I just recently got into programming PIC chips and have started a new
> project. A key pad combination controlled lock. I have a keypad with the
> numbers 0-6 on it and an enter button. The idea is to enter the right
> combination, press enter and then a signal will be sent off one of the I/O
> pins to unlock the lock.
>
> The trouble is, with the clock speed so high, I have to make sure that after
> one presses the key it does not register that key again if they dont get
> their finger off it fast enough. I wanted to make the device programmable so
> I didnt want to hardcode any of the numbers in which is where I run into
> trouble. I didnt explain my problem well but I just cant see what direction
> to go from here, It probably makes more sense in the code.....The commented
> part is the part I need help with......
> If there was a way to compare numbers or AND bits or OR bit instead of bytes
> I think I could do it....Any suggestions?
>
> ;Constants
> STATUS equ 03h
> TRISA equ 85h
> TRISB equ 86h
> PORTA equ 05h
> PORTB equ 06h
> NUM1 equ 0Dh ;NUM1-6 are where the combo is stored
> NUM2 equ 0Eh
> NUM3 equ 0Fh
> NUM4 equ 10h
> NUM5 equ 11h
> FLAG equ 13h ;Not quite sure what to do with this yet...Im sure Ill need
> it though
> COUNT equ ;Used for delay subroutine
>
> ;Temp stuff just to give NUM1-6 a combo which is 1-2-3-4-5
> movlw 01h
> movwf NUM1
> movlw 02h
> movwf NUM2
> movlw 03h
> movwf NUM3
> movlw 04h
> movwf NUM4
> movlw 05h
> movwf NUM5
>
> ;Setup ports
> bsf STATUS,5
> movlw 01h
> movwf TRISA
> movlw b'11111111'
> movwf TRISB
> bcf STATUS,5
>
> ;Main Loop
> movlw 00h
> movwf FLAG
> State1 btfss PORTB,NUM1 ;<----Is this valid code? I didnt know if the
> NUM1 part is valid...
> goto State1
> call Delay
> State2 ;make sure no buttons are pressed
> ;If button other than value in NUM2 is pressed goto State1
> ;If button associated with NUM2 is pressed goto State3
> State3
> State4
> State5
>
> Delay
> ;just wait....I dont need help with this....

Regarding label "State1", yes, that code is perfectly legal. But I
think it doesn't do what you intend. You have NUM1 equated to 0x0D, a
atorage location for one of your variables. The code in question tests
bit 0x0D of PortB; bit thirteen does not exist on an 8-bit port.

Might be other problems with your code. I stopped checking at "State1".

The speed of your micro isn't a problem as far as using a keyboard.
Debounce the keys, either in hardware or in software, and when your code
detects a key "down" it should wait for it to go "up" again and not
process any further key presses until that key is "up" again.



Relevant Pages

  • R: Problem with LCD & PIC16C54C
    ... PORTA EQU 0x05; Physical Address on PIC ... movlw timehigh ... movwf COUNTHIGH ... SDELAY;delay ...
    (sci.electronics.design)
  • Re: PIC 18F242 PortA Problem
    ... All goes well until it get to PORTA. ... > SECONDS equ h'000' ... > movlw h'60' ... > movwf TRISA ...
    (sci.electronics.design)
  • Re: Pulse counter/freq-volt converter
    ... tmr1_off equ b'00000110' ... goto init ... movlw tmr1_off; ... movwf OPTION_REG ...
    (sci.electronics.design)
  • Re: PIC 16F84A Problems
    ... > simply counts up in binary and displays the count on LEDS connected directly ... > STATUS equ 03h ... > movlw 00h ... > movwf TRISB ...
    (sci.electronics.design)
  • Pic Eusart behaviour
    ... I know the timer is working by scoping the A1 pin. ... config XINST = OFF ... movwf TRISA ... movlw 0xFF; make PORTB all input ...
    (sci.electronics.basics)