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

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

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

  • #include.h>
  • 从串中取下一个数字(左->
  • 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--);
    }
    delay_ms(uint x)
    {
    uint i;
    while(x--)for(i=0;i<120;i++);
    }
    //初始化A7105
    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);
    }
    //复位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写数据
    void A7105_Write_Register(uchar addr,uchar value)
    {
    SCS=0;
    addr|=0x00;
    Write_Register(0x08,addr);
    Write_Register(0x08,value);
    SCS=1;
    }
    //A7105读数据
    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读取数据
    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校准
    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)
    {
    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]);
    }
    //主函数
    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否则对不上码

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

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

    网站地图

    Top