Skip to content

Instantly share code, notes, and snippets.

/gist:c241385cfbe34e8ac454 Secret

Created Apr 16, 2015
Embed
What would you like to do?
/* Column pin configuration
* col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
* pin: B4 B5 B6 F7 F6 F5 B0 B1 B2 B3 B7 D0 D1 C6 C7
*/
static void init_cols(void)
{
// Input with pull-up(DDR:0, PORT:1)
DDRF &= ~(1<<7 | 1<<6 | 1<<5);
PORTF |= (1<<7 | 1<<6 | 1<<5);
DDRD &= ~(1<<1 | 1<<0);
PORTD |= (1<<1 | 1<<0);
DDRC &= ~(1<<7 | 1<<6);
PORTC |= (1<<7 | 1<<6);
DDRB &= ~(1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
PORTB |= (1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
}
static matrix_row_t read_cols(void)
{
return (PINB&(1<<4) ? 0 : (1<<0)) |
(PINB&(1<<5) ? 0 : (1<<1)) |
(PINB&(1<<6) ? 0 : (1<<2)) |
(PINF&(1<<7) ? 0 : (1<<3)) |
(PINF&(1<<6) ? 0 : (1<<4)) |
(PINF&(1<<5) ? 0 : (1<<5)) |
(PINB&(1<<0) ? 0 : (1<<6)) |
(PINB&(1<<1) ? 0 : (1<<7)) |
(PINB&(1<<2) ? 0 : (1<<8)) |
(PINB&(1<<3) ? 0 : (1<<9)) |
(PINB&(1<<7) ? 0 : (1<<10)) |
(PIND&(1<<0) ? 0 : (1<<11)) |
(PIND&(1<<1) ? 0 : (1<<12)) |
(PINC&(1<<6) ? 0 : (1<<13)) |
(PINC&(1<<7) ? 0 : (1<<14));
}
/* Row pin configuration
* row: 0 1 2 3 4
* pin: D2 D3 D5 D4 D7
*/
static void unselect_rows(void)
{
// Hi-Z(DDR:0, PORT:0) to unselect
DDRD &= ~0b10111100;
PORTD &= ~0b10111100;
}
static void select_row(uint8_t row)
{
// Output low(DDR:1, PORT:0) to select
switch (row) {
case 0:
DDRD |= (1<<0);
PORTD &= ~(1<<0);
break;
case 1:
DDRD |= (1<<1);
PORTD &= ~(1<<1);
break;
case 2:
DDRD |= (1<<2);
PORTD &= ~(1<<2);
break;
case 3:
DDRD |= (1<<3);
PORTD &= ~(1<<3);
break;
case 4:
DDRD |= (1<<5);
PORTD &= ~(1<<5);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.