RM-yahoo-544

Name: Mr. Ramakrishna Movva
Web Site:

3 x 4 keypad source code

This is code for 4 io's for a 3 x 4 keypad based on Mike Rigby Jones Circuit with four diodes. This code works fine on the 877 and gives hex number 1 to 12 for each key. The logic is the same as the original code but avoids tables to make it more sturdy

start: 
bsf STATUS,RP0 bcf option_reg,not_rbpu bcf STATUS,RP0 clrf PORTB call LCD_Clr

find_key
call scan movf keycode,w xorlw 0x00 btfsc status,z goto find_key movf keycode,w call LCD_HEX key_off call scan movf keycode,w xorlw 0x00 btfsc status,z goto find_key goto key_off scan: movlw B'00001110' movwf PORTB bsf STATUS,RP0 ; bank 1 movwf TRISB ; turn B0 to an output (low) bcf STATUS,RP0 ; bank 0 movf PORTB,W ; get port b state andlw 0x0f ; mask lower nibble movwf keys xorlw B'00001110' btfsc status,z goto row2 row1_1 movf keys,w xorlw 0x0C btfss status,Z goto row1_2 movlw 0x0A movwf keycode return row1_2 movf keys,w xorlw 0x08 btfss status,Z goto row1_3 movlw 0x0B movwf keycode return row1_3 movf keys,w xorlw 0x0A btfss status,Z goto no_key movlw 0x0C movwf keycode return row2 movlw B'00001101' movwf PORTB bsf STATUS,RP0 ; bank 1 movwf TRISB ; turn B0 to an output (low) bcf STATUS,RP0 ; bank 0 movf PORTB,W ; get port b state andlw 0x0f movwf keys xorlw B'00001101' btfsc status,z goto row3 row2_1 movf keys,w xorlw 0x0C btfss status,Z goto row2_2 movlw 0x07 movwf keycode return row2_2 movf keys,w xorlw 0x09 btfss status,Z goto row2_3 movlw 0x08 movwf keycode return row2_3 movf keys,w xorlw 0x08 btfss status,Z goto no_key movlw 0x09 movwf keycode return row3 movlw B'00001011' movwf PORTB bsf STATUS,RP0 ; bank 1 movwf TRISB ; turn B0 to an output (low) bcf STATUS,RP0 ; bank 0 movf PORTB,W ; get port b state andlw 0x0f ; mask lower nibble movwf keys xorlw B'00001011' btfsc status,z goto row4 row3_1 movf keys,w xorlw 0x08 btfss status,Z goto row3_2 movlw 0x04 movwf keycode return row3_2 movf keys,w xorlw 0x09 btfss status,Z goto row3_3 movlw 0x05 movwf keycode return row3_3 movf keys,w xorlw 0x0A btfss status,Z goto no_key movlw 0x06 movwf keycode return row4 movlw B'00000111' movwf PORTB bsf STATUS,RP0 ; bank 1 movwf TRISB ; turn B0 to an output (low) bcf STATUS,RP0 ; bank 0 movf PORTB,W ; get port b state andlw 0x0f ; mask lower nibble movwf keys xorlw B'00000111' btfsc status,z goto no_key row4_1 movf keys,w xorlw 0x04 btfss status,Z goto row4_2 movlw 0x01 movwf keycode return row4_2 movf keys,w xorlw 0x01 btfss status,Z goto row4_3 movlw 0x02 movwf keycode return row4_3 movf keys,w xorlw 0x02 btfss status,Z goto no_key movlw 0x03 movwf keycode return no_key clrf keycode return END