微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > MSP430控制AD9851产生扫频波

MSP430控制AD9851产生扫频波

时间:11-13 来源:互联网 点击:
#include msp430xG43x.h>

#include "DDS_DATA.H"
#define uchar unsigned char
#define uint unsigned int

#define DDS_CONTROL_PORT P5OUT
#define DDS_CONTROL_DIR_PORT P5DIR
#define DDS_DATA_PORT P4OUT
#define DDS_DATA_DIR_PORT P4DIR
#define DDS_FQUD 0x20
#define DDS_WCLK 0x40
#define DDS_RESET 0x80

void SET_DDS_FQUD_HIGH(){DDS_CONTROL_PORT|=DDS_FQUD; };
void SET_DDS_FQUD_LOW() {DDS_CONTROL_PORT&=~DDS_FQUD;};

void SET_DDS_WCLK_HIGH(){DDS_CONTROL_PORT|=DDS_WCLK; };
void SET_DDS_WCLK_LOW() {DDS_CONTROL_PORT&=~DDS_WCLK;};

void SET_DDS_RESET_HIGH(){DDS_CONTROL_PORT|=DDS_RESET; };
void SET_DDS_RESET_LOW() {DDS_CONTROL_PORT&=~DDS_RESET;};
void SET_DDS_DATA(unsigned char lcd_data){ DDS_DATA_DIR_PORT|=0XFF;DDS_DATA_PORT&=lcd_data; };

void delay1(void)
{uint m; for(m=11;m>0;m--);}

void delay(uint z)
{ uint x,y; for(x=z;x>0;x--)for(y=110;y>0;y--);}

void resetdds(void)
{
SET_DDS_RESET_HIGH();
delay(100);
SET_DDS_WCLK_LOW() ;
SET_DDS_FQUD_LOW();
SET_DDS_RESET_LOW();
delay(1);
}

void DDS_SET_FRE(uint dds_num)
{ uchar dds_data_temp,i;
for(i=0;i<5;i++)
{
dds_data_temp=DDS_DATA[dds_num][i];
SET_DDS_DATA(dds_data_temp);
SET_DDS_WCLK_HIGH();_NOP();_NOP();
SET_DDS_WCLK_LOW() ;_NOP();_NOP();
}
SET_DDS_FQUD_HIGH();
_NOP();_NOP();_NOP();
SET_DDS_FQUD_LOW();
}

void timer0_init()
{
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 200;
TACTL = TASSEL_2 + MC_2;
}

uint fre_start;
uint fre_over;
uint dds_start;
uint dds_over;
uchar dds_refresh;
void main()
{

WDTCTL = WDTPW + WDTHOLD;
timer0_init();
resetdds();
fre_start=0;
fre_over=20;
dds_refresh=0;
_BIS_SR(LPM0_bits + GIE);
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if(dds_refresh==1)
{
dds_refresh=0; //清刷新标志
dds_start=fre_start;
dds_over =fre_over;
}
DDS_SET_FRE(dds_start);
dds_start=dds_start+1;
if(dds_start==dds_over){dds_start=fre_start;};
CCR0 += 200; // Add Offset to CCR0
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top