void WriteToReg(unsigned char ByteData) // write ByteData to the register
{
unsigned char temp;
int i;
AD7793_CS3=0;
temp=0x80;
for(i=0;i<8;i++)
{
if((temp & ByteData)==0)
{
AD7793_DIN=0;
}
else
{
AD7793_DIN=1;
}
AD7793_CLK=0;
Delay(10);
AD7793_CLK=1;
Delay(10);
temp=temp>>1;
}
AD7793_CS3=1;
}
void ReadFromReg(unsigned char nByte) // nByte is the number of bytes which need to be read
{
int i,j;
unsigned char temp;
AD7793_DIN=1;
AD7793_CS3=0;
temp=0;
AD7793_DOUT=1;
for(i=0; i<nByte; i++)
{
for(j=0; j<8; j++)
{
AD7793_CLK=0;
if(AD7793_DOUT==0)
{
temp=temp<<1;
}
else
{
temp=temp<<1;
temp=temp+0x01;
}
delay(3);
AD7793_CLK=1;
delay(3);
}
DataRead=temp;
temp=0;
}
AD7793_CS3=1;
}
这个是官方的读写例程,跟我的读写出来的数据也是一样的
|