dac.c

来自「DSP部分功能测试 串口」· C语言 代码 · 共 70 行

C
70
字号
//-------------------------------//
//---dac.c-----------------------//
//-------------------------------//


#include	"math.h"

#define DAC0 port00
volatile ioport unsigned port00;   /*DAC0 IO PASS THROUGH*/
#define DAC1 port01
volatile ioport unsigned port01;   /*DAC1 IO PASS THROUGH*/ 
#define DAC2 port02
volatile ioport unsigned port02;   /*DAC2 IO PASS THROUGH*/
#define DAC3 port03
volatile ioport unsigned port03;   /*DAC3 IO PASS THROUGH*/
#define KEY port30
volatile ioport unsigned port30;   /*KEY IO*/
#define LED port2040                           
volatile ioport unsigned int port2040;/*LED*/


unsigned int GetSin(unsigned int index);
void DACSinOut(unsigned int count); 

extern void DACtest(void);


void DACtest(void)
{
	unsigned int temp;
	while(1)
	{
		asm("	clrc  XF");
		DACSinOut(1);
		temp=~KEY&0x00ff;
		LED=~temp;
		asm("	setc  XF");
		DACSinOut(1);	
	}
} 

unsigned int GetSin(unsigned int index)
{
    double temp;
    unsigned int tmp;
    temp=index;
	temp=(sin((temp/180)*3.1416)+1)/2*2000;
	tmp=(unsigned int)temp;
	return tmp;       	
}

void DACSinOut(unsigned int count)
{
    unsigned int tmp;
    int i,j;
    for(i=0; i<count; i++)
    {   
		for(j=0;j<360;j++)
        {   
        	tmp=GetSin(j);
			delay(10);
			DAC0=tmp;
			DAC1=tmp;
			DAC2=tmp;
			DAC3=tmp;
        }	
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?