Newer
Older
pic-keypad / keypad.lst
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001 ;;; KEYPAD.ASM
                      00002 ;;; Copyright (c) 2002, TundraWare Inc., All Rights Reserved
                      00003 ;;; 
                      00004 ;;; Program to encode keypad presses into binary numbers
                      00005 ;;; 
                      00006 ;;; $Id: keypad.asm,v 1.34 2002/06/18 16:44:33 tundra Exp tundra $
                      00007 
                      00008 
                      00009 ;;;;;;;;;;
                      00010 ;;; This code assumes the following keypad wiring to PORTB on the PIC:
                      00011 ;;;
                      00012 ;;;  RB7   RB6   RB5   RB4   RB3   RB2   RB1   RB0
                      00013 ;;;  Col.  Col.  Col.  Col.  Row   Row   Row   Row
                      00014 ;;;   4     3     2     1     4     3     2     1
                      00015 ;;;;;;;;;;      
                      00016 
                      00017                 list            p=16F84A
                      00018                 include         <P16F84A.INC>
                      00001         LIST
                      00002 ; P16F84A.INC  Standard Header File, Version 2.00    Microchip Technology, Inc.
                      00134         LIST
                      00019 
                      00020         errorlevel      -302            ;suppress bank selection messages
2007   3FF3           00021         __config        3ff3h           ;RC osc, WDT off
2000   0001 0002 0003 00022         __idlocs        1234
       0004 
                      00023  
                      00024 ;;;;;;;;;;
                      00025 ;;; Device Constants
                      00026 ;;;;;;;;;;
                      00027 
  00000000            00028 tmr2    equ     00H                     ; TMR0 prescaler constants
  00000001            00029 tmr4    equ     01H
  00000002            00030 tmr8    equ     02H
  00000003            00031 tmr16   equ     03H
  00000004            00032 tmr32   equ     04H
  00000005            00033 tmr64   equ     05H
  00000006            00034 tmr128  equ     06H
  00000007            00035 tmr256  equ     07H
                      00036 
                      00037 
                      00038 ;;;;;;;;;;
                      00039 ;;; Circuit Constants
                      00040 ;;;;;;;;;;
                      00041 
  00000006            00042 KEYPAD  equ     PORTB
  00000005            00043 OUTPUT  equ     PORTA
  00000004            00044 PAR_SEL equ     4               ; bit used to select parallel/serial output
  00000004            00045 PLATCH  equ     4               ; parallel latch bit
  00000001            00046 SCLK    equ     1               ; serial clock out bit
  00000000            00047 SDAT    equ     0               ; serial data out bit
  00000002            00048 SLATCH  equ     2               ; serial latch bit
  00000086            00049 TRISKEY equ     TRISB
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

  00000085            00050 TRISOUT equ     TRISA
                      00051 
                      00052 ; Constants used to Set TMR0 interrupt rate.
                      00053 ; Adjust as needed using the following formula:
                      00054 ;
                      00055 ;    I = T * TMR0_CNT * Prescaler Factor
                      00056 ;
                      00057 ; TMR0_PRIME is the value actually used to prime
                      00058 ; TMR0 when restarting it - it counts *up* and
                      00059 ; interrupts on overflow.
                      00060 ;
                      00061 ; The following TMR0 constants are approximately:
                      00062 ;
                      00063 ;   (T) Internal Clock Interval:  3us
                      00064 ;       (I) TMR0 Interrupt Rate:  480us
                      00065 
                      00066 
  00000005            00067 TMR0_CNT        equ     D'5'
  00000004            00068 TMR0_PRE        equ     tmr32
  000000FB            00069 TMR0_PRIME      equ     D'256'-TMR0_CNT
                      00070 
                      00071 
                      00072 ;;;;;;;;;;
                      00073 ;;; Program Contants
                      00074 ;;;;;;;;;;
                      00075 
  00000005            00076 DEBOUNCE_COUNT  equ     05h     ; # times keyhit must be unchanged to be valid
  0000000A            00077 DEBOUNCE_TIME   equ     0ah     ; # TMR0 interrupts to wait between keyboard reads
  00000001            00078 CLK_TIME        equ     01h     ; # TMR0 interrupts for serial clock true
  00000004            00079 MAX_COL         equ     04h     ; # of columns on the keyboard
  0000000F            00080 NO_HIT          equ     0fh     ; bit pattern which means no key has been hit
  00000001            00081 LATCH_TIME      equ     01h     ; # TMR0 interrupts to leave latch line true
  00000003            00082 REPEAT_COUNT    equ     03h     ; scan delay = 
                      00083                                 ;     REPEAT_COUNT * REPEAT_DELAY * TMR0 rate
  00000057            00084 REPEAT_DELAY    equ     D'87'
                      00085         
                      00086 ;;;;;;;;;;
                      00087 ;;; Register File Assignments
                      00088 ;;;;;;;;;;
                      00089         
                      00090         CBLOCK 0cH
                      00091                 ; context save area
                      00092 
  0000000C            00093                 _fsr
  0000000D            00094                 _pclath
  0000000E            00095                 _status
  0000000F            00096                 _w
                      00097 
                      00098                 ; flags
                      00099 
  00000010            00100                 par_out         ; non-zero -> parallel out; zero -> serial out
                      00101 
                      00102                 ; variables
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  3


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00103 
  00000011            00104                 count
  00000012            00105                 current_col
  00000013            00106                 key_val
  00000014            00107                 wait_count
                      00108         ENDC
                      00109 
                      00110         
                      00111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                      00112 
                      00113         
                      00114 ;;;;;;;;;;
                      00115 ;;; Power-On Entry Point
                      00116 ;;;;;;;;;;
                      00117 
0000                  00118                 org     00H
0000   2820           00119                 goto    main
                      00120 
                      00121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                      00122 
                      00123 ;;;;;;;;;;
                      00124 ;;; Interrupt Handler
                      00125 ;;;;;;;;;;
                      00126 
0004                  00127                 org     04H
                      00128 
0004   008F           00129                 movwf   _w              ; save context
0005   0803           00130                 movfw   STATUS
0006   1303           00131                 bcf     STATUS,RP1
0007   1283           00132                 bcf     STATUS,RP0
0008   008E           00133                 movwf   _status
0009   0804           00134                 movfw   FSR
000A   008C           00135                 movwf   _fsr
000B   080A           00136                 movfw   PCLATH
000C   008D           00137                 movwf   _pclath
000D   018A           00138                 clrf    PCLATH
                      00139 
                      00140                 ; Figure out who interrupted and service it
                      00141 
000E   190B           00142                 btfsc   INTCON,T0IF     ; did we get a TMR0 interrupt?
000F   2811           00143                 goto    tmr0_svc        ; yup
0010   2817           00144                 goto    restore_context ; no supported interrupt type found
                      00145 
                      00146                 ; TMR0 ISR
0011                  00147 tmr0_svc:
0011   110B           00148                 bcf     INTCON,T0IF     ; clear the interrupt condition
0012   30FB           00149                 movlw   TMR0_PRIME      ; prime the counter
0013   0081           00150                 movwf   TMR0
                      00151 
                      00152                 ; Update the wait timer if it is in use
                      00153                 ; Only do this on TMR0 interrupts so timing is predictable 
                      00154 
0014   0814           00155                 movfw   wait_count
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  4


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0015   1D03           00156                 btfss   STATUS,Z        ; non-zero count means 'in use'
0016   0394           00157                 decf    wait_count,F    ; decrement current count
                      00158 
                      00159                 ;;; End TMR0 ISR
                      00160 
0017                  00161 restore_context:
0017   080D           00162                 movfw   _pclath         ; restore entry context
0018   008A           00163                 movwf   PCLATH
0019   080C           00164                 movfw   _fsr
001A   0084           00165                 movwf   FSR
001B   080E           00166                 movfw   _status
001C   0083           00167                 movwf   STATUS
001D   0E8F           00168                 swapf   _w,F            ; get W back w/o changing Z flag
001E   0E0F           00169                 swapf   _w,W
                      00170         
001F   0009           00171                 retfie                  ; all done
                      00172 
                      00173 ;;; End of interrupt handler
                      00174 
                      00175 
                      00176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                      00177 
                      00178         
                      00179 ;;;;;;;;;;
                      00180 ;;; Main program logic
                      00181 ;;;;;;;;;;
                      00182 
0020                  00183 main:
0020   20DC           00184                 call    init            ; initialize the system
0021                  00185 scan:
0021   0A92           00186                 incf    current_col,F   ; pickup next column to scan
0022   3005           00187                 movlw   MAX_COL+1       ; if current_col > MAX_COL then
0023   0212           00188                 subwf   current_col,W   ; we just did last column, so start over
0024   1D03           00189                 btfss   STATUS,Z        ; zero means we need to start over
0025   2828           00190                 goto    key_scan        ; nope, go look for key hits
0026   0192           00191                 clrf    current_col     ; yes, reinit column counter
0027   2821           00192                 goto    scan
0028                  00193 key_scan:
0028   0812           00194                 movfw   current_col     ; get bit pattern which
0029   2069           00195                 call    col_select      ; selects curently desired column
002A   0086           00196                 movwf   KEYPAD          ; and enable that column
002B   0806           00197                 movfw   KEYPAD          ; get keypad inputs
002C   390F           00198                 andlw   0fh             ; only want row bits
002D   3EF1           00199                 addlw   -NO_HIT         ; see if key hit occured
002E   1903           00200                 btfsc   STATUS,Z        ; in current column
002F   2821           00201                 goto    scan            ; no, look at next column
0030   20AC           00202                 call    key_get         ; yes, process ignore key releaseskeystroke
0031   390F           00203                 andlw   0fh             ; there is bounce on a key *release*
0032   3EF1           00204                 addlw   -NO_HIT         ; as well as a key *press*
0033   1903           00205                 btfsc   STATUS,Z        ; we want to debounce key releases
0034   2821           00206                 goto    scan            ; (so they do not look like legit keystrokes)
                      00207                                         ; but then we just ignore the release
0035   20BC           00208                 call    key_xlate       ; legit keystroke - turn into binary value
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  5


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0036   208D           00209                 call    key_out         ; and output it
                      00210 
                      00211                 ; introduce wait between keyboard scans to limit
                      00212                 ; key repeat rate
                      00213 
0037   3003           00214                 movlw   REPEAT_COUNT
0038   0091           00215                 movwf   count
0039                  00216 scan_delay:
0039   3057           00217                 movlw   REPEAT_DELAY
003A   20D7           00218                 call    wait
003B   0B91           00219                 decfsz  count,F
003C   2839           00220                 goto    scan_delay
                      00221 
003D   2821           00222                 goto    scan            ; scan forever
                      00223 
                      00224 ;;; End of main logic
                      00225 
                      00226 
                      00227  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                      00228 
                      00229 
                      00230  ;;;;;;;;;;
                      00231  ;;; Data & Tables
                      00232  ;;;;;;;;;;
                      00233 
                      00234 ;;;;;;;;;;
                      00235 ;;; Embedded Release & Copyright Information
                      00236 ;;;;;;;;;;
                      00237 
003E   35E5 3CF0 30E4 00238                 DA      "keypad.asm - $Revision: 1.34 $ - Copyright 2002, TundraWare Inc., All Rights Re
                            served."
       1761 39ED 102D 
       1024 2965 3B69 
       39E9 37EE 1D20 
       18AE 19B4 1024 
       102D 1043 37F0 
       3CF2 34E7 3474 
       1032 1830 192C 
       1054 3AEE 3272 
       30D7 30F2 32A0 
       24EE 31AE 1620 
       20EC 3620 2969 
       33E8 3A73 1052 
       32F3 32F2 3B65 
       322E 
                      00239 
                      00240 ; End of Embedded Release & Copyright Information
                      00241 
                      00242 
                      00243 ;;;;;;;;;;
                      00244 ;;; Column selection bit patterns.
                      00245 ;;;;;;;;;;
                      00246 
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  6


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0069                  00247 col_select:
0069   0782           00248                 addwf   PCL,F
006A   34F0           00249                 DT      b'11110000'     ; placeholder, no column selected
006B   34E0           00250                 DT      b'11100000'     ; column 1 selected
006C   34D0           00251                 DT      b'11010000'     ; column 2 selected
006D   34B0           00252                 DT      b'10110000'     ; column 3 selected
006E   3470           00253                 DT      b'01110000'     ; column 4 selected
                      00254 
                      00255 ;;;;;;;;;;
                      00256 ;;; Translate row/column selection pattern into equivalent binary value.
                      00257 ;;; There is one subtable for each column.  '*' is translated of 0eh and
                      00258 ;;; '#' is translated to 0fh.  This allows the entire keyboard to be
                      00259 ;;; uniquely translated to 1 of 16 hex output values.
                      00260 ;;;;;;;;;;
                      00261 
006F                  00262 col1_keys:
006F   0782           00263                 addwf   PCL,F
0070   3401           00264                 DT      01h             ; Row 1
0071   3404           00265                 DT      04h             ; Row 2
0072   3407           00266                 DT      07h             ; Row 3
0073   340E           00267                 DT      0eh             ; Row 4
0074                  00268 col2_keys:
0074   0782           00269                 addwf   PCL,F
0075   3402           00270                 DT      02h             ; Row 1
0076   3405           00271                 DT      05h             ; Row 2
0077   3408           00272                 DT      08h             ; Row 3
0078   3400           00273                 DT      00h             ; Row 4
0079                  00274 col3_keys:
0079   0782           00275                 addwf   PCL,F
007A   3403           00276                 DT      03h             ; Row 1
007B   3406           00277                 DT      06h             ; Row 2
007C   3409           00278                 DT      09h             ; Row 3
007D   340F           00279                 DT      0fh             ; Row 4
007E                  00280 col4_keys:
007E   0782           00281                 addwf   PCL,F
007F   340A           00282                 DT      0ah             ; Row 1
0080   340B           00283                 DT      0b              ; Row 2
0081   340C           00284                 DT      0c              ; Row 3
0082   340D           00285                 DT      0dh             ; Row 4
                      00286 
                      00287 
                      00288 ;;;;;;;;;;
                      00289 ;;; Translate a nibble bit pattern where an on bit means that row was selected
                      00290 ;;; into an equivalent binary value for that row.
                      00291 ;;;;;;;;;;
                      00292 
0083                  00293 bit2row:
0083   0782           00294                 addwf   PCL,F
0084   3400           00295                 DT      00H             ; placeholder, never used
0085   3400           00296                 DT      00H             ; b'0001' => row 1
0086   3401           00297                 DT      01H             ; b'0010' => row 2
0087   3400           00298                 DT      00H             ; placeholder, never used
0088   3402           00299                 DT      02H             ; b'0100' => row 3
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  7


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0089   3400           00300                 DT      00H             ; placeholder, never used
008A   3400           00301                 DT      00H             ; placeholder, never used
008B   3400           00302                 DT      00H             ; placeholder, never used
008C   3403           00303                 DT      03H             ; b'1000' => row 4
                      00304 
                      00305 
                      00306 ;;; End of translation tables
                      00307 
                      00308         
                      00309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                      00310 
                      00311 
                      00312 ;;;;;;;;;;
                      00313 ;;; Supporting Subroutines
                      00314 ;;;;;;;;;;
                      00315 
                      00316 
                      00317 ;;;;;;;;;;
                      00318 ;;; Output current keystroke.
                      00319 ;;; This routine supports both serial and parallel output modes,
                      00320 ;;; which are selected at init time as follows:
                      00321 ;;;
                      00322 ;;;          A4=0  ===> Serial Output
                      00323 ;;;          A4=1  ===> Parallel Output
                      00324 ;;;;;;;;;;
                      00325 
008D                  00326 key_out:
                      00327 
008D   3000           00328                 movlw   0               ; clear W
008E   0710           00329                 addwf   par_out,W       ; if 0, we want serial output
008F   1903           00330                 btfsc   STATUS,Z
0090   2898           00331                 goto    serial_out
                      00332 
                      00333                 ; parallel output routine
                      00334 
0091   0813           00335                 movfw   key_val         ; load the value
0092   0085           00336                 movwf   OUTPUT
0093   1605           00337                 bsf     OUTPUT,PLATCH   ; latch on
0094   3001           00338                 movlw   LATCH_TIME
0095   20D7           00339                 call    wait
0096   1205           00340                 bcf     OUTPUT,PLATCH   ; latch off
0097   0008           00341                 return
                      00342 
                      00343                 ; serial output routine
0098                  00344 serial_out:
0098   3004           00345                 movlw   04h             ; we have to shift out 4 bits LSB->MSB
0099   0091           00346                 movwf   count
009A                  00347 shift_bit:
009A   1005           00348                 bcf     OUTPUT,SDAT     ; assume it's a 0
009B   1C13           00349                 btfss   key_val,0       ; see what it really is
009C   289E           00350                 goto    clock_bit
009D   1405           00351                 bsf     OUTPUT,SDAT     ; nope, it was a 1
009E                  00352 clock_bit:
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  8


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

009E   1485           00353                 bsf     OUTPUT,SCLK     ; clock it out
009F   3001           00354                 movlw   CLK_TIME
00A0   20D7           00355                 call    wait
00A1   1085           00356                 bcf     OUTPUT,SCLK     ; reset clock bit
00A2   0391           00357                 decf    count,F         ; see if bits left to do
00A3   1903           00358                 btfsc   STATUS,Z
00A4   28A7           00359                 goto    serial_latch    ; all done
00A5   0C93           00360                 rrf     key_val,F       ; pickup next bit
00A6   289A           00361                 goto    shift_bit       ; and move it           
                      00362 
                      00363                 ; now latch the data out
00A7                  00364 serial_latch:
00A7   1505           00365                 bsf     OUTPUT,SLATCH   ; latch on
00A8   3001           00366                 movlw   LATCH_TIME
00A9   20D7           00367                 call    wait
00AA   1105           00368                 bcf     OUTPUT,SLATCH   ; latch off
00AB   0008           00369                 return
                      00370 
                      00371 ;;; End of 'key_out'
                      00372 
                      00373 
                      00374 ;;;;;;;;;;
                      00375 ;;; Read a debounced key from the keyboard.
                      00376 ;;; Keep reading keyboard until the value has not changed 
                      00377 ;;; DEBOUNCE_COUNT times.  Wait an interval of DEBOUNCE_TIME
                      00378 ;;; between read attempts
                      00379 ;;;;;;;;;;
                      00380 
00AC                  00381 key_get:
00AC   0806           00382                 movfw   KEYPAD
00AD   0093           00383                 movwf   key_val
00AE                  00384 debounce:
00AE   3005           00385                 movlw   DEBOUNCE_COUNT  ; setup debounce counter
00AF   0091           00386                 movwf   count
00B0                  00387 check_key:
00B0   300A           00388                 movlw   DEBOUNCE_TIME   ; wait to let keyboard settle
00B1   20D7           00389                 call    wait
00B2   0806           00390                 movfw   KEYPAD
00B3   0293           00391                 subwf   key_val,F       ; see if matched last
00B4   1903           00392                 btfsc   STATUS,Z        ; if Z, the values matched
00B5   28B8           00393                 goto    matched
00B6   0093           00394                 movwf   key_val         ; no match, start debounce cycle again
00B7   28AE           00395                 goto    debounce
00B8                  00396 matched:
00B8   0093           00397                 movwf   key_val         ; save in case we have to do again
00B9   0B91           00398                 decfsz  count,F         ; see how many times left to go
00BA   28B0           00399                 goto    check_key       ; more matches to do
                      00400 
00BB   0008           00401                 return                  ; got DEBOUNCE_COUNT matches - all done
                      00402 
                      00403 ; End of 'key_get'
                      00404 
                      00405 
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE  9


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00406 ;;;;;;;;;;
                      00407 ;;; Translate the current keystroke into an equivalent binary value.
                      00408 ;;;;;;;;;;
                      00409 
00BC                  00410 key_xlate:
                      00411                 ; translate the hardware bit pattern indicating
                      00412                 ; which row was selected into an equivalent binary
                      00413                 ; row number.  This will be used to index into
                      00414                 ; the translation table for the current column to
                      00415                 ; get the final binary value for that key.
                      00416 
00BC   0913           00417                 comf    key_val,W       ; complement so only bit on corresponds
00BD   390F           00418                 andlw   0fh             ; to row selected - mask unused off
00BE   2083           00419                 call    bit2row         ; translate it into a row number
00BF   0093           00420                 movwf   key_val         ; save for use below
                      00421 
                      00422                 ; translate key value into equivalent binary value
                      00423                 ; using the appropriate translation table for the
                      00424                 ; current column
                      00425 
00C0   0812           00426                 movfw   current_col     ; get current column
00C1   3EFF           00427                 addlw   -1              ; convert into an 0-relative offset
00C2   0782           00428                 addwf   PCL,F           ; dispatch into the following jump table
00C3   28C7           00429                 goto    col1_xlate
00C4   28CB           00430                 goto    col2_xlate
00C5   28CF           00431                 goto    col3_xlate
00C6   28D3           00432                 goto    col4_xlate
                      00433 
00C7                  00434 col1_xlate:
00C7   0813           00435                 movfw   key_val
00C8   206F           00436                 call    col1_keys
00C9   0093           00437                 movwf   key_val
00CA   0008           00438                 return
                      00439 
00CB                  00440 col2_xlate:
00CB   0813           00441                 movfw   key_val
00CC   2074           00442                 call    col2_keys
00CD   0093           00443                 movwf   key_val
00CE   0008           00444                 return
                      00445 
00CF                  00446 col3_xlate:
00CF   0813           00447                 movfw   key_val
00D0   2079           00448                 call    col3_keys
00D1   0093           00449                 movwf   key_val
00D2   0008           00450                 return
                      00451 
00D3                  00452 col4_xlate:
00D3   0813           00453                 movfw   key_val
00D4   207E           00454                 call    col4_keys
00D5   0093           00455                 movwf   key_val
00D6   0008           00456                 return
                      00457 
                      00458 
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE 10


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00459 ;;; End of 'key_xlate'
                      00460 
                      00461 
                      00462 ;;;;;;;;;;
                      00463 ;;; Generic wait routine.
                      00464 ;;; Expects wait count to be passed in W.
                      00465 ;;; Total wait time is thus W * TMR0 interrupt rate
                      00466 ;;;;;;;;;;
                      00467 
00D7                  00468 wait:
00D7   0094           00469                 movwf   wait_count
00D8                  00470 waiting:
00D8   0814           00471                 movfw   wait_count      ; wait until we countdown to 0
00D9   1D03           00472                 btfss   STATUS,Z
00DA   28D8           00473                 goto    waiting
00DB   0008           00474                 return
                      00475 
                      00476 ;;; End Of 'wait'
                      00477 
                      00478 
                      00479 ;;;;;;;;;;
                      00480 ;;; Initialize hardware and software at startup as needed.
                      00481 ;;; Returns with register bank 0 selected.
                      00482 ;;;;;;;;;;
                      00483 
00DC                  00484 init:
00DC   018B           00485                 clrf    INTCON          ; all interrupts off, flags cleared
                      00486 
                      00487                 ; determine whether we want serial or parallel output
                      00488                 ; and set flag accordingly for use later in the output routine
                      00489 
00DD   0190           00490                 clrf    par_out         ; assume serial
00DE   1A05           00491                 btfsc   OUTPUT,PAR_SEL  ; if high - parallel out
00DF   0990           00492                 comf    par_out,F       ; we want parallel output
                      00493                 
                      00494                 ; Setup control registers
                      00495 
00E0   1683           00496                 bsf     STATUS,RP0      ; select register bank 1  
                      00497  
                      00498                 ; setup output port with all bits output enabled
                      00499 
00E1   30E0           00500                 movlw   b'11100000'     ; set OUTPUT 0:4 as outputs
00E2   0085           00501                 movwf   TRISOUT         ; (to output binary value of keypress)
                      00502 
                      00503                 ; Setup control registers
                      00504 
00E3   1683           00505                 bsf     STATUS,RP0      ; select register bank 1  
                      00506  
                      00507                 ; setup keypad interface port
                      00508 
00E4   300F           00509                 movlw   b'00001111'     ; KEYPAD high nibble set for output
                      00510                                         ; (for column control)
00E5   0086           00511                 movwf   TRISKEY         ; KEYPAD low nibble set for input
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE 11


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00512                                         ; (to read rows)
                      00513 
                      00514                 ; setup TMR0 interrupt interval
                      00515 
00E6   0181           00516                 clrf    OPTION_REG      ; TMR0: assign int. clock & prescaler
                      00517                                         ; PORTB: weak pullups
00E7   3004           00518                 movlw   TMR0_PRE        ; Set TMR0 prescale factor
00E8   0481           00519                 iorwf   OPTION_REG,F
                      00520 
00E9   1283           00521                 bcf     STATUS,RP0      ; select register bank 0
                      00522 
                      00523                 ; Prime the TMR0 countup counter
                      00524 
00EA   30FB           00525                 movlw   TMR0_PRIME      ; prime the counter
00EB   0081           00526                 movwf   TMR0
                      00527 
                      00528                 ; Intialize ports
                      00529 
00EC   0185           00530                 clrf    OUTPUT
00ED   0186           00531                 clrf    KEYPAD
                      00532 
                      00533                 ; Initialize variables
                      00534 
00EE   0192           00535                 clrf    current_col
00EF   0193           00536                 clrf    key_val
00F0   0191           00537                 clrf    count
00F1   0194           00538                 clrf    wait_count
                      00539 
                      00540                 ; Setup interrupt handling
                      00541 
00F2   168B           00542                 bsf     INTCON,T0IE     ; enable TMR0 interrupt
00F3   178B           00543                 bsf     INTCON,GIE      ; and turn interrupts back on
                      00544 
00F4   0008           00545                 return  
                      00546 
                      00547 ;;; End of 'init'
                      00548 
                      00549 
                      00550 ;;;;;;;;;;
                      00551 ;;; EEPROM Contents
                      00552 ;;;;;;;;;;
                      00553         
2100                  00554                 org     2100h
                      00555 
2100                  00556                 DE      ""
                      00557                 END
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE 12


SYMBOL TABLE
  LABEL                             VALUE 

C                                 00000000
CLK_TIME                          00000001
DC                                00000001
DEBOUNCE_COUNT                    00000005
DEBOUNCE_TIME                     0000000A
EEADR                             00000009
EECON1                            00000088
EECON2                            00000089
EEDATA                            00000008
EEIE                              00000006
EEIF                              00000004
F                                 00000001
FSR                               00000004
GIE                               00000007
INCFILES                          ../include
INDF                              00000000
INTCON                            0000000B
INTE                              00000004
INTEDG                            00000006
INTF                              00000001
IRP                               00000007
KEYPAD                            00000006
LATCH_TIME                        00000001
MAX_COL                           00000004
NOT_PD                            00000003
NOT_RBPU                          00000007
NOT_TO                            00000004
NO_HIT                            0000000F
OPTION_REG                        00000081
OUTPUT                            00000005
PAR_SEL                           00000004
PCL                               00000002
PCLATH                            0000000A
PLATCH                            00000004
PORTA                             00000005
PORTB                             00000006
PS0                               00000000
PS1                               00000001
PS2                               00000002
PSA                               00000003
RBIE                              00000003
RBIF                              00000000
RD                                00000000
REPEAT_COUNT                      00000003
REPEAT_DELAY                      00000057
RP0                               00000005
RP1                               00000006
SCLK                              00000001
SDAT                              00000000
SLATCH                            00000002
STATUS                            00000003
T0CS                              00000005
T0IE                              00000005
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE 13


SYMBOL TABLE
  LABEL                             VALUE 

T0IF                              00000002
T0SE                              00000004
TMR0                              00000001
TMR0_CNT                          00000005
TMR0_PRE                          00000004
TMR0_PRIME                        000000FB
TRISA                             00000085
TRISB                             00000086
TRISKEY                           00000086
TRISOUT                           00000085
W                                 00000000
WR                                00000001
WREN                              00000002
WRERR                             00000003
Z                                 00000002
_CP_OFF                           00003FFF
_CP_ON                            0000000F
_HS_OSC                           00003FFE
_LP_OSC                           00003FFC
_PWRTE_OFF                        00003FFF
_PWRTE_ON                         00003FF7
_RC_OSC                           00003FFF
_WDT_OFF                          00003FFB
_WDT_ON                           00003FFF
_XT_OSC                           00003FFD
__16F84A                          00000001
_fsr                              0000000C
_pclath                           0000000D
_status                           0000000E
_w                                0000000F
bit2row                           00000083
check_key                         000000B0
clock_bit                         0000009E
col1_keys                         0000006F
col1_xlate                        000000C7
col2_keys                         00000074
col2_xlate                        000000CB
col3_keys                         00000079
col3_xlate                        000000CF
col4_keys                         0000007E
col4_xlate                        000000D3
col_select                        00000069
count                             00000011
current_col                       00000012
debounce                          000000AE
init                              000000DC
key_get                           000000AC
key_out                           0000008D
key_scan                          00000028
key_val                           00000013
key_xlate                         000000BC
main                              00000020
matched                           000000B8
MPASM 03.00 Released           KEYPAD.ASM   6-18-2002  17:39:48         PAGE 14


SYMBOL TABLE
  LABEL                             VALUE 

par_out                           00000010
restore_context                   00000017
scan                              00000021
scan_delay                        00000039
serial_latch                      000000A7
serial_out                        00000098
shift_bit                         0000009A
tmr0_svc                          00000011
tmr128                            00000006
tmr16                             00000003
tmr2                              00000000
tmr256                            00000007
tmr32                             00000004
tmr4                              00000001
tmr64                             00000005
tmr8                              00000002
wait                              000000D7
wait_count                        00000014
waiting                           000000D8


MEMORY USAGE MAP ('X' = Used,  '-' = Unused)

0000 : X---XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
00C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXX-----------
2000 : XXXX---X-------- ---------------- ---------------- ----------------

All other memory blocks unused.

Program Memory Words Used:   242
Program Memory Words Free:   782


Errors   :     0
Warnings :     0 reported,     0 suppressed
Messages :     0 reported,     4 suppressed