BigEd wrote:
Are you sure your inputs are set to be inputs and are not driving a value?
Don't think so. I've double checked the wiring and this is my defintions for the ports/pins on the AVR:
Code:
// 0=input, 1=output
// rows (PD pins 4-7), columns PD, pins 0-3)
DDRD = 0b11110000; // port D, set to 4-7 (output), 0-3 (input)
PORTD = 0xff; // port D, pins 4-7 output 1111, pull ups enabled for pins 0-3
// VIA pins (lower nibble=PC, pins 3 to 0 (reversed), upper nibble=PB6 (bit4), PB2 (bit5), PB1 (bit6), PB0 (bit7)
DDRC = 0xff; // port C, set to output
PORTC = 0x0; // port C, pull ups disabled
DDRB = 0xff; // port B, set to output
PORTB = 0; // port B, pull ups disabled
The "good" news is that I now get the short6 circuit issue when more than one key is pressed when they're on different rows
.
I'll put in the tristating for the rows.
[edit]
Here we go. This works fine and no need for those diodes. Still puzzled as to why they don't work though...
Code:
unsigned char scanKbd(void)
{
// ensure that
//PORTD = 0xff;
unsigned char scanresult;
scanresult = 0;
for (int row=4;row<=7;row++)
{
KYBD_bit_set(DDRD, KYBD_bit(row)); // set row as output
KYBD_bit_clear(PORTD, KYBD_bit(row));
for (int col=0;col<=3;col++)
{
if (KYBD_bit_get(PIND, KYBD_bit(col))==0)
{
KYBD_bit_set(scanresult, KYBD_bit(col));
KYBD_bit_set(scanresult, KYBD_bit(row));
}
}
KYBD_bit_set(PORTD, KYBD_bit(row));
KYBD_bit_clear(DDRD, KYBD_bit(row)); // set row as input (disable it)
}
return(scanresult);
}