Hans de Vries wrote: > > I've created (yet another) 4x4 matrix keyboard decode-routine. > I've placed 4 NOP's in it, because in a similar routine, they also were > there (bad reason) , but I'm not sure if they are needed. > They are there to let the output-pins when the pattern on portb is > changed. But are they nescessary? There are several factors that affect this decision, however just to be safe I would leave them in but change them to goto's: > MOVWF PORTB ;Put mask on port > NOP ;Let pins settle > NOP ;But is this nescessary?? > NOP > NOP > NOP > NOP > BTFSS PORTB,0 ;IS first bit clear? > RETURN ;Yes, so that row was pressed > MOVWF PORTB ;Put mask on port goto $+1 ;Let pins settle goto $+1 ;But is this nescessary?? goto $+1 > BTFSS PORTB,0 ;IS first bit clear? > RETURN ;Yes, so that row was pressed So you get the same delay for half the instructions. Another trick to get the 6-cycle delay is to do this: > MOVWF PORTB ;Put mask on port CALL a_return ;Let pins settle goto $+1 ;But is this nescessary?? > BTFSS PORTB,0 ;IS first bit clear? a_return: RETURN ;Yes, so that row was pressed If you have other delays then they can be grouped together: delay_6: NOP delay_5: NOP delay_4: RETURN And then if you need a delay of 6 cycles, just add a 'CALL delay_6' > MOVWF PORTB ;Put mask on port CALL delay_6 ;Let pins settle ;But is this nescessary?? > BTFSS PORTB,0 ;IS first bit clear? > RETURN ;Yes, so that row was pressed Payson posted something similar to this a good while back. Perhaps you care to elaborate John? Scott