/*****************************************************AD9834波形產(chǎn)生程序*****************************************************/#includeMSP430x16x.h>#define FSYNCL P2OUT = ~BIT5 #define FSYNCH P2OUT |= BIT5 #define SCLKL P2OUT = ~BIT6 #define SCLKH P2OUT |= BIT6 #define SDATAL P2OUT = ~BIT7#define SDATAH P2OUT |= BIT7double data=1000 ;#define FCLK 50#define uchar unsigned char#define uint unsigned int#define ulong unsigned longint x;/**************************發(fā)送控制字**************************/void Send_Con(uint Con_word){uchar i;FSYNCL;for(i=0;i16;i++){if ((Con_word0x8000)==0x8000){SDATAH;}elseSDATAL ;Con_word=1;SCLKL;SCLKH;}FSYNCH;}/****************************************************初始化函數(shù):-------------------------------------------------------------------功能:軟件位控制,IOUT正弦波,SIGNBITOUT方波,寫(xiě)FREQREG0,寫(xiě)PHASE0Send_Con(0x2038) 一次性寫(xiě)FREQREG0Send_Con(0x0038) 單獨(dú)改寫(xiě)FREQREG0的LSBSend_Con(0x1038) 單獨(dú)改寫(xiě)FREQREG0的MSB-------------------------------------------------------------------功能:軟件位控制,IOUT三角波寫(xiě)FREQREG0,寫(xiě)PHASE0Send_Con(0x2002) 一次性寫(xiě)FREQREG0Send_Con(0x0002) 單獨(dú)改寫(xiě)FREQREG0的LSBSend_Con(0x1008) 單獨(dú)改寫(xiě)FREQREG0的 MSB*************************//****************************發(fā)送頻率字****************************/void Send_Freq(uint Freq_word){uchar i;FSYNCL;for(i=0;i16;i++){if ((Freq_word0x8000)==0x8000){SDATAH;}elseSDATAL ;Freq_word=1;SCLKL;SCLKH;}FSYNCH;}/***************************** q發(fā)送相位字注:根據(jù)情況可設(shè)定入口參數(shù),設(shè)置相位*****************************/void Send_Phase(){Send_Con(0xC000); //設(shè)置初相位為0}/*******************************************************設(shè)置頻率值 Freq_value(value)=Freq_data(data)*FCLK/2^282^28=268435456=0x10000000*******************************************************/void zhengxianbo(ulong Freq_value ){ulong value1,value2;uint LSB_D,MSB_D;SCLKH;FSYNCH;value1= Freq_value;value2= Freq_value;LSB_D=(value1%0x4000)+0x4000; //寫(xiě)FREQ0 REG 的LSBMSB_D=(value2/0x4000)+0x4000; //寫(xiě)FREQ0 REG 的MSBSend_Con(0x2038);
//DDS初始化設(shè)置,IOUT正弦波,SIGNBITOUT方波,一次性寫(xiě)FREQREG0Send_Freq(LSB_D); Send_Freq(MSB_D);void Send_Phase();}void main(){uint n;static ulong x=0;static ulong Freq_value;WDTCTL=WDTPW+WDTHOLD;P2DIR=0Xff;while(1){for(x=0;x10;x++){if(x==9)data=1000;elsedata=data+1000*x;Freq_value=(ulong)(data*5.3687);zhengxianbo(Freq_value);for(n=0;n20000;n++);}}}
評(píng)論