各位大神,帮妹纸看看,关于F5529的一个程序

2019-03-24 11:20发布

我要用F5529输出正弦波,下面是我的程序,但是就是没有波形,跪求各位大神帮忙看看是什么原因
#include<msp430x14X.h>
#include "HAL_Dogs102x6.h"

#define SCLK_HIGH      P4OUT |= BIT5
#define SCLK_LOW       P4OUT &= ~BIT5
#define CS_HIGH        P4OUT |= BIT4
#define CS_LOW         P4OUT &= ~BIT4
#define FS_HIGH        P2OUT |= BIT0
#define FS_LOW         P2OUT &= ~BIT0
#define DIN_HIGH       P6OUT |= BIT0
#define DIN_LOW        P6OUT &= ~BIT0

void port_init();
void init_clk();
void Dac5616_Init();
void TimerB_init();
void Dac_5616();
unsigned  int temp, temp1;


unsigned int sin[120]={0x800,0x86b,0x8d5,0x940,0x9a9,0xa11,0xa78,0xadd,0xb40,
0xba1,0xbff,0xc5a,0xcb3,0xd08,0xd59,0xda7,0xdf1,0xe37,0xe78,0xeb5,0xeed,0xf20,
0xf4e,0xf77,0xf9b,0xfb9,0xfd2,0xfe6,0xff4,0xffd,0xfff,0xffd,0xff4,0xfe7,0xfd3,
0xfba,0xf9c,0xf78,0xf4f,0xf21,0xeee,0xeb6,0xe7a,0xe39,0xdf3,0xda9,0xd5c,0xd0a,
0xcb5,0xc5d,0xc02,0xba4,0xb43,0xae0,0xa7b,0xa14,0x9ac,0x943,0x8d9,0x86e,0x803,
0x798,0x72d,0x6c3,0x659,0x5f1,0x58a,0x525,0x4c2,0x461,0x403,0x3a7,0x34f,0x2fa,
0x2a8,0x25a,0x210,0x1cb,0x189,0x14c,0x114,0xe1,0xb2,0x89,0x65,0x46,0x2d,0x19,
0xb,0x3,0x0,0x2,0xa,0x18,0x2b,0x44,0x62,0x86,0xae,0xdc,0x10f,0x147,0x183,0x1c4,
0x20a,0x253,0x2a1,0x2f2,0x347,0x39f,0x3fa,0x458,0x4b9,0x51c,0x581,0x5e7,0x650,
0x6b9,0x723,0x78e};

void init_clk()     
{
  unsigned int i;   
  BCSCTL1 &= ~XT2OFF;   //打开XT2高体振荡器
  do
  {
    IFG1 &= ~OFIFG;     //清除晶振失败标志
    for (i = 0xFF; i > 0; i--); //等待8MHZ晶体起振
  }
  while ((IFG1 & OFIFG) != 0);  //晶振失效标志仍然存在?
  BCSCTL2 |= SELM_2;  //MCLK和SMCLK选择高频晶振
  BCSCTL2 |= SELS;
}

void Dac5616_Init(void)
{
  P2DIR |= BIT0;
  P4DIR |= (BIT4 + BIT5);
  P6DIR |= BIT0;
}

void Dac_5616(unsigned int data)
{
  unsigned int i;

  CS_HIGH;
  SCLK_HIGH;
  FS_HIGH;
  CS_LOW;
  FS_LOW;
  
  for (i=0; i<16; i++)
  {
    if (data & 0x8000) DIN_HIGH;
    else DIN_LOW;
    SCLK_LOW;
    data = data << 1;
    SCLK_HIGH;
                  
  }
  FS_HIGH;
  CS_HIGH;       
}

void delay (int x)
{
  unsigned int i, j = 1;
  while(1)
  {
    for (i = 0; i < x; i++)
    {
      for (j = 0; j < 5000; j++)
      ;;      
    }
    break;
  }

}

void port_init()
{
  temp = 0;
  temp1 = 0;
}

void TimerB_init()
{
  TBCCR0 = 1;
  TBCTL |= TBSSEL_2 + TBCLR + MC_1;
  TBCCTL0 = CCIE;
}

#pragma vector = TIMERB0_VECTOR
__interrupt void Timer_B (void)
{
  temp++;     
  if (temp == 120)
  {
    temp = 0;
  }
  temp1 = sin[temp];
  Dac_5616(temp1);
}

void main( void )
{
  // Stop watchdog timer to prevent time out reset
  //unsigned temp;
  WDTCTL = WDTPW + WDTHOLD;
  //Dogs102x6_init();
  //Dogs102x6_backlightInit();
  //Dogs102x6_setBacklight(5);
  //Dogs102x6_setContrast(8);
  //Dogs102x6_clearScreen();
  init_clk();
  port_init();
  Dac5616_Init();
  TimerB_init();
  
  _EINT();
  while(1);
}

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
8条回答
李雪莹
1楼-- · 2019-03-24 14:55
<
错了,是#include<msp430F5529.h>
lcofjp
2楼-- · 2019-03-24 17:02
< :TI_MSP430_内容页_SA7 --> 首先要确保TimerB中断得到相应,这个通过仿真是能看到的。
然后要确定SPI输出波形没问题,可以通过示波器观察。
还要确保硬件电路没问题。
dai277530706
3楼-- · 2019-03-24 22:43
 精彩回答 2  元偷偷看……
dai277530706
4楼-- · 2019-03-24 22:59
李雪莹
5楼-- · 2019-03-25 00:58
dai277530706 发表于 2014-7-14 09:32
F5529没有DAC模块吧???我记得只有ADC

用的外设DA,TLV5616
李雪莹
6楼-- · 2019-03-25 05:54
 精彩回答 2  元偷偷看……

一周热门 更多>

相关问题

    相关文章