ad9850-c程序-源代碼
#include
#include
float l,m,n,q,z;
double k;?
//-----------------------定義管腳-----------------------------
#define? data_OUT P1
sbit FQ_UD=P3^0;????????? //AD9850信號更新申請
sbit W_CLK=P3^1;
sbit FESET="P3"^2;????????? //寫控制字時鐘
unsigned char CON_word[5];
//Word data[7] data[6] data[5] data[4] data[3] data[2] data[1] data[0]
//W0? Phase b? Phase b3? Phase b2? Phase b1 Phase b0? Power Down? Control???? Control
//W1 Freq-b31??? Freq-b30 Freq-b29 Freq-b28 Freq-b27 Freq-b26 Freq-b25 Freq-b24
//W2 Freq-b23 Freq-b22 Freq-b21 Freq-b20 Freq-b19 Freq-b18 Freq-b17 Freq-b16
//W3 Freq-b15 Freq-b14 Freq-b13 Freq-b12 Freq-b11 Freq-b10 Freq-b9????? Freq-b8
//W4 Freq-b7???? Freq-b6???? Freq-b5???? Freq-b4???? Freq-b3???? Freq-b2?
//--------------------------------------------------------------------------------------------------
// 函數名稱: delay
// 入口參數: N
// 函數功能:延時子程序,實現(16*N+24)us的延時
// 系統采用11.0592MHz的時鐘時,延時滿足要求,其它情況需要改動
//--------------------------------------------------------------------------------------------------
?// void delay(unsigned? int N)?
?// {
?// int i;
? //for(i=0;i // }
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
?/*******************************************************/
?? void Freq_Adjust(long value_Freq)
{?
??? unsigned int i;
?? long f;
?unsigned char L4,L3,L2,L1,L0;
?? FQ_UD=0;
??? f="value"_Freq*86;
??? L0=0x28;
??? L4= f&0x000000ff;
??? L3=(f>>8)&0x000000ff;
??? L2=(f>>16)&0x000000ff;
??? L1=(f>>24)&0x000000ff;
?? CON_word[0]=L0;
?? CON_word[4]=L4;
?? CON_word[3]=L3;
?? CON_word[2]=L2;
?? CON_word[1]=L1;
???? FQ_UD=0;
???? W_CLK=0;
? //delay(0);
? _nop_(); _nop_(); _nop_();? _nop_(); _nop_();
? CON_word[0]=CON_word[0]&0xFC;?? //置工作方式選擇位為00
???? for(i=0;i<5;i++)
???? {?
? FESET="1";
? W_CLK=0;
???? data_OUT=CON_word[i];????? //送控制字
??? // delay(0);
?_nop_(); _nop_(); _nop_(); _nop_();_nop_();
? FESET="0";
???? W_CLK=1;?????????????????? //上升延
???? //delay(0);
? _nop_(); _nop_(); _nop_();_nop_();_nop_();
???? }
???? FQ_UD=1;
?
}
//-------------------------------------------------------------------------------
// 函數名稱:main
// 用戶主函數
// 函數功能:主函數
//-------------------------------------------------------------------------------
main()
{
??? BEGAIN:
?LCD_Initial();
?P2=0XF0;
?GotoXY(0,0);
??? Print("Please Input :");
?GotoXY(0,1);
?Print("????????????? ");
?m=0;
?k=0;
?l=0;
?//q=5;
? FQ_UD=0;?
??? Freq_Adjust(50000);
??? while(1)
? {?
????? while(1)
????? {?
?
??? m="keynum"();
??? if(m>=0&&m<=9||m==15||m==14)
????? {
????? z="m";
?? Delay1ms(150);
?? break;
??? }
??? }
???? if(m>=0&&m<=9)
????? {
??? l++;
?? }
??
??? if(z==14)
????? {
???? goto? BEGAIN;
?? }
??? if(z==15)
??? {
???? GotoXY(0,1);
???? Print(&TempBuffer[0]);
???? GotoXY(9,1);
???? Print("OK!!");
???? Delay1ms(1000);
???? break;
??? }
??????
???? if(l==1)
????? {k=z;}
???? if(l==2)
????? {
??? k="k"*10+z;
?? }
?
???? if(l==3)
????? {
???? k="k"*10+z;
??? }
??? if(l==4)
??? {?
??? k="k"*10+z;
??? }
??? if(l==5)
??? {?
??? k="k"*10+z;
??? }
???? if(l==6)
??? {?
??? k="k"*10+z;
??? }
???? if(l==7)
??? {?
??? k="k"*10+z;
??? }
???? if(l==8)
??? {?
??? k="k"*10+z;
??? }
??
???? if(l>8||k>25000000)
???? {
??????? GotoXY(0,1);
??????? Print("???? ERROR!!????? ");
???? Delay1ms(500);
??????? goto? BEGAIN;
????? }
??
?? IntToStr(k,&TempBuffer[0],0);
?? GotoXY(0,1);
?? Print(&TempBuffer[0]);
???????? P2=0XF0;
?? Delay1ms(150);???
??? }
?FQ_UD=0;
?Freq_Adjust(k);
?while(1)
?{
?
?GotoXY(0,0);
?Print("THE PL DISPLAY");
?IntToStr(k,&TempBuffer[0],0);
?GotoXY(0,1);
?Print(&TempBuffer[0]);
??????? m="keynum"();
?????? if(m==10)
???? { Delay1ms(300) ;
???? if(k>=30000000){k=30000000;}
??? else{ k="k"+1000;}
???? }
???? if(m==11)
???? {Delay1ms(300) ;
????? if(k<=0){k=0;}
?????? else{k=k-1000;}
???? }
??????? if(m==14)
????? {
?? goto? BEGAIN;
?? }
?
??? }
}
AD9850內含可編程DDS系統和高速比較器,能實現全數字編程控制的頻率合
成??删幊藾DS系統的核心是相位累加器,它由一個加法器和一個N位相位寄
存器組成,N一般為24~32。每來一個外部參考時鐘,相位寄存器便以步長M
遞加。相位寄存器的輸出與相位控制字相加后可輸入到正弦查詢表地址上。正
弦查詢表包含一個正弦波周期的數字幅度信息,每一個地址對應正弦波中0°~3
60°范圍的一個相位點。
評論
查看更多