void HC165_readSerialData(uint8_t serial_data[])
{
uint8_t buttons[2] = {0, 0};
uint8_t i,j;
uint8_t _byte;
/* Pulse LD low and then high to load parallel data */
PORTC.3=0;//LD_LOW;
delay_ms(1);
PORTC.3=1;//LD_HIGH;
/* For each '165... */
for (i = 0; i <= 2; i++)
{
_byte = 0;
/* ...read the serial out data */
for (j =0; j <= 7; j++) {
_byte <<= 1; //shifts a reasonably expensive,so we only do one shift per loop
if (PIND.5 & (1<<QH_PIN))
{
_byte |=1; //then we conditionally set the lsb
}
PORTD.7=0;//CLKINH_LOW;
delay_ms(1);
PORTD.7=1;//CLKINH_HIGH;
if(PIND.5==0)
{
LCDprint("0");
delay_ms(10);
}
else if(PIND.5==1)
{
LCDprint("1");
delay_ms(10);
}
}
serial_data[I] = _byte;
}
/* Disable clocking now */
CLKINH_HIGH; //got me beat why you need to inhibit the clock - I'd just tie it low and save a port pin
}
uint8_t buttons[2] = {0, 0};
int i=0;unsigned char out;unsigned char data; // uint8_t register_value;
void main(void)
{
DDRA=0xff;
DDRB=0xff;
DDRC=0b00001100;
DDRD=0b11011111;
// PORTB.4=0; //buzer
// delay_ms(200);
PORTB.4=1;
PORTA.7=1;
PORTA.1=0;
PORTC.2=0;
SET_HC165_DDR;
SET_QH_PULLUP;
LCDinit();
delay_ms(10);
LCDcmd(0x01);
while(1)
{
HC165_readSerialData(buttons);
delay_ms(1000);
LCDcmd(0x01);
delay_ms(1000);
}
}