void lcd_buttons() // read LCD switch matrix
{
char i;
data = 0; //
for(i=0; i<6; i++) // clock out six '0' bits
clock = 1; clock = 0; // to clear the '164 latches
data = 1; //
clock = 1; clock = 0; // col 0, '0001' (QA = 1)
data = 0; //
i = 0; //
if(swpin == 1) // if SW1 on Q1 pressed
i.0 = 1; //
clock = 1; clock = 0; // col 1, '0010' (QB = 1)
if(swpin == 1) // if SW2 on Q2 pressed
i.1 = 1; //
clock = 1; clock = 0; // col 2, '0100' (QC = 1)
if(swpin == 1) // if SW3 on Q3 pressed
i.2 = 1; //
clock = 1; clock = 0; // col 3, '1000' (QD = 1)
if(swpin == 1) // if SW4 on Q4 pressed
i.3 = 1; //
i ^= SwLatch; // changes (press or release)
SwLatch ^= i; // update switch state latch
i &= SwLatch; // i = "new press" bits
SwFlags ^= i; // update flag bits for Main
}