/*****************************************************AD9834波形产生程序*****************************************************/#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;/**************************发送控制字**************************/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;}/****************************************************初始化函数:-------------------------------------------------------------------功能:软件位控制,IOUT正弦波,SIGNBITOUT方波,写FREQREG0,写PHASE0Send_Con(0x2038) 一次性写FREQREG0Send_Con(0x0038) 单独改写FREQREG0的LSBSend_Con(0x1038) 单独改写FREQREG0的MSB-------------------------------------------------------------------功能:软件位控制,IOUT三角波写FREQREG0,写PHASE0Send_Con(0x2002) 一次性写FREQREG0Send_Con(0x0002) 单独改写FREQREG0的LSBSend_Con(0x1008) 单独改写FREQREG0的 MSB*************************//****************************发送频率字****************************/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发送相位字注:根据情况可设定入口参数,设置相位*****************************/void Send_Phase(){Send_Con(0xC000); //设置初相位为0}/*******************************************************设置频率值 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; //写FREQ0 REG 的LSBMSB_D=(value2/0x4000)+0x4000; //写FREQ0 REG 的MSBSend_Con(0x2038);
//DDS初始化设置,IOUT正弦波,SIGNBITOUT方波,一次性写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++);}}}
评论