/****************************************************
PC3Á¬½ÓSH/LD--STOR£¬PC2Á¬½ÓCLK--CLK,PC4Á¬½ÓQH--DATA£¬
************************************************/
#include <iom128v.h>
#include <macros.h>
#include "config.h"
#define uchar unsigned char
#define uint unsigned int
#define nop NOP()
#define SET_LOAD PORTC |= (1<<PC3)
#define CLR_LOAD PORTC &= ~(1<<PC3)
#define SET_CLK PORTC |= (1<<PC2)
#define CLR_CLK PORTC &= ~(1<<PC2)
#define Ls165_data PINC & (1 << PINC4)
#define CLR_EAST_EN PORTB &= ~(1 << PB0)
#define SET_EAST_EN PORTB |= (1 << PB0)
uchar read_ls165[2];
//===============================================
void Read_LS165(void)
{
uchar j,i,key_code;
PORTC = 0x0c;
DDRC=0x0c;
//DDRC |= (1<<SH_LD) | (1<<CLK); //PD0,PD1 OUTPUT ,PD2 INPUT
while(1)
{
CLR_LOAD;
delay_ms(10);
SET_LOAD ;
CLR_EAST_EN;
delay_ms(1);
for(j=0;j<2;j++)
{
for(i=0;i<8;i++)
{
read_ls165[j]<<=1;
if(Ls165_data)
read_ls165[j] |=Ls165_data;
CLR_CLK;
delay_ms(1);
SET_CLK;
}
}
CLR_CLK;
delay_ms(1);
SET_CLK;
SET_EAST_EN;
}
} |