📄 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 port40
volatile ioport unsigned int port40;/*LED*/
#define LDAC0 port10
volatile ioport unsigned port10; /*DAC0 IO PASS THROUGH*/
#define LDAC1 port11
volatile ioport unsigned port11; /*DAC1 IO PASS THROUGH*/
#define LDAC2 port12
volatile ioport unsigned port12; /*DAC2 IO PASS THROUGH*/
#define LDAC3 port13
volatile ioport unsigned port13; /*DAC3 IO PASS THROUGH*/
#define LATCHDAC port21
volatile ioport unsigned port21; /*DAC3 IO PASS THROUGH*/
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*4000;
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(5);
LDAC0=tmp;
delay(5);
LDAC1=tmp;
delay(5);
LDAC2=tmp;
delay(5);
LDAC3=tmp;
delay(5);
LATCHDAC = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -