//main.c
#include "msp430f247.h"
#include "stdlib.h"
#include "string.h"
/*****************************************软件延时,主频1M*******************/
#define CPU_F1 ((double)1000000)
#define delay_us1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000000.0))
#define delay_ms1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000.0))
/****************************************************************************/
/*****************************************软件延时,主频1M*******************/
#define CPU_F8 ((double)8000000)
#define delay_us8M(x) __delay_cycles((long)(CPU_F8*(double)x/1000000.0))
#define delay_ms8M(x) __delay_cycles((long)(CPU_F8*(double)x/1000.0))
/****************************************************************************/
//128点输出正弦波样本值
char data_Sin[128]={
128,134,140,147,153,159,165,171,177,182,188,193,199,204,209,213,
218,222,226,230,234,237,240,243,245,248,250,251,253,254,254,255,
255,255,254,254,253,251,250,248,245,243,240,237,234,230,226,222,
218,213,209,204,199,193,188,182,177,171,165,159,153,147,140,134,
128,122,116,109,103,97,91,85,79,74,68,63,57,52,47,43,38,34,30,26,
22,19,16,13,11,8,6,5,3,2,2,1,1,1,2,2,3,5,6,8,11,13,16,19,22,26,30,
34,38,43,47,52,57,63,68,74,79,85,91,97,103,109,116,122};
/************************************************
函数名称:主函数
函数功能:D/A转换器应用二:正弦波发生器
入口参数:无
出口参数:无
描述:
作者:老马识途单片机
日期:2018年1月10日
************************************************/
main()
{
unsigned int i;
WDTCTL = WDTPW + WDTHOLD;//关看门狗
P4DIR=0xff;
while(1)
{
for(i=0;i<128;i++)
{
P4OUT=data_Sin;
delay_us1M(156);
}
}
}