|
AD9854原理圖如下(pdf文檔清晰版請(qǐng)下載附件):
0.png (93.08 KB, 下載次數(shù): 93)
下載附件
2017-7-22 18:46 上傳
0.png (34.87 KB, 下載次數(shù): 82)
下載附件
2017-7-22 18:45 上傳
AD9854單片機(jī)源程序如下:
- //=====================================================================
- // AD9854 驅(qū)動(dòng)程序設(shè)計(jì)
- //AD9854.c
- //說明:10MHZ 有源晶振
- //=====================================================================
- #include <reg52.h>
- #include <lcd1602.h>
- #include <intrins.h>
- sfr P4 = 0xC0; //1111,1111 端口4
- sbit KEY1 = P3^5;
- sbit KEY2 = P3^4;
- sbit KEY3 = P3^3;
- sbit KEY4 = P3^2;
- unsigned char FreqWord[6]; //6個(gè)字節(jié)頻率控制字
- /*
- CLK_Set為時(shí)鐘倍頻設(shè)置,可設(shè)置4~20倍倍頻,但最大不能超過300MHZ
- Freq_mult_unsigned long和Freq_mult_doulle均為2的48次方除以系統(tǒng)時(shí)鐘,一個(gè)為長(zhǎng)整形,一個(gè)為雙精度型
- */
- #define CLK_Set 20
- const unsigned long Freq_mult_ulong = 1407375;
- const double Freq_mult_doulle = 1407374.88355328;
- //**************************修改硬件時(shí)要修改的部分********************************
- #define AD9854_DataBus P2
- #define AD9854_AdrBus P0
- sbit AD9854_RST = P3^6; //AD9854復(fù)位端口
- sbit AD9854_UDCLK = P3^7; //AD9854更新時(shí)鐘
- sbit AD9854_WR = P4^1; //AD9854寫使能,低有效
- sbit AD9854_RD = P4^2; //AD9854讀使能,低有效
- sbit AD9854_FDATA = P4^3; //AD9854 FSK,PSK控制
- sbit AD9854_OSK = P4^4; //AD9854 OSK控制端
- unsigned char flag = 1;
- unsigned int fc = 1000;
- unsigned long LFerq = 750;
- unsigned long HFerq = 1250;
- void AD9854_WR_Byte(unsigned char addr,unsigned char dat);
- void AD9854_Init(void);
- void Freq_convert(long Freq);
- void AD9854_InitFSK(void);
- void AD9854_SetFSK(unsigned long Freq1,unsigned long Freq2);
- //void delay (unsigned int us);
- void UpDisplay()
- {
- unsigned char disbuf[5];
- LCD_Write_String(0, 0, "BaseFerq M");
- LCD_Write_String(0, 1, "Now Ferq M");
- disbuf[0] = fc / 1000 + '0';
- disbuf[1] = '.';
- disbuf[2] = fc % 1000 / 100 + '0';
- disbuf[3] = fc % 100 / 10 + '0';
- disbuf[4] = fc % 10 + '0';
- disbuf[5] = 0;
- LCD_Write_String(9, 0, disbuf);
- disbuf[0] = HFerq / 1000 + '0';
- disbuf[1] = '.';
- disbuf[2] = HFerq % 1000 / 100 + '0';
- disbuf[3] = HFerq % 100 / 10 + '0';
- disbuf[4] = HFerq % 10 + '0';
- disbuf[5] = 0;
- LCD_Write_String(9, 1, disbuf);
- }
- void DownDisplay()
- {
- unsigned char disbuf[5];
- LCD_Write_String(0, 0, "BaseFerq M");
- LCD_Write_String(0, 1, "Now Ferq M");
- disbuf[0] = fc / 1000 + '0';
- disbuf[1] = '.';
- disbuf[2] = fc % 1000 / 100 + '0';
- disbuf[3] = fc % 100 / 10 + '0';
- disbuf[4] = fc % 10 + '0';
- disbuf[5] = 0;
- LCD_Write_String(9, 0, disbuf);
- disbuf[0] = LFerq / 1000 + '0';
- disbuf[1] = '.';
- disbuf[2] = LFerq % 1000 / 100 + '0';
- disbuf[3] = LFerq % 100 / 10 + '0';
- disbuf[4] = LFerq % 10 + '0';
- disbuf[5] = 0;
- LCD_Write_String(9, 1, disbuf);
- }
- void AD9854_SetSine(unsigned long Freq,unsigned int Shape)
- {
- unsigned char count;
- unsigned char Adress;
- Adress = 0x04; //選擇頻率控制字地址的初值
- Freq_convert(Freq); //頻率轉(zhuǎn)換
- for(count=6;count>0;) //寫入6字節(jié)的頻率控制字
- {
- AD9854_WR_Byte(Adress++,FreqWord[--count]);
- }
-
- AD9854_WR_Byte(0x21,Shape>>8); //設(shè)置I通道幅度
- AD9854_WR_Byte(0x22,(unsigned char)(Shape&0xff));
-
- AD9854_WR_Byte(0x23,Shape>>8); //設(shè)置Q通道幅度
- AD9854_WR_Byte(0x24,(unsigned char)(Shape&0xff));
- AD9854_UDCLK=1; //更新AD9854輸出
- AD9854_UDCLK=0;
- }
- void main()
- {
- LCD_Init();
- LCD_Clear();
- /*LCD_Write_String(0,0,"BaseFerq 0.875 M");
- LCD_Write_String(0,1,"Now Ferq 1.125 M");*/
- UpDisplay();
- AD9854_Init();
- AD9854_SetSine(HFerq * 1000,4000);
- // AD9854_SetSine(1000000,4000);
- // while(1);
- // AD9854_InitFSK();
- //
- // AD9854_SetFSK(HFerq * 1000, LFerq * 1000);
-
- // AD9854_SetFSK(1000000,1000000);
- // AD9854_FDATA = 1;
- // while(1);
- while(1)
- {
- if(!KEY1)
- {
- if (flag == 1)
- {
- AD9854_SetSine(0,0);
- //AD9854_InitFSK();
- flag = 0;
- }
- else
- {
- // AD9854_InitFSK();
- // AD9854_SetFSK(HFerq * 1000, LFerq * 1000);
- AD9854_SetSine(HFerq * 1000,4000);
- flag = 1;
- }
-
- while (!KEY1);
- }
- if (flag == 1)
- {
- if (!KEY2)
- {
- AD9854_SetSine(0,0);
- fc += 100;
- if (fc == 7900) fc = 7800;
- LFerq = fc * 3 / 4;
- HFerq = fc * 5 / 4;
- UpDisplay();
- AD9854_SetSine(HFerq * 1000,4000);
- // AD9854_InitFSK();
- // AD9854_SetFSK(HFerq * 1000, LFerq * 1000);
-
- while (!KEY2);
- }
- if (!KEY3)
- {
- AD9854_SetSine(0,0);
- fc -= 100;
- if (fc == 300) fc = 400;
- LFerq = fc * 3 / 4;
- HFerq = fc * 5 / 4;
- UpDisplay();
- AD9854_SetSine(HFerq * 1000,4000);
- // AD9854_InitFSK();
- // AD9854_SetFSK(HFerq * 1000, LFerq * 1000);
- while (!KEY3);
- }
- if (!KEY4)
- {
- //AD9854_FDATA = 1;
- AD9854_SetSine(LFerq * 1000,4000);
- DownDisplay();
- while (!KEY4);
- AD9854_SetSine(HFerq * 1000,4000);
- //AD9854_FDATA = 0;
- UpDisplay();
- }
- }
- }
- }
- //====================================================================================
- //函數(shù)名稱:void AD9854_WR_Byte(unsigned char addr,unsigned char dat)
- //函數(shù)功能:AD9854并行口寫入數(shù)據(jù)
- //入口參數(shù):addr 6位地址
- // dat 寫入的數(shù)據(jù)
- //出口參數(shù):無
- //====================================================================================
- void AD9854_WR_Byte(unsigned char addr,unsigned char dat)
- {
- AD9854_AdrBus = (addr&0x3f) | (AD9854_AdrBus&0xc0);
- AD9854_DataBus = dat;
- AD9854_WR = 0;
- AD9854_WR = 1;
- }
- //====================================================================================
- //函數(shù)名稱:void AD9854_Init(void)
- //函數(shù)功能:AD9854初始化
- //入口參數(shù):無
- //出口參數(shù):無
- //====================================================================================
- void AD9854_Init(void)
- {
- AD9854_WR=1;//將讀、寫控制端口設(shè)為無效
- AD9854_RD=1;
- AD9854_UDCLK=0;
- AD9854_RST=1; //復(fù)位AD9854
- AD9854_RST=0;
- AD9854_WR_Byte(0x1d,0x10); //關(guān)閉比較器
- AD9854_WR_Byte(0x1e,CLK_Set); //設(shè)置系統(tǒng)時(shí)鐘倍頻
- AD9854_WR_Byte(0x1f,0x00); //設(shè)置系統(tǒng)為模式0,由外部更新
- AD9854_WR_Byte(0x20,0x60); //設(shè)置為可調(diào)節(jié)幅度,取消插值補(bǔ)償
- AD9854_UDCLK=1; //更新AD9854輸出
- AD9854_UDCLK=0;
- }
- //====================================================================================
- //函數(shù)名稱:void Freq_convert(long Freq)
- //函數(shù)功能:正弦信號(hào)頻率數(shù)據(jù)轉(zhuǎn)換
- //入口參數(shù):Freq 需要轉(zhuǎn)換的頻率,取值從0~SYSCLK/2
- //出口參數(shù):無 但是影響全局變量FreqWord[6]的值
- //說明: 該算法位多字節(jié)相乘算法,有公式FTW = (Desired Output Frequency × 2N)/SYSCLK
- // 得到該算法,其中N=48,Desired Output Frequency 為所需要的頻率,即Freq,SYSCLK
- // 為可編程的系統(tǒng)時(shí)鐘,F(xiàn)TW為48Bit的頻率控制字,即FreqWord[6]
- //====================================================================================
- void Freq_convert(long Freq)
- {
- unsigned long FreqBuf;
- unsigned long Temp=Freq_mult_ulong;
- unsigned char Array_Freq[4]; //將輸入頻率因子分為四個(gè)字節(jié)
- Array_Freq[0]=(unsigned char)Freq;
- Array_Freq[1]=(unsigned char)(Freq>>8);
- Array_Freq[2]=(unsigned char)(Freq>>16);
- Array_Freq[3]=(unsigned char)(Freq>>24);
- FreqBuf=Temp*Array_Freq[0];
- FreqWord[0]=FreqBuf;
- FreqBuf>>=8;
- FreqBuf+=(Temp*Array_Freq[1]);
- FreqWord[1]=FreqBuf;
- FreqBuf>>=8;
- FreqBuf+=(Temp*Array_Freq[2]);
- FreqWord[2]=FreqBuf;
- FreqBuf>>=8;
- FreqBuf+=(Temp*Array_Freq[3]);
- FreqWord[3]=FreqBuf;
- FreqBuf>>=8;
- FreqWord[4]=FreqBuf;
- FreqWord[5]=FreqBuf>>8;
- }
- //====================================================================================
- //函數(shù)名稱:void AD9854_InitFSK(void)
- //函數(shù)功能:AD9854的FSK初始化
- //入口參數(shù):無
- //出口參數(shù):無
- //====================================================================================
- void AD9854_InitFSK(void)
- {
- AD9854_WR=1; //將讀、寫控制端口設(shè)為無效
- AD9854_RD=1;
- AD9854_UDCLK=0;
- AD9854_RST=1; //復(fù)位AD9854
- AD9854_RST=0;
- AD9854_WR_Byte(0x1d,0x10); //關(guān)閉比較器
- AD9854_WR_Byte(0x1e,CLK_Set); //設(shè)置系統(tǒng)時(shí)鐘倍頻
- AD9854_WR_Byte(0x1f,0x02); //設(shè)置系統(tǒng)為模式1,由外部更新
- AD9854_WR_Byte(0x20,0x60); //設(shè)置為可調(diào)節(jié)幅度,取消插值補(bǔ)償
- AD9854_UDCLK=1; //更新AD9854輸出
- AD9854_UDCLK=0;
- }
- //====================================================================================
- //函數(shù)名稱:void AD9854_SetFSK(unsigned long Freq1,unsigned long Freq2)
- //函數(shù)功能:AD9854的FSK設(shè)置
- //入口參數(shù):Freq1 FSK頻率1
- // Freq2 FSK頻率2
- //出口參數(shù):無
- //====================================================================================
- void AD9854_SetFSK(unsigned long Freq1,unsigned long Freq2)
- {
- unsigned char count=6;
- unsigned char Adress1,Adress2;
- const unsigned int Shape=4000; //幅度設(shè)置. 為12 Bit,取值范圍為(0~4095)
-
- Adress1=0x04; //選擇頻率控制字1地址的初值
- Adress2=0x0a; //選擇頻率控制字2地址的初值
-
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
63535281AD9854-msk-for-stm32.zip
(125.05 KB, 下載次數(shù): 125)
2017-7-22 14:39 上傳
點(diǎn)擊文件名下載附件
123 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|