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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/15/06 04:24
Read: times


 
#124339 - more Informative code
Responding to: ???'s previous message
Hello All,

I have commnted the code in more expressive way

SCAN_MATRIX_KEYBORAD Subroutine is to find whhether any column is low or not. If yes then jump to AHEAD subroutine.

AHEAD Subroutine is to find any row is low ot not. If any row is low then jump to PROCESS SCAN.

PROCESS_SCAN subroutine is to check last time whethere any column is low or not. If yes then jump to ROW_SCAN_1.

ROW_SCAN_1 subroutine is to check whether the 1st row is low or not. If it is the case then jump to ROW_1 and get the corresponding value of row in dptr which is in the form of LOOKUP TABLE.

If still there is a probs in getting the code. Revrt me with the probs.

regards
AS

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

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

PROCESS_SCAN:
      mov    a, p1 ;get the value of keypressed in A 
      cpl    a ; compliment it and find whether actually a key is pressed or not
               ; if all the rows and coulmns are high it means no key is being pressed
      jz     SCAN_MATRIX_KEYBOARD ;if no key is pressed then jump SCAN_MATRIX_KEYBORAD
                                   ; by seeking value zero in A 
      cpl    a ; get the original value of p1
      push   acc ; preserve this value of p1
      anl    a, #0fh ;for again checking whether any coumn is low or not
      cjne   a, #0fh, ROW_SCAN_1 ; if any column is low then jump to find the corresponding row

      sjmp   SCAN_MATRIX_KEYBOARD

ROW_SCAN_1:
      pop   acc ; get the original value of keypressed again to check which row is pressed
      anl   a, #0f0h ; make higher nibbles high so that the row which is low can be trassed
                     ; as upto now it is scanned that a column is low
      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