Uživatel:Matallui

Z MAM wiki

Přejít na: navigace, hledání

[editovat] Keyboard Detection

Authors: Luís Taniça, Nikita Kuzmin

Matrix keyboard looks like this:


It can be connected like this:

Soubor:IC-matrix keyb.png


In our case it was used ATtiny2313

Connections:

 Row1 - D1
 Row2 - D2
 Row3 - D3
 Row4 - D4
 Col1 - B2
 Col2 - B3
 Col3 - B4
 Col4 - B5

Soubor:ATtiny2313.png

In order to detect wich key is being pressed it was used:

 R20 - Row
 R21 - Column


Code:

	.EQU PINB = $16		; PINB address
	.EQU DDRB = $17		; DDRB address
	.EQU PORTB = $18	; PORTB address
	.EQU PIND = $10		; PIND address
	.EQU DDRD = $11		; DDRB address
	.EQU PORTD = $12	; PORTB address

	; PORT D
	.EQU ROW1 = 1
	.EQU ROW2 = 2
	.EQU ROW3 = 3
	.EQU ROW4 = 4
	; PORT B
	.EQU LED_X = 0		; LED_X is on PB0, pin 12 of ATtiny2313
	.EQU LED_Y = 1
	.EQU COL1 = 2
	.EQU COL2 = 3
	.EQU COL3 = 4
	.EQU COL4 = 5

	; R20 KEEPS ROW
	; R21 KEEPS COL

	; Pins connected do led are outputs, DDRx=1 (set)
	SBI DDRB, LED_X	; output
	SBI DDRB, LED_Y	; output

	CBI DDRD, ROW1	; input
	CBI DDRD, ROW2	; input
	CBI DDRD, ROW3	; input
	CBI DDRD, ROW4	; input

	CBI DDRB, COL1	; input
	CBI DDRB, COL2	; input
	CBI DDRB, COL3	; input
	CBI DDRB, COL4	; input

	SBI PORTB, COL1	; with pull-up R
	SBI PORTB, COL2	; with pull-up R
	SBI PORTB, COL3	; with pull-up R
	SBI PORTB, COL4	; with pull-up R


START:
	LDI R21, 0; ROW1
	LDI R22, 0; ROW2
	LDI R23, 0; ROW3
	LDI R24, 0; ROW4

	;IN R20, PIND

HOP:
	SBI DDRD, ROW1
	CBI PORTD, ROW1
	RCALL TESTCOL1
	CBI DDRD, ROW1
	SBI PORTD, ROW1

	SBI DDRD, ROW2
	CBI PORTD, ROW2
	RCALL TESTCOL2
	CBI DDRD, ROW2
	SBI PORTD, ROW2

	SBI DDRD, ROW3
	CBI PORTD, ROW3
	RCALL TESTCOL3
	CBI DDRD, ROW3
	SBI PORTD, ROW3

	SBI DDRD, ROW4
	CBI PORTD, ROW4
	RCALL TESTCOL4
	CBI DDRD, ROW4
	SBI PORTD, ROW4

	RJMP START

TESTCOL1:
	LDI R16, 0X01
	SBIS PINB, COL1
	OR R21, R16
	LDI R16, 0X02
	SBIS PINB, COL2
	OR R21, R16
	LDI R16, 0X04
	SBIS PINB, COL3
	OR R21, R16
	LDI R16, 0X08
	SBIS PINB, COL4
	OR R21, R16
	RET

TESTCOL2:
	LDI R16, 0X01
	SBIS PINB, COL1
	OR R22, R16
	LDI R16, 0X02
	SBIS PINB, COL2
	OR R22, R16
	LDI R16, 0X04
	SBIS PINB, COL3
	OR R22, R16
	LDI R16, 0X08
	SBIS PINB, COL4
	OR R22, R16
	RET

TESTCOL3:
	LDI R16, 0X01
	SBIS PINB, COL1
	OR R23, R16
	LDI R16, 0X02
	SBIS PINB, COL2
	OR R23, R16
	LDI R16, 0X04
	SBIS PINB, COL3
	OR R23, R16
	LDI R16, 0X08
	SBIS PINB, COL4
	OR R23, R16
	RET

TESTCOL4:
	LDI R16, 0X01
	SBIS PINB, COL1
	OR R24, R16
	LDI R16, 0X02
	SBIS PINB, COL2
	OR R24, R16
	LDI R16, 0X04
	SBIS PINB, COL3
	OR R24, R16
	LDI R16, 0X08
	SBIS PINB, COL4
	OR R24, R16
	RET


Image from Seminar:

Osobní nástroje