1699 views|0 replies

3836

Posts

19

Resources
The OP
 

Share the DDS output waveform of MSP430 controlled by sine wave and square wave C language program [Copy link]

//*******************************************************// // Subroutine description// //***************************************************// //Function 1: ad9850_reset() // Reset ad9850, then enter parallel port write mode //Function 2: ad9850_reset_serial() // Reset ad9850, then enter serial port write mode //Function 3: ad9850_wr_parrel(unsigned char w0,double frequence) // Parallel port writes ad9850 data, w0 is the data of w0 in ad9850, frequence // is the written frequency //Function 4: ad9850_wr_serial(unsigned char w0,double frequence) // Serial port writes ad9850 data, w0 is the data of w0 in ad9850, frequence // is the written frequency //Bits to be defined: //ad9850_w_clk; //ad9850_fq_up ; //ad9850_rest ; //ad9850_bit_data ; //Example: //sbit ad9850_w_clk =P2^2; //sbit ad9850_fq_up =P2^1; //sbit ad9850_rest =P2^0; //sbit ad9850_bit_data =P1^7; //***************************************************// // Write data description// //***************************************************// // Write data example: // ad9850_reset() // wr_lcd02_data(unsigned char x) // ad9850_wr_parrel(0x01,1000) // ad9850_wr_serial(0x01,1000) //***************************************************// //---------------------------------------------------// // Program// //---------------------------------------------------// # include
# include

#define ad9850_w_clk_High   P2OUT|=0x04
#define ad9850_w_clk_Low    P2OUT&=~0x04
#define ad9850_fq_up_High   P2OUT|=0x02
#define ad9850_fq_up_Low    P2OUT&=~0x02
#define ad9850_rest_High    P2OUT|=0x01
#define ad9850_rest_Low     P2OUT&=~0x01
#define ad9850_bit_data     P1OUT

//***************************************************//
//              ad9850复位(并口模式)                 //
//---------------------------------------------------//
void ad9850_reset()
{
  ad9850_w_clk_Low;
  ad9850_fq_up_Low;
  ad9850_rest_Low;
  ad9850_rest_High;
  ad9850_rest_Low;
}
//***************************************************//
//              ad9850复位(并口模式)                 //
//---------------------------------------------------//
void ad9850_reset_serial()
{
ad9850_w_clk_Low;
ad9850_fq_up_Low;
//rest信号
  ad9850_rest_Low;
  ad9850_rest_High;
  ad9850_rest_Low;
//w_clk信号
ad9850_w_clk_Low;
ad9850_w_clk_High;
ad9850_w_clk_Low;
//fq_up信号
ad9850_fq_up_Low;
ad9850_fq_up_High;
ad9850_fq_up_Low;
}
//***************************************************//
//          向ad9850中写命令与数据(并口)             //
//---------------------------------------------------//
void ad9850_wr_parrel(unsigned char w0,double frequence)
{
unsigned char w;
long int y;
double x;
//计算频率的HEX值
x=4294967295/125;//适合125M晶振
//如果时钟频率不为125MHZ,修改该处的频率值,单位MHz !!!
frequence=frequence/1000000;
frequence=frequence*x;
y=(double)frequence;
//写w0数据
w=w0;   
ad9850_bit_data=w;      //w0
ad9850_w_clk_High;
ad9850_w_clk_Low;
//写w1数据
w=(y>>24);
ad9850_bit_data=w;      //w1
ad9850_w_clk_High;
ad9850_w_clk_Low;
//写w2数据
w=(y>>16);
ad9850_bit_data=w;      //w2
ad9850_w_clk_High;
ad9850_w_clk_Low;
//写w3数据
w=(y>>8);
ad9850_bit_data=w;      //w3
ad9850_w_clk_High;
ad9850_w_clk_Low;
//写w4数据
w=(y>>=0);
ad9850_bit_data=w;      //w4
ad9850_w_clk_High;
ad9850_w_clk_Low;
//移入始能
ad9850_fq_up_High;
ad9850_fq_up_Low;
}

//***************************************************//
//                   测试程序1000Hz                  //
//---------------------------------------------------//
main()
{
   WDTCTL=WDTPW+WDTHOLD;
   P1DIR=0XFF;
   P2DIR=0XFF;
//---------------------------------------------------//
//并行写1000Hz程序
ad9850_reset();
ad9850_wr_parrel(0x00,1);
//---------------------------------------------------//
while(1)
{
}
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list