Hi Guys ,

Well this keyboard matrix routine has been here a while and works well.

but if you need to place a 1 row or column port pin on another port out of sequence then you have a problem.

I face this as i changed from 16f1947 to 18f67k22 on the pcb , where the 16f1947 has portF.0 , and 18f67k22 does not
as you guessed a row pin was on Portf.0

PORTF.0 -3 was row ,portb 0-3 was column , so no problem with the column port , but row0 wont work on an non existent port
so the new row0 port was connected to a spare pin at portG.4

PortG.4 TRES direction was set to output prior to keypad.bas include used , but could have been set in in the keypad.bas section of code after the asm that sets the TRES for the colume and row ports assigned


I used the port offset value to point portG.4 , when it was selecting row0 , and set the POrtG.4 =1 prior as per steves comments
the offset value 12 is worked out 12 port locations past portF0

i also did not care if portF.0 TRES were set to output as per steves routine , but if this was an issue , removing the ASM code that sets the TRES in keypad.bas and do it as per normal would have been ok


I hope this helps someone that has a similar problem

cheers

Sheldon

Code section prior to change
=====================

Code:
ScanKeypad:
        key=0                                              ; no key is press
        row=0                                              ; begin scan @ ROW0
        col=0                                              ; and COL0
               
        kb_row_PORT=kb_row_PORT | InitialState             ; set all ROW bits to 1 using bitwise OR
        repeat                                             
            
          
              ROWBIT=ROW+KB_ROW_BIT                    ; point to a ROW bit
              kb_row_PORT.0[RowBit]=0                      ; clear actual ROW bit
after code change
==============

Code:
ScanKeypad:
        key=0                                              ; no key is press
        row=0                                              ; begin scan @ ROW0
        col=0                                              ; and COL0
        PORTG.4 = 1                                        ; Setup row-0 = 1 
        
        kb_row_PORT=kb_row_PORT | InitialState             ; set all ROW bits to 1 using bitwise OR
        repeat                                             
            
            if row = 0  then 
               Rowbit = 12                                 ; offset amount for row 0  from PortF.0 to point to PortG.4 
             else  
              ROWBIT=ROW+KB_ROW_BIT                        ; point to a ROW bit
            endif   
              kb_row_PORT.0[RowBit]=0                      ; clear actual ROW bit