Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/14/06 09:45
Read: times


 
#124282 - commented code
Responding to: ???'s previous message
Here is the code of SCAN KEYS with commnets.

I hope it is readable, if not then reply what are the probs you are facing.

Also reply mw the error in logic

regards
AS

SCAN_MATRIX_KEYBOARD:
     acall   DELAY ; calls the 30 MS delay subroutine
     mov     a, p1 ; mov the value of p1 to acc
     push    acc   ; value of acc is preserved
     anl     a, #0fh ; higher nibble is made low ie ROW
     cjne    a, #0fh, AHEAD ;if the Lower Nibble ie Coulmn reading is not high then 
                            ; it means any column has been pressed
                            ; jump to subroutine AHEAD
     sjmp    SCAN_MATRIX_KEYBOARD ; otherwise LOOP

AHEAD:
     pop     acc ; get back the original value of p1 
     anl     a, #0f0h ; Make lower Nibbles ie column low
     cjne    a, #0f0h, PROCESS_SCAN ; if the higher nibbles ie ROW are not high
                                    ; it means any ROW is pressed
                                    ; then jump to PROCESS_SCAN
     sjmp    SCAN_MATRIX_KEYBOARD ; otherwise LOOP

PROCESS_SCAN:
      mov    a, p1 ; once agin move the value of p1 to acc
      cpl    a ; compliment it and find whether actually a key is pressed or not
      jz     SCAN_MATRIX_KEYBOARD ; 
      cpl    a ; get the original value of p1
      push   acc ; preserve this value of p1
      anl    a, #0fh 
      cjne   a, #0fh, ROW_SCAN_1 ;; again check any column had been pressed or not

      sjmp   SCAN_MATRIX_KEYBOARD

ROW_SCAN_1:
      pop   acc ; get the original value of acc agian to check which row is pressed
      anl   a, #0f0h ; make higher nibbles high 
      cjne  a, #0e0h, ROW_SCAN_2 ; if ROW 1 has been pressed then jump to ROW_1 
                                 ; otherwise jump to ROW_2 checking
      sjmp  ROW_1

ROW_SCAN_2:
     cjne   a, #0d0h, ROW_SCAN_3
     sjmp   ROW_2

ROW_SCAN_3:
     cjne   a, #0b0h, ROW_SCAN_4
     sjmp   ROW_3

ROW_SCAN_4:
     cjne   a, #70h, SCAN_MATRIX_KEYBOARD
     sjmp   ROW_4

ROW_1:
     mov    dptr, #CODE1
     sjmp   FINAL

ROW_2:
     mov    dptr, #CODE2
     sjmp   FINAL

ROW_3:
     mov    dptr, #CODE3
     sjmp   FINAL

ROW_4:
     mov    dptr, #CODE4

FINAL:
     mov     a, p1 ; get the original value of p1 so that the COlumn can be sestimated from here
     clr     c ; clear carry flag

SUB_FINAL:
     rrc     a ; rotate right untill carry is clear
     jnc     MATCH ; if the carry is clear then jump to MATCH
     inc     dptr ; if carry is not clear then increment the DPTR
     sjmp    SUB_FINAL ; LOOP

MATCH:
     clr     a ; clear acc
     movc    a,@a+dptr ; move the value of dptr to ACC
     ;mov    r6, a
     push    acc ; preserve this value
     ret


CODE1: db '1','2','3','4'
CODE2: db '5','6','7','8'
CODE3: db '9','10','11','12'
CODE4: db '13','14','15','16'



List of 27 messages in thread
TopicAuthorDate
Matrix Keyboard not working            01/01/70 00:00      
   the logic            01/01/70 00:00      
   Lots of problems            01/01/70 00:00      
      no, it's completely bad in concept            01/01/70 00:00      
      Does the LCD Work?            01/01/70 00:00      
      enphasizing            01/01/70 00:00      
   commented code            01/01/70 00:00      
      Persistance my friend            01/01/70 00:00      
         I'll try it in other way            01/01/70 00:00      
            I'll make the corrections            01/01/70 00:00      
      Note on comments            01/01/70 00:00      
         bad, very bad - yes, but not necessarily because            01/01/70 00:00      
            Subroutine Details            01/01/70 00:00      
               I don't know            01/01/70 00:00      
                I do not know what that information is good for.            01/01/70 00:00      
                  Column scan after ROW confirmation            01/01/70 00:00      
                     Maybe the problem is not here            01/01/70 00:00      
      more Informative code            01/01/70 00:00      
         Comments are better            01/01/70 00:00      
         The Algorithm            01/01/70 00:00      
            This isn\'t necessarily true ...            01/01/70 00:00      
               a correct pain in the gluteus maximus            01/01/70 00:00      
                  Why so much pain?            01/01/70 00:00      
               An exercise for the student            01/01/70 00:00      
               everyone else            01/01/70 00:00      
   Does the LCD Work?            01/01/70 00:00      
      LCD is fine            01/01/70 00:00      

Back to Subject List