读控制寄存器也是错误的,可是我看了感觉时序什么的都是对的
以下是我写控制寄存器的程序:
void WriteREG(unsigned long int puke) //0x209022激活自校准模式 this sub function is to write 24bit data to register
{
unsigned int flag = 0;
unsigned int ShiftFlag = 0x0080;
unsigned int High8 = 0, Low16 = 0, ShiftData = 0;
int i = 0;
High8 = (puke & 0x00FF0000)>>16;
Low16 = puke & 0x0000FFFF;
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFFE; //set SCLK low
*P_IOA_Buffer = *P_IOA_Buffer | 0x0010; //set TFS high
*P_IOA_Buffer = *P_IOA_Buffer | 0x0008; //RFS taken high
*P_IOA_Dir = *P_IOA_Dir | 0x0002; //to configure SDATA as ouput
*P_IOA_Attrib = *P_IOA_Attrib | 0x0002;
//start to write data to control register
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFDF; // A0 set LOW,write control reg
Delay1us();
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFEF; // TFS set low
for(i = 0; i<24; i++)
{
if(0 == i) //deal with the high 8 bit
{
ShiftFlag = 0x0080;
ShiftData = High8;
}
else if(8 == i) //deal with the low 16 bit
{
ShiftFlag = 0x8000;
ShiftData = Low16;
}
flag = ShiftData & ShiftFlag;
if(flag)
{
*P_IOA_Buffer = *P_IOA_Buffer | 0x0002;//SDATA=1 0010
// asm("INT OFF");
// Delay1us();
// asm("INT IRQ");
*P_IOA_Buffer = *P_IOA_Buffer | 0x0001;//SLCK a rising edge
// asm("INT OFF");
Delay1us();
// asm("INT IRQ");
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFFE;//SLCK a down edge
Delay1us();
}
else
{
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFFD; //SDATA=0
// asm("INT OFF");
// Delay1us();
// asm("INT IRQ");
*P_IOA_Buffer = *P_IOA_Buffer | 0x0001; //give SCLK a rising edge
// asm("INT OFF");
Delay1us();
// asm("INT IRQ");
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFFE;
Delay1us();
}
ShiftFlag = ShiftFlag >> 1;
}
*P_IOA_Buffer = *P_IOA_Buffer | 0x0010; //set TFS high
*P_IOA_Buffer = *P_IOA_Buffer | 0x0020; //set A0 high
}
读控制寄存器也是错误的,可是我看了感觉时序什么的都是对的
以下是我写控制寄存器的程序:
void WriteREG(unsigned long int puke) //0x209022激活自校准模式 this sub function is to write 24bit data to register
{
unsigned int flag = 0;
unsigned int ShiftFlag = 0x0080;
unsigned int High8 = 0, Low16 = 0, ShiftData = 0;
int i = 0;
High8 = (puke & 0x00FF0000)>>16;
Low16 = puke & 0x0000FFFF;
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFFE; //set SCLK low
*P_IOA_Buffer = *P_IOA_Buffer | 0x0010; //set TFS high
*P_IOA_Buffer = *P_IOA_Buffer | 0x0008; //RFS taken high
*P_IOA_Dir = *P_IOA_Dir | 0x0002; //to configure SDATA as ouput
*P_IOA_Attrib = *P_IOA_Attrib | 0x0002;
//start to write data to control register
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFDF; // A0 set LOW,write control reg
Delay1us();
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFEF; // TFS set low
for(i = 0; i<24; i++)
{
if(0 == i) //deal with the high 8 bit
{
ShiftFlag = 0x0080;
ShiftData = High8;
}
else if(8 == i) //deal with the low 16 bit
{
ShiftFlag = 0x8000;
ShiftData = Low16;
}
flag = ShiftData & ShiftFlag;
if(flag)
{
*P_IOA_Buffer = *P_IOA_Buffer | 0x0002;//SDATA=1 0010
// asm("INT OFF");
// Delay1us();
// asm("INT IRQ");
*P_IOA_Buffer = *P_IOA_Buffer | 0x0001;//SLCK a rising edge
// asm("INT OFF");
Delay1us();
// asm("INT IRQ");
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFFE;//SLCK a down edge
Delay1us();
}
else
{
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFFD; //SDATA=0
// asm("INT OFF");
// Delay1us();
// asm("INT IRQ");
*P_IOA_Buffer = *P_IOA_Buffer | 0x0001; //give SCLK a rising edge
// asm("INT OFF");
Delay1us();
// asm("INT IRQ");
*P_IOA_Buffer = *P_IOA_Buffer & 0xFFFE;
Delay1us();
}
ShiftFlag = ShiftFlag >> 1;
}
*P_IOA_Buffer = *P_IOA_Buffer | 0x0010; //set TFS high
*P_IOA_Buffer = *P_IOA_Buffer | 0x0020; //set A0 high
}
举报