Keycode datatable

Thread Starter

daredavel

Joined Feb 22, 2010
32
good day sir! i'm kinda confuse and i need help in understanding how this datatable works.. How can it be determine if that certain key is press? and it is arrange in an usual manner.. although i know that its stand for RETLW 1, RETLW 2, etc.. and what is the purpose of keymask sir? and BNZ? I really need to understand how this works(specially the * and # part).. Thank you sir!!


Rich (BB code):
movf keycode,  W                           addwf PCL, F
                           dt 0x60
                           dt "123a"
                           dt "456b"
                           dt "789c"
                           dt "*0#d"
actual sample code:
Rich (BB code):
  ram                                       EQU 0x0c
  dcnt0                                   EQU ram1                                                 ; delay counter 0
  dcnt1                                   EQU ram2                          ; delay counter 1
  dcnt2                                   EQU ram3                                                 ; delay counter 2
  beepcnt                             EQU ram4                                                 ; beep cycle counter
  keycode                             EQU ram5
  rowcnt                                EQU ram6
  colcnt                                  EQU ram7
  colstatus                            EQU ram8
   
   
  cod                                        EQU ram9                                                 ; actual code
  cod_end                            EQU cod+loc
   
  readlen                              EQU cod_end
  readbuf                              EQU cod_end+1
  readbuf_end                  EQU readbuf+loc
   
  tmptr                                   EQU readbuf_end                                ; pointer for comparing and copying readbuf
  tmbyte                               EQU readbuf_end+1                         ; temp storage for comparing and copying
   
  ;--------------------------------------------------------------------------------------------------------------
 keytable                                                    ;determine pressed key's real code from scancode
                          movf keycode, W
                          addwf PCL, F
                          dt 0x60
                          dt "123a"
                          dt "456b"
                          dt "789c"
                          dt "*0#d"
   
  keyscan                                                      ; scan the keyboard
                          clrf keycode
                          movlw 4
                          movwf rowcnt
  movlw 0xfe
                          tris PORTA                                                 ; select row 0
   
  rowscan                             
  movlw 0xa0
                          call udelay
                          swapf PORTB, W
                          movwf colstatus
                          movlw 4
                          movwf colcnt
   
  colscan       
                          incf keycode, F
                          rrf colstatus, F
                          btfss STATUS, C
                          goto keytable                ; a key was found
  decfsz colcnt, F
                          goto colscan
  bsf STATUS, C
  bsf STATUS, RP0
                          rlf TRISA, F                                                 ; select next row
                          bcf STATUS, RP0
  decfsz rowcnt, F
                          goto rowscan
                          retlw 0                                ; no key was found
   
  main                                                                                     ; program starts here
                          clrf PORTA
                          clrw
                          tris PORTA                                                ; porta all output
                          clrf PORTB
                          movlw 0xf0                                             ; pb4-7 inputs
                          tris PORTB
                          bcf STATUS, RP0                                    ;bank 0
  
   
  loop                                      
  clrf PORTB                        ; clear output
  call read                            ; read code from keyboard into readbuf
                          movlw cod
                          call compbuf                  ; compare code in readbuf with code at cod
                          bnz loop                             ; the code is different
                                                                          ; the code matches, check which enter (#*) was pressed
                          movlw '*'
                          subwf keycode, W                             ; * changes code
                          bz codechange
   
  pulseout                                                                            ; # operates output
                          movlw 0x04                                           ; RB2 is output
                          movwf PORTB
  movlw pulsewidth
                          movwf dcnt2
  out0                                     
  movlw d'200'
                          call udelay
                          decfsz dcnt2, F
                          goto out0
  goto loop
   
  codechange                    
  movlw 2                                                                           ; * changes code
                          movwf PORTB                                        ; indicate changing the code
                          call read                                                      ; read new code into readbuf
  movlw cod
                          call copybuf                                            ; copy new code into cod
                          call read                                                    ; read new code twice
                          movlw cod                                              ; and check if the new code is confirmed
                          call compbuf                                          ; wrong code entry, restart with the original code
                          bnz warm
                                                                                                  ; new code is comfirmed twice, store into eeprom
                          call eep_write
                          goto loop
   
  read                                      
  clrf readlen
   
  readloop                                                                           ; wait until no key is pressed
                          clrw
                          tris PORTA                                                ; porta all LOW
                          movf PORTB, W
                          andlw 0xf0                                                                        ; keymask
                          xorlw 0xf0
                          btfss STATUS, Z
                          goto readloop
  movlw  0xf0                                            ; wait 24 ms
                          call udelay                                                                         ; (debounce)
   
  key_pressed
                          call keyscan
                          andlw 0xff
                          movwf keycode
                          bz readloop
                          movlw 0xf0                                               ; wait 24 ms
                          call udelay                                                ; (debounce)
                                                                                                  ; check if the buffer is full
                          movlw clen
                          subwf readlen, W
                          bnz read_notfull                                  
                          ; buffer is full, can return if an enter key (*#) is pressed
                          ; check for ENTER
                          call read_chkenter
                                                                                                  ; enter is pressed, return
                          movlw 0x40
                          call beep
                          movf keycode, W
                          return
   
  read_notenter
                                                                                                  ; buffer is full, but more characters entered
                                                                                                  ; shift the buffer
                          movlw readbuf+1
                          movwf FSR
   
  read_shift                         movf INDF, W
                          decf FSR, F
                          movwf INDF
                          incf FSR, F
                          incf FSR, F
                          movlw readbuf_end
                          subwf FSR, W
                          bnz read_shift
                          decf readlen, F
   
  read_notfull                   
         call read_chkenter                                      ; if the buffer is not full                                                                                                                       ; enter key (*#) is pressed, clear buffer
                          movlw 0x40
                          call beep
                          movlw readbuf
                          addwf readlen, W
                          movwf FSR
                          movf keycode, W
                          movwf INDF
                          incf readlen, F
                          goto readloop
 
Thread starter Similar threads Forum Replies Date
I General Electronics Chat 1
Top