Kod: Zaznacz cały
void keyb_check(void)
{
uint8_t i, j, key;
shift_reg_load();
key=7;
for (i=0; i < keyb_len; i++)
{
for (j=0; j<8; j++)
{
if bit_is_clear(KEYB_I, KEYB_DTA)
keyb_state[key/8] |= _BV(key % 8);
else
keyb_state[key/8] &= ~_BV(key % 8);
shift_reg_clock(1);
key--;
}
shift_reg_clock(4);
key+=12;
for (j=0; j<4; j++)
{
if bit_is_clear(KEYB_I, KEYB_DTA)
keyb_state[key/8] |= _BV(key % 8);
else
keyb_state[key/8] &= ~_BV(key % 8);
shift_reg_clock(1);
key--;
}
key+=12;
}
}
// ************************************************************************************
// Generates 'count' clock signals for the keyboard shift register
void shift_reg_clock(uint8_t count)
{
while (count--)
{
set_keyb_clk();
few_us_delay();
reset_keyb_clk();
few_us_delay();
}
}
// ************************************************************************************
// Generates a load signal for the keyboard shift register
void shift_reg_load(void)
{
KEYB_O &= ~(_BV(KEYB_LD) | _BV(KEYB_CLK));
few_us_delay();
set_keyb_ld();
few_us_delay();
set_keyb_clk();
few_us_delay();
reset_keyb_ld();
reset_keyb_clk();
few_us_delay();
}