已回答假定已回答

dac配置问题

mermaidangel 在 2015-12-15 詢問的問題
最後回覆由hpkamen於2015-12-24提供

写了程序调用dac.h,然后报了以下错误

C:\Keil\ARM\INC\ADI\dac.h(43): error:  #101: "s_DAC_Channel" has already been declared in the current scope

C:\Keil\ARM\INC\ADI\dac.h:   typedef struct s_DAC_Channel {

C:\Keil\ARM\INC\ADI\dac.h:                  ^

C:\Keil\ARM\INC\ADI\dac.h(46): error:  #256: invalid redeclaration of type name "s_DAC_Channel" (declared at line 46)

C:\Keil\ARM\INC\ADI\dac.h:   } s_DAC_Channel;

C:\Keil\ARM\INC\ADI\dac.h:     ^

C:\Keil\ARM\INC\ADI\dac.h(48): error:  #101: "s_DAC" has already been declared in the current scope

C:\Keil\ARM\INC\ADI\dac.h:   typedef struct s_DAC {

C:\Keil\ARM\INC\ADI\dac.h:                  ^

C:\Keil\ARM\INC\ADI\dac.h(50): error:  #256: invalid redeclaration of type name "s_DAC" (declared at line 50)

 

 

附上程序

#include <aduc7020.h>

#include <stdio.h>

#include <irq.h>

#include <timer.h>

#include <dac.h>

#include <uart.h>

#include <i2c.h>

#include <pla.h>

#include <gpio.h>

#include <flash.h>

#include <pwm.h>

 

 

 

 

 

 

void ADCpoweron(int time)  //ADC上电启动

{

  ADCCON=0X20;

  while(time>=0)

  time--;

}

 

 

 

 

void SysClkInit(void)

{

  PLLKEY1=0XAA;

  PLLCON=0X01;

  PLLKEY2=0X55;

  POWKEY1=0X01;

  PLLCON=0X00;

  PLLKEY2=0XF4;

}

 

 

void delay(int length)

{

while(length>0)

  length--;

}

 

 

unsigned long int i=0;

static int j=0;

int m;    //初始值确定

int n;    //终点值确定

int y;

unsigned short int num[10000];

float f;    //频率定义

float b;

float total0=0;

float total1=0;

 

 

int main(void)

{

 

  SysClkInit(); //时钟配置

  ADCpoweron(20000); //ADC上电

  ADCCP=0x12;

  REFCON=0x01;

  GP1CON=0x011; //配置tx和rx引脚到DAC3和ADC3

  

  //配置UART波特率为115200

  COMCON0=0x80;

  COMDIV0=0x00B;

  COMDIV1=0x00;

  COMCON0=0x07;

 

  while(i<10000)

  {

  ADCCON=0x7E3;

  while(!ADCSTA)

  num[i]=(ADCDAT>>16);

  if((num[i]<=0.001)&(num[i]>=-0.001)) //寻找零点

  {

  m=i;   //记录初始的值

  j++;

  }

  if(j==2)  //得到频率

  {

  n=i;

  f=41.78/(i-m);

  }

  i++;

  }

    y=(m+n)/2;

  //DAC配置

  DAC0CON=0X02;

  REFCON=0x01;   //链接到参考电压源

  //DAC 输出

  for(i=y;i<(y+2*(n-m));i++)

  {

       DAC0DAT=(num[i]<<16);     

  }

 

}

結果