Ejemplo n.º 1
0
/*
 * keypad_write_cols: write all 16 column bits in 'val' to shift register.
 */
static void keypad_write_cols( short val )
{
    int i;

    for( i = 0; i < MAX_COLS; i++ )
    {
        if( val < 0 )
            data_h( );
        else
            data_l( );
        clk_h( );
        val <<= 1;
        clk_l( );
    }
}
Ejemplo n.º 2
0
void put_9200a(uint8 value)
{
	int8 i;
	
//	PORTC &= !DIAL_CS;	//put 0,enable CS
	
	for(i = 4; i >= 0 ; i--)
	{
		clk_h();
		put_value((value >> i) & 0x01);
		__delay_cycles(20);
		clk_l();
		__delay_cycles(20);
	}
	 __delay_cycles(20);
	__delay_cycles(20);
//	PORTC |= DIAL_CS;
	
}
Ejemplo n.º 3
0
/*
 * keypad_scan: perform a single scan of keyboard. Returns keycode of
 * key that was pressed (or -1 if nothing).
 */
int keypad_scan( void )
{
    int row, col;
    int pressed = -1;

    leds_off( );		// turn off LEDs during scan
    keypad_write_cols( ~1 );	// single zero at column 0
    data_h( );			// shift in ones
    for( col = 0; col < MAX_COLS; col++ )
    {
        keypad_state[col] = get_rows( );
        clk_h( );
        clk_l( );
    }
    keypad_write_cols( ~leds );
    leds_on( );

    // keyboard has been scanned, now look for pressed keys
    for( col = 0; col < MAX_COLS; col++ )
    {
        uint8_t diff = keypad_state[col] ^ keypad_prev[col];

        if( diff )
        {
            for( row = 0; row < MAX_ROWS; row++ )
            {
                uint8_t mask = 1 << row;

                if( diff & mask & keypad_state[col] )
                    pressed = row * 16 + col;
            }
        }
        keypad_prev[col] = keypad_state[col];
    }
    return pressed;
}