CS5460基本读写程序(无bug版本)

/**********************************************************************
*CS5460A写命令函数
**********************************************************************/ 
void write_command(unsigned char cs5460_command)
{ unsigned char data i;
for(i=0;i<8;i++)
{
     SDI_5460 = (bit)(cs5460_command&0x80);
       _delay_us(5);
     SCK_5460=0;
    _delay_us(5); 
        SCK_5460=1; 
    _delay_us(5);
    cs5460_command=cs5460_command<<1;
}
SCK_5460=0;  
}

/**********************************************************************
*CS5460A读函数
*写数据的时候还要写入3个NOP空位
**********************************************************************/
void cs5460_READ(unsigned char cs5460_command)
{
    unsigned char data i,j;
    unsigned char temp;
    bit c_temp;  
    write_command(cs5460_command);
    for(i=0;i<3;i++)
      {
        temp = 0xfe;
        for(j=0;j<8;j++)
             {
                SCK_5460=0;
             _delay_us(2);            
    /************下面三行必须要有,否则写入和读出的数据不正确***************/
              SDI_5460 = (bit)((temp&0x80)>>7);    //写入空数据NOP即0xfe
             c_temp = SDO_5460;                    //读数据
             rec_data[i] = rec_data[i]|c_temp;    //将数据写入全局变量中进行存储   
            if(j!=7)                              //最后一个位单独处理
              {
                rec_data[i] = rec_data[i]<<1;
                temp = temp<<1;
              }
            SCK_5460=1;
            _delay_us(2);          
          }//end for
      } //end for
  SCK_5460=0;    
}//end function

原文地址:https://www.cnblogs.com/Double0Seven/p/2553118.html