標題: 級聯(lián)74HC165,單片機讀數(shù)據(jù)不正常的問題 [打印本頁]

作者: arronfive    時間: 2018-7-10 08:20
標題: 級聯(lián)74HC165,單片機讀數(shù)據(jù)不正常的問題
unsigned char key_data_hc165[2];
void HC165_Init(unsigned char *str,unsigned char n)
{
    unsigned char i,j,tmp;
  
        KEY_STB = 0;      //read all the data to the latch
        _nop_();
        _nop_();
        KEY_STB = 1;
        delay_ms(1);
        KEY_CLK = 0;

        for(j = 0;j < n;j++)
        {
                tmp = 0;
                for(i=0; i<8; i++)
                {
                        tmp<<=1;      //left shift 1 bit
                        tmp|=KEY_DATA1;
               
                        KEY_CLK=0;                //CLK set zero
                        _nop_();                         //risiing edge
                        _nop_();
                        KEY_CLK=1;               //CLK set one  
                        _nop_();
                }
                *str++=tmp;
        }        
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1