⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adf4360.c

📁 单片机控制adf4360锁相源原代码
💻 C
字号:
          /*锁相频率源设置程序,一共12位数据控制位,fr为50MHz时,R的分频数为50,
          A的数值在0~15之间,B的数值在1~8191之间。
          14位控制位所对应的十进制数据为:Fin=[P*B+A]*(fr/R)。  P=16
          */
          #include <reg51.h>
          #include <stdio.h>
          #include <math.h>
          #include <absacc.h>

          //#define RDP0  XBYTE[0XFFFF]

            //sbit  M8 = M^7;                     /*  频率控制A的4位二进制数*/
          static unsigned long idata Low0;          /*  存储从P0口读来的低8位数值 */
          static unsigned long idata Fin0;          /*  写入pe3236的频率控制二进制数 */
          unsigned long idata mm,i;

          sbit LE=P3^0;      //L01
          sbit DAT=P3^1;
          sbit CLK=P3^2;

          sbit P33LE=P3^3;    //L02
          sbit P34DAT=P3^4;
          sbit P35CLK=P3^5;
          static unsigned long idata mul2;



    /*************************************************************
           Multiplier2函数用于计算2的幂次
   **************************************************************/
    void Multiplier2(unsigned idata n)
     {
       unsigned int i;
       mul2=1;
       for(i=0;i<n;i++)
        {mul2=mul2*2;}
     }

    /************************************************************************
    L1Code函数用于将控制和数据按照相应串口规则发送到ADF4360中的相应寄存器中。
   *************************************************************************/

     void SetControl_L1_DataCode(unsigned long int Controlcod)
   {
    unsigned short int i,s;
       LE=0;
       Multiplier2(23);
       for(i=0;i<24;i++)
       {
       DAT=Controlcod/mul2;
       CLK=0;
       CLK=1;
       s=DAT;
       Controlcod=Controlcod-s*mul2;
       Controlcod=Controlcod<<1;
       }
       LE=1;
    }

       void SetN_L1_DataCode(unsigned int Dcp3cod,unsigned long int ABcod,unsigned int P)
   {
    unsigned short int i,s;
    unsigned long int Acod,Bcod;
       Bcod=ABcod/P;
       Acod=ABcod%P;
       LE=0;
       Multiplier2(2);
       for(i=0;i<3;i++)
       {
       DAT=Dcp3cod/mul2;
       CLK=0;
       CLK=1;
       s=DAT;
       Dcp3cod=Dcp3cod-s*mul2;
       Dcp3cod=Dcp3cod<<1;
       }

       Multiplier2(12);     //13bit B counter
       for(i=0;i<13;i++)
       {
       DAT=Bcod/mul2;
       CLK=0;
       CLK=1;
       s=DAT;
       Bcod=Bcod-s*mul2;
       Bcod=Bcod<<1;
       }

       DAT=0;
       CLK=0;
       CLK=1;

       Multiplier2(4);     //5bit A counter
       for(i=0;i<5;i++)
       {
       DAT=Acod/mul2;
       CLK=0;
       CLK=1;
       s=DAT;
       Acod=Acod-s*mul2;
       Acod=Acod<<1;
       }

       DAT=1;
       CLK=0;
       CLK=1;

       DAT=0;
       CLK=0;
       CLK=1;

       LE=1;
       }

        void SetR_L1_DataCode(unsigned int Dcp8cod,unsigned long int Rcod)
   {
    unsigned short int i,s;
       LE=0;
       Multiplier2(7);
       for(i=0;i<8;i++)
       {
       DAT=Dcp8cod/mul2;
       CLK=0;
       CLK=1;
       s=DAT;
       Dcp8cod=Dcp8cod-s*mul2;
       Dcp8cod=Dcp8cod<<1;
       }

       Multiplier2(13);     //14bit R counter
       for(i=0;i<14;i++)
       {
       DAT=Rcod/mul2;
       CLK=0;
       CLK=1;
       s=DAT;
       Rcod=Rcod-s*mul2;
       Rcod=Rcod<<1;
       }

       DAT=0;
       CLK=0;
       CLK=1;

       DAT=1;
       CLK=0;
       CLK=1;

       LE=1;
       }


    /************************************************************************
    L2Code函数用于将控制和数据按照相应串口规则发送到ADF4360中的相应寄存器中。
   *************************************************************************/

     void SetControl_L2_DataCode(unsigned long int Controlcod)
   {
    unsigned short int i,s;
       P33LE=0;
       Multiplier2(23);
       for(i=0;i<24;i++)
       {
       P34DAT=Controlcod/mul2;
       P35CLK=0;
       P35CLK=1;
       s=P34DAT;
       Controlcod=Controlcod-s*mul2;
       Controlcod=Controlcod<<1;
       }
       P33LE=1;
    }

       void SetN_L2_DataCode(unsigned int Dcp3cod,unsigned long int ABcod)
   {
    unsigned short int i,s;
       P33LE=0;
       Multiplier2(2);
       for(i=0;i<3;i++)
       {
       P34DAT=Dcp3cod/mul2;
       P35CLK=0;
       P35CLK=1;
       s=P34DAT;
       Dcp3cod=Dcp3cod-s*mul2;
       Dcp3cod=Dcp3cod<<1;
       }

       Multiplier2(12);     //13bit B counter
       for(i=0;i<13;i++)
       {
       P34DAT=ABcod/mul2;
       P35CLK=0;
       P35CLK=1;
       s=P34DAT;
       ABcod=ABcod-s*mul2;
       ABcod=ABcod<<1;
       }

       for(i=0;i<6;i++)
       {
       P34DAT=0;
       P35CLK=0;
       P35CLK=1;
       }

       P34DAT=1;
       P35CLK=0;
       P35CLK=1;

       P34DAT=0;
       P35CLK=0;
       P35CLK=1;

       P33LE=1;
       }

        void SetR_L2_DataCode(unsigned idata Dcp8cod,unsigned long int Rcod)
   {
    unsigned short int i,mul,s;
       P33LE=0;
       Multiplier2(7);
       for(i=0;i<8;i++)
       {
       P34DAT=Dcp8cod/mul2;
       P35CLK=0;
       P35CLK=1;
       s=P34DAT;
       Dcp8cod=Dcp8cod-s*mul2;
       Dcp8cod=Dcp8cod<<1;
       }

       Multiplier2(13);     //14bit R counter
       for(i=0;i<14;i++)
       {
       P34DAT=Rcod/mul2;
       P35CLK=0;
       P35CLK=1;
       s=P34DAT;
       Rcod=Rcod-s*mul2;
       Rcod=Rcod<<1;
       }

       P34DAT=0;
       P35CLK=0;
       P35CLK=1;

       P34DAT=1;
       P35CLK=0;
       P35CLK=1;

       P33LE=1;
       }



    /******************************************************************
    函数原型:  void main(void)
    功    能:
    *******************************************************************/
     void main()
       {
     unsigned int i;
     unsigned char j;
     unsigned char  R=50 ;    //参考源输入分频数



     SetR_L2_DataCode(0X30,R);     //L02
     SetControl_L2_DataCode(0X0FD104);
     for(i=0;i<4000;i++)    //延时
        {}
     SetN_L2_DataCode(0,140);

     SetR_L1_DataCode(0,R);  //L01
     SetControl_L1_DataCode(0X8FE100);

     for(i=0;i<1500;i++)    //延时
        {}

      while(1)
      {
        Low0=P1;      //取P1口的数据
       Fin0=Low0*5+1080;   //频率起点为1080MHz
       SetN_L1_DataCode(0,Fin0,32);     //设置分频系数32
       for(i=0;i<10;i++)    //延时
        {}
       while(1)         //死循环
        {
          j = P1;
          if(j!=Low0)
          {
              break;
          }
        }
      }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -