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
總結
以上是生活随笔為你收集整理的CS5460基本读写程序(无bug版本)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jenkins 安装与使用--实例
- 下一篇: 数据库损坏的修复成功案例分享