void Init_A7105(void)
{
SCK=0;
SDIO=1;
SCS=1;
GPIO1=1;
A7105_Reset_Chip();
//delay_us(50000);
A7105_Write_ID();
A7105_Config_Chip();
A7105_Calibration();
}
void A7105_Entry_Stdy(void)
{
A7105_Write_Command(CMD_STBY);
}
void A7105_Setup_Wpll(void)
{
A7105_Write_Command(CMD_PLL);
}
void A7105_Setup_Channel(uchar ch)
{
A7105_Write_Register(PLL1_REG,ch);
}
void A7105_Entry_RX(void)
{
A7105_Write_Command(CMD_RX);
}
void A7105_Entry_TX(void)
{
A7105_Write_Command(CMD_TX);
}
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;
value<<=0x01;
SCK=0;
}
}
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;
}
void A7105_Write_Command(uchar cmd)
{
SCS=0;
Write_Register(0x04,cmd);
SCS=1;
}
void A7105_Write_Register(uchar addr,uchar value)
{
SCS=0;
addr|=0x00;
Write_Register(0x08,addr);
Write_Register(0x08,value);
SCS=1;
}
uchar A7105_Read_Register(uchar addr)
{
uchar temp=0;
SCS=0;
addr|=0x40;
Write_Register(0x08,addr);
temp=Read_Register();
SCS=1;
return temp;
}
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);
}
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;
}
void A7105_Write_DATA_To_FIFO(void)
{
uchar i=0;
SCS=0;
Write_Register(0x08,FIFO_DATA_REG);
for(i=0;i{
LED=~LED;
Write_Register(0x08,LED_BIT[i]);
}
SCS=1;
}
void A7105_Calibration(void)
{
uchar temp;
uchar fb,fbcf;
A7105_Entry_Stdy();//校準必須在待機模式下進行
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)
{
;
}
A7105_Write_Register(VCO_CURRENT_CAL_REG,0x13);
A7105_Write_Register(VCO_SINGLE_BAND_CAL1_REG,0x09);
}
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]);
}
void main(void)
{
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
Init_A7105();
delay_ms(50);
A7105_Entry_Stdy();
A7105_Write_DATA_To_FIFO();
while(1)
{
A7105_Setup_Channel(100);
A7105_Setup_Wpll();
A7105_Entry_TX();
delay_us(150);
while(GPIO1);
}
}
評論