#includereg52.h#includeMATH.H#includeINTRINS.Htypedefunsignedcharuchar;typedefunsignedintuint;#defineP_262P1//口线连线(从高到低):A3,A2,A1,A0,D1,D0,Wr,_sbitP_wr=P_262^1;sbitFclk_S2=P2^2;//CPLD选择Fclk控制线sbitFclk_S1=P2^1;sbitFclk_S0=P2^0;sbitPFS0=P2^3;//工作模式工作模式选择0sbitPFS1=P2^4;//工作模式工作模式选择1longFLCK=1000000;//MAX262工作频率ucharMod=2;//工作模式0,1,2,3#definePI3.1415926#definedelay_262()_nop_();_nop_();_nop_()voiddelay(unsignedintd){unsignedcharj;while(d!=0){d--;j=70;do{j--;}while(j!=0);}}//***************************************************************//写两比特的数据voidwrite(ucharadd,uchardat2bit){P_262=(P_262&0x0f)|(add4);P_262=(P_262&0xf3)|((dat2bit2)&0x0c);P_wr=0;delay_262();P_wr=1;delay_262();}//**************************************************************//设置A通道工作模式voidSet_AM(ucharmod){write(0,mod);}//设置A通道F值voidSet_AF(uchardatF){write(1,datF);datF=datF2;write(2,datF);datF=datF2;write(3,datF);}//设置A通道Q值voidSet_AQ(uchardatQ){write(4,datQ);datQ=datQ2;write(5,datQ);datQ=datQ2;write(6,datQ);datQ=(datQ2)&1;write(7,datQ);}//设置B通道工作模式voidSet_BM(ucharmod){write(8,mod);}//设置A通道F值voidSet_BF(uchardatF){write(9,datF);datF=datF2;write(10,datF);datF=datF2;write(11,datF);}//设置A通道Q值voidSet_BQ(uchardatQ){write(12,datQ);datQ=datQ2;write(13,datQ);datQ=datQ2;write(14,datQ);datQ=(datQ2)&1;write(15,datQ);}//***************************************************************//基本计算//***************************************************************//根据截止频率fc计算中心频率f0///*ucharCopF0(floatq,floatfc){q=pow(q,2);q=(float)q*2;q=(float)(q-1)/q;//1-(1/q)fc=(float)fc*sqrt(sqrt(1+pow(q,2))-q);}floatCopF0_tx(floatq,floatfc){q=pow(q,2);q=(float)q*2;q=(float)(q-1)/q;//1-(1/q)fc=fc*sqrt(sqrt(1+pow(q,2))+q);}*///根据中心频率求设定值FNfloatCopFn(ucharmod,floatf0){if(1==mod){return((float)((FLCK*2.8284271247/f0)/PI)-26);}else{return((float)((FLCK*2/f0)/PI)-26);}}//根据Q求设定值QNucharCopQn(ucharmod,floatq){if(1==mod){return(128-(float)(90.51/q));}else{return(128-(float)(64/q));}}//***************************************//功能接口函数//设定频率Set_F0(ucharmod,floatf0){if(f028612){Fclk_S2=0;Fclk_S1=0;Fclk_S0=0;//Fclk4MFLCK=4000000;}elseif(f014306){Fclk_S2=0;Fclk_S1=0;Fclk_S0=1;//Fclk2MFLCK=2000000;}elseif(f07153){Fclk_S2=0;Fclk_S1=1;Fclk_S0=0;//Fclk1MFLCK=1000000;}elseif(f03683){Fclk_S2=0;Fclk_S1=1;Fclk_S0=1;//Fclk512KFLCK=512000;}elseif(f01831){Fclk_S2=1;Fclk_S1=0;Fclk_S0=0;//Fclk256FLCK=256000;}else{Fclk_S2=1;Fclk_S1=0;Fclk_S0=1;//Fclk128FLCK=128000;}Set_AF(CopFn(mod,f0));Set_BF(CopFn(mod,f0));}//设置滤波器模式,0为底通、1为高通、2为带通Set_PFmod(ucharmod){if(mod3){switch(mod){case0:PFS1=0;PFS0=0;Mod=0;break;case1:PFS1=0;PFS0=1;Mod=2;break;case2:PFS1=1;PFS0=0;Mod=0;break;}Set_AM(Mod);Set_BM(Mod);}}//uintTx;floatTx;voidmain(void){/*Tx=CopFn(Mod,120048);Tx=CopQn(Mod,1);Tx=CopF0(0.7,60000);Tx=CopF0_tx(0.7,Tx);*/delay(10000);delay(10000);delay(10000);Set_AM(Mod);Set_AQ(CopQn(Mod,1));Set_BM(Mod);Set_BQ(CopQn(Mod,1));//Set_AF(CopFn(Mod,5000));//Set_BF(CopFn(Mod,5000));Set_PFmod(2);Set_F0(Mod,8000);for(;;);}