微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > A7105(2.4G)与STC89C52单片机无线收发程序(发射程序)

A7105(2.4G)与STC89C52单片机无线收发程序(发射程序)

时间:11-27 来源:互联网 点击:

={20,40,80,120,160};
uchar RX_DATA_Buffer[RF_DATA_PACKET_SIZE];
const uchar code LED_BIT[]={0x00,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,
18,19,20,21,22,23,24,25,26,27,28,29,30,31,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,0x55,0xaa,0xff};
bit RX_Flag;
uchar timer,seq,Err_Hop_Ctn,timer_ctn;
uchar Read_ID[4];

void Init_A7105(void);
void A7105_Config_Chip(void);
void A7105_Calibration(void);
void A7105_Entry_Stdy(void);
void A7105_Setup_Wpll(void);
void A7105_Setup_Channel(uchar ch);
void A7105_Entry_TX(void);
void A7105_Entry_RX(void);
void A7105_Reset_Chip(void);
void A7105_Reset_RX_FIFO(void);
void A7105_Reset_TX_FIFO(void);
void Write_Register(uchar bits,uchar value);
uchar Read_Register(void);
void A7105_Write_Command(uchar cmd);
void A7105_Write_Register(uchar addr,uchar value);
uchar A7105_Read_Register(uchar addr);
void A7105_Write_ID(void);
void A7105_Read_ID(uchar *Read_Ptr);
void A7105_Write_DATA_To_FIFO(void);
void A7105_Read_DATA_From_FIFO(void);
void Send_DATA_By_RF(uchar Send_Byte);
void Rec_RF_DATA(void);

void delay_us(uint x)
{
while(x--);
}

void delay_ms(uint x)
{
uint i;
while(x--)for(i=0;i<120;i++);
}

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]);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top