Matrix keyboard

Z MAM wiki

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

Matrix keyboard looks like this:


It can be connected like this (you may use different microprocessor, this is just an example):

Soubor:IC-matrix keyb.png


Choose whatever microprocessor you like (among those we have), connect also some LED(s) using ideas from our previous seminar and:

  • detect and indicate that one particular key is pressed (plan your keyboard connection but at this moment you may just use one wire instead of the keyboard)
  • connect the keyboard, detect that ANY key is pressed
  • detect WHICH key is pressed


Input pins are configured by both DDRx and PORTx:

DDRx PORTx pin function
0 0 input without pull-up rezistor
0 1 input with pull-up rezistor

Good way to test input is to read PINx via SBIS or SBIC instruction.

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

	.EQU LED_X = 0		; LED_X is on PB0, pin 12 of ATtiny2313
	.EQU LED_Y = 1		; LED_Y is on PB1, pin 13 of ATtiny2313
	.EQU BUT = 5		; where button is

; Pins connected to LED are outputs, DDRx=1 (set):
	SBI	DDRB, LED_X	; SBI - Set Bit in I/O Register
	SBI	DDRB, LED_Y	; SBI - Set Bit in I/O Register

	CBI DDRD, BUT	; input
	SBI PORTD, BUT	; with pull-up r.

HOP:
	SBIS PIND, BUT
	RJMP A
	RCALL GREEN
	;..
	RJMP B
A:
	RCALL RED
	;...
B:
	RJMP HOP


RED:
	SBI	PORTB, LED_X
	CBI	PORTB, LED_Y
	RET
GREEN:
	SBI	PORTB, LED_Y
	CBI	PORTB, LED_X
	RET
Osobní nástroje