//設(shè)置為接收模式
void A7105_Entry_RX(void)
{
A7105_Write_Command(CMD_RX);
}
//設(shè)置為發(fā)射模式
void A7105_Entry_TX(void)
{
A7105_Write_Command(CMD_TX);
}
//復(fù)位A7105
void A7105_Reset_Chip(void)
{
A7105_Write_Register(MODE_REG,0x00);
}
void A7105_Reset_RX_FIFO(void)
{
A7105_Write_Command(CMD_RX_FIFO_RESET);
}
void A7105_Reset_TX_FIFO(void)
{
A7105_Write_Command(CMD_TX_FIFO_RESET);
}
//寫寄存器
void Write_Register(uchar bits,uchar value)
{
uchar i;
for(i=0;i{
if(value&0x80)
SDIO=1;
else
SDIO=0;
SCK=1;
SCK=0;
value<<=0x01;
}
}
//讀寄存器
uchar Read_Register(void)
{
uchar i,temp=0;
SDIO=1;
for(i=0;i<8;i++)
{
if(SDIO)
temp=(temp<<1)|0x01;
else
temp<<=0x01;
SCK=1;
SCK=0;
}
return temp;
}
//A7105寫指令
void A7105_Write_Command(uchar cmd)
{
SCS=0;
Write_Register(0x04,cmd);
SCS=1;
}
//A7105寫數(shù)據(jù)
void A7105_Write_Register(uchar addr,uchar value)
{
SCS=0;
addr|=0x00;
Write_Register(0x08,addr);
Write_Register(0x08,value);
SCS=1;
}
//A7105讀數(shù)據(jù)
uchar A7105_Read_Register(uchar addr)
{
uchar temp=0;
SCS=0;
addr|=0x40;
Write_Register(0x08,addr);
temp=Read_Register();
SCS=1;
return temp;
}
//A7105寫ID
void A7105_Write_ID(void)
{
SCS=0;
Write_Register(0x08,ID_DATA_REG);
Write_Register(0x08,ID_CODE0);
Write_Register(0x08,ID_CODE1);
Write_Register(0x08,ID_CODE2);
Write_Register(0x08,ID_CODE3);
SCS=1;
A7105_Read_ID(Read_ID);
}
//A7105讀ID
void A7105_Read_ID(uchar *read_prt)
{
SCS=0;
Write_Register(0x08,(ID_DATA_REG|0x40));
SDIO=1;
*read_prt++=Read_Register();
*read_prt++=Read_Register();
*read_prt++=Read_Register();
*read_prt++=Read_Register();
SCS=1;
}
//A7105從FIFO讀取數(shù)據(jù)
void A7105_Read_DATA_From_FIFO(void)
{
uchar i,temp=0;
SCS=0;
Write_Register(0x08,FIFO_DATA_REG|0x40);
for(i=0;iRX_DATA_Buffer[i]=Read_Register();
SCS=1;
}
//A7105校準(zhǔn)
void A7105_Calibration(void)
{
uchar temp;
uchar fb,fbcf;
A7105_Entry_Stdy();//校準(zhǔn)必須在待機(jī)模式下進(jìn)行
A7105_Write_Register(CALIBRATION_REG,0x01);
do
{
temp=A7105_Read_Register(CALIBRATION_REG);
temp&=0x01;
}while(temp);
temp=A7105_Read_Register(IF_CALIBRATION1_REG);
fb=temp&0x0f;
fbcf=(temp>>4)&0x01;
if(fbcf==1)
{
LED=0;
}
A7105_Write_Register(VCO_CURRENT_CAL_REG,0x13);
A7105_Write_Register(VCO_SINGLE_BAND_CAL1_REG,0x09);
}
//配置A7105
void A7105_Config_Chip(void)
{
uchar i;
//0x00 mode register, for reset
//0x05 fifo data register
//0x06 id code register
//0x23 IF calibration II, only read
//0x32 filter test register
for(i=0x01;i<=0x04;i++)
A7105_Write_Register(i,A7105_Default_Par[i]);
for(i=0x07;i<=0x22;i++)
A7105_Write_Register(i,A7105_Default_Par[i]);
for(i=0x24;i<=0x31;i++)
A7105_Write_Register(i,A7105_Default_Par[i]);
}
//主函數(shù)
void main(void)
{
uchar i;
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
Init_A7105();
delay_ms(500);
A7105_Entry_Stdy();
while(1)
{
A7105_Setup_Channel(100-1);//接收頻率必須減1否則對(duì)不上碼
A7105_Setup_Wpll();
A7105_Entry_RX();
delay_us(150);
while(GPIO1);
//P0=A7105_Read_Register(0x03);
A7105_Read_DATA_From_FIFO();
for(i=0;i<64;i++)
{
P0=RX_DATA_Buffer[i];
delay_ms(300);
}
A7105_Entry_Stdy();
}
}
評(píng)論