Searching \ for '[PIC]:keypad scan problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'keypad scan problem'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:keypad scan problem'
2000\11\03@115832 by BENEDICIC SAMO

flavicon
face
   Hi!

I'm new to PIC programming. Currently I'm working on a program that scans
4x4 keypad, stores which key is pressed and outputs that on 7 segment LED
display.Program works fine in MPLAB-SIM, but it doesn't work in target
system. It doesn't react on keypress at all. The only thing it does is that
'g' segment is lit constantly.Here's my code ( part of it was taken from
mr.Ilmar Roosma from Weirdsoft ).Can anyone tell me, where the problem
is.Hardware is tested and works fine. Thanks for help,

Samo


;                         stolpci
; Matrx.asm     =============             shema prikljucitve na pic
;               |  1 2 3 4  |  RB4
; vrstice                   |  5 6 7 8  |  RB5
;               |  9 0 a b  |  RB6
;               |  c d e f   |  RB7
;               =============
;                RB0 1 2 3
; poklièem:
;          call getkey
; rezultat dobim v keychar
;
; poklièe DisplayOut za prikaz na led
;
; Martix klaviatuur v1.0 CopyLeft(c)1999 WeirdSoft Ilmar Roosmaa

       LIST            P=16f84       ; definicija procesorja
       ERRORLEVEL      -302    ; uti¹am mpasm za napake pri bankah in tris

       __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

       INCLUDE         "p16f84.inc"

keychar equ     0x10            ; variables
zamik   equ     0x11

       ORG     0x0000          ; zaèetek programa

init    bsf     STATUS,RP0      ; bank 1
       clrf    PORTB
       movlw   b'00001111'     ; RB4,5,6,7 vrstice definiram kot izhode
       movwf   TRISB
       bcf     STATUS,RP0      ; bank 0
       clrf    keychar


main    call    getkey          ; poklièi rutino getkey
       call    DisplayOut

       clrf    PORTA           ; poèisti porte, da ne gorijo
       clrf    PORTB           ; segmenti, kadar ni treba

       goto    main            ; glavni program je neskonèna zanka

getkey


       movlw   b'11111111'     ; postavi vse linije PORTB na '1'
       movwf   PORTB

;prva vrstica

       bcf     PORTB,4         ; postavi prvo vrstico na logièno '0'
       btfss   PORTB,0         ; ce je visoko, preskoèi, èe pa je tipka pritisnjena, pojdi
       goto    r0c0            ; na Row0 Column0
       btfss   PORTB,1         ; enako preveri ¹e drugi, tretji
       goto    r0c1            ; in èetrti stolpec (tipke
       btfss   PORTB,2         ;1,2,3,A)
       goto    r0c2            ;
       btfss   PORTB,3         ;
       goto    r0c3            ;
       bsf     PORTB,4         ; èe ni niè, pojdi na drugo vrstico

;druga vrsta

       bcf     PORTB,5
       btfss   PORTB,0
       goto    r1c0
       btfss   PORTB,1
       goto    r1c1            ; druga vrstica (tipke 4,5,6,B)
       btfss   PORTB,2
       goto    r1c2
       btfss   PORTB,3
       goto    r1c3
       bsf     PORTB,5

;tretja vrsta

       bcf     PORTB,6
       btfss   PORTB,0
       goto    r2c0
       btfss   PORTB,1
       goto    r2c1
       btfss   PORTB,2
       goto    r2c2
       btfss   PORTB,3
       goto    r2c3
       bsf     PORTB,6

;èetrta vrsta

       bcf     PORTB,7
       btfss   PORTB,0
       goto    r3c0
       btfss   PORTB,1
       goto    r3c1
       btfss   PORTB,2
       goto    r3c2
       btfss   PORTB,3
       goto    r3c3
       bsf     PORTB,7         ; èe pridem do sem, ni bilo niè pritisnjeno


       return

r0c0    movlw   1               ;1
       goto    savek
r0c1    movlw   2               ;2
       goto    savek
r0c2    movlw   3               ;3
       goto    savek
r0c3    movlw   10              ;A
       goto    savek
r1c0    movlw   4               ;4
       goto    savek
r1c1    movlw   5               ;5
       goto    savek
r1c2    movlw   6               ;6
       goto    savek
r1c3    movlw   11              ;B
       goto    savek
r2c0    movlw   7               ;7
       goto    savek
r2c1    movlw   8               ;8
       goto    savek
r2c2    movlw   9               ;9
       goto    savek
r2c3    movlw   12              ;C
       goto    savek
r3c0    movlw   14              ;*
       goto    savek
r3c1    movlw   0               ;0
       goto    savek
r3c2    movlw   15              ;#
       goto    savek
r3c3    movlw   13              ;D

savek   movwf   keychar         ; omista olek keychar-le

       return                  ; kodo pritisnjene tipke imam v keychar

DisplayOut


       movlw b'00000000'       ; naredi portb vse izhode
       tris PORTB

       call LedTable           ; tam bom imel doloceno, kateri segmenti bodo
       movwf   PORTB           ; pri¾gani

       movlw   b'11111110'
       tris    PORTA           ; omogoèi digit sink na PORTA, 0
       bsf     PORTA, 0

       call    delay

       return

LedTable
       movf    keychar, w              ; nalozi, katera tipka je pritisnjena in
       addwf   PCL, F                  ; prvi naslov v tabeli
       retlw   b'01000000'                             ; zato, da mi ni treba zmanj¹ati offseta za 1, ker
skoèi
       retlw   b'00000110'             ; na naslednji naslov + vrednost v keychar
       retlw   b'01011011'             ;2
       retlw   b'01001111'             ;3
       retlw   b'01100110'             ;4

       retlw   b'01101101'             ;5
       retlw   b'01111101'             ;6
       retlw   b'00000111'             ;7
       retlw   b'01111111'             ;8

       retlw   b'01101111'             ;9
       retlw   b'00111111'             ;0
       retlw   b'01110111'             ;a
       retlw   b'01111100'             ;b

       retlw   b'00111001'             ;c
       retlw   b'01011110'             ;d
       retlw   b'01111001'             ;e
       retlw   b'00110001'             ;f


delay

       movlw   .200
       movwf   zamik

;zanka  decfsz  zamik
;       goto    zanka
;
       return

       end

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
"[PIC]:","[SX]:","[AVR]:"

2000\11\03@132951 by M. Adam Davis

flavicon
face
Take a good look at the definition of your 0 and F characters for the LED
output.  It looks like 0 may be incorrect.  If so, the fact that segment G is
staying on could be a result of the display showing the inverse of 0.

I didn't look too closely at the implementation, and can only imagine how you
have it hooked up.  Could it be that you've got the number definitions inverted
with respect to how the LED is hooked up?

Also, it appears as though you have the keypad hooked up to the same port as the
LED.  Perhaps there are some incorrect interactions between the two?  Do you
have pull-ups on the keypad?

But at least you have comments!  Comment Nazi's won't be up in arms about it ;-)

-Adam

BENEDICIC SAMO wrote:
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
"[PIC]:","[SX]:","[AVR]:" =uP ONLY! "[EE]:","[OT]:" =Other "[BUY]:","[AD]:" =Ads




2000\11\04@152730 by Ethan Swint

flavicon
face
Samo-

I'm currently taking a class where we use a pic emulator (Tech Tools
ClearView Mathias using a PIC1674A) and a C compiler.  Our program was to
read inputs from the keypad on port b and output it to a PC via RS232 on
port c.  The program didn't work - unless our digital scope was hooked up to
the keypad inputs on port b!  We ran across something in the documentation
that described an input pullup resistor, but setting this option didn't seem
to have any effect.  My best guess is that there was some capacitance in the
keypad that prevented the signals from switching properly and the scope
provided a path to ground for the inputs.  You might try hooking up large
external resistors to the keypad.

I've attatched the list file (can be viewed in text editor) in that shows
the C code with the assembly for anyone who's interested.

Ethan Swint

{Original Message removed}

2000\11\04@153358 by Ethan Swint

flavicon
face
part 1 9814 bytes content-type:text/plain; (decoded quoted-printable)

Oops - here's the list file!
----- Original Message -----
From: "Ethan Swint" <spam_OUTEthan_SwintTakeThisOuTspambaylor.edu>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Saturday, November 04, 2000 2:28 PM
Subject: Re: [PIC]:keypad scan problem


> Samo-
>
> I'm currently taking a class where we use a pic emulator (Tech Tools
> ClearView Mathias using a PIC1674A) and a C compiler.  Our program was to
> read inputs from the keypad on port b and output it to a PC via RS232 on
> port c.  The program didn't work - unless our digital scope was hooked up
to
> the keypad inputs on port b!  We ran across something in the documentation
> that described an input pullup resistor, but setting this option didn't
seem
> to have any effect.  My best guess is that there was some capacitance in
the
{Quote hidden}

scans
> > 4x4 keypad, stores which key is pressed and outputs that on 7 segment
LED
{Quote hidden}


part 2 20046 bytes content-type:application/octet-stream; (decode)

part 3 146 bytes
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics




2000\11\05@205914 by William
flavicon
face
Hi, Mr Ethan.

I also did an experiment on keypad for my PIC16F84 last weeks. I only took me
about 4 days to solve my problem. First, I also though that my problem got
problem, but later I found that there is problem in my hardware part (keypad).
I hope that this can help you.

My program is using port B (bit0-bit3) as outputs, and portA (bit0-bit3) as
inputs.
I am doing a 4 x 4 keypad matrix scanning.

Program is outputed only a "0" at a time for sending output at portB (ie. 1110,
for
column one). Then, program will scan (read) row-by-row to check which key is
pressed. *When no key is pressed, portA will always read 0x0F.

The following is my simple experiment hardware 4 x 4 keypad, I added in the
pull-up
resistors, then I finally solve my problem!



          5V                   PORT B
          |
          +-+-+-+        B0    B1    B2    B3
          | | | |        |     |     |     |
PORT A     | | | |        |     |     |     |
          R R R R        |     |     |     |
          | | | |        |     |     |     |
A0 --------+--------------S-----S-----S-----S
            | | |        |     |     |     |
            | | |        |     |     |     |
A1 ----------+------------S-----S-----S-----S
              | |        |     |     |     |
              | |        |     |     |     |
A2 ------------+----------S-----S-----S-----S
                |        |     |     |     |
                |        |     |     |     |
A3 --------------+--------S-----S-----S-----S


S denotes as switch, and R denotes as pull-up resistors.

R values is around 1k - 3.3k, for me, I use 2.2k, it works
fine!

Before I added in those pull-up resistors, my read for the
keys is not stable, sometimes can and sometime cannot. Later,
I found out that when I press the key, it will generate a
machanical noise, and cause the reading for the key fault.
I use hardware method to triggle this problem, that's add in
the pull-up resistors at the portA inputs.

Good luck.

Regards,

William

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.




More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...