⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hello_world.c

📁 ad7656采样的程序
💻 C
字号:
/********************************************************
AD7656 实验
*********************************************************/
# include <stdio.h>
# include "system.h"
# include "altera_avalon_pio_regs.h"
# include "alt_types.h"
# include "sys/alt_irq.h"
# include "priv/alt_busy_sleep.h"

alt_u16 readbuf[6];
float analog_input[6];
int done;

void delay(int time);

void PRINT()
{
   int i;
   
   for(i=0;i<6;i++)
   {
    
    if(readbuf[i]>0x0&&readbuf[i]<=0x7FFF)
            analog_input[i]=(readbuf[i]*0.305)/1000;
    else if (readbuf[i]>=0x8000&&readbuf[i]<=0xFFFF)
            analog_input[i]=(readbuf[i]*0.305)/1000-20;
      
    else if(readbuf[i]<0||readbuf[i]>0x7FFF)
       printf("Data is out of range.\n"); 
        
    printf("Input analog V%d=%fv\n",i+1,analog_input[i]);        
   }
}



static void ad7656_interrupts(void * context, alt_u32 id)
{ 
  
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(INTS_BASE,0);
 
  done++;
}

void initAD7656(void)
{
  IOWR_ALTERA_AVALON_PIO_DATA(CONVST_BASE,1);
  IOWR_ALTERA_AVALON_PIO_DATA(RESET_BASE,1);
  delay(5000);
  IOWR_ALTERA_AVALON_PIO_DATA(RESET_BASE,0);
  
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(INTS_BASE,1);
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(INTS_BASE,0);
  
  IOWR_ALTERA_AVALON_PIO_DATA(CONVST_BASE,0);
  
  IOWR_ALTERA_AVALON_PIO_DATA(RD_BASE,1);
  IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE,1);
  alt_irq_register(INTS_IRQ,NULL,ad7656_interrupts);
}

void delay( int time)
{
  int i;
  for(i=0;i<time;i++);
}

int main(void)
{ 

   
 int j;
 done=0;
 
 
 initAD7656();
 IOWR_ALTERA_AVALON_PIO_DATA(CONVST_BASE,0);
 while(1)
 {

  IOWR_ALTERA_AVALON_PIO_DATA(CONVST_BASE,1);
  
  if(0!=done)
   {
    
   done--;
    IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE,0);
    for(j=0;j<6;j++)
     {
      IOWR_ALTERA_AVALON_PIO_DATA(RD_BASE,0);
      readbuf[j]= IORD_ALTERA_AVALON_PIO_DATA(AD_DATA_BASE);
      IOWR_ALTERA_AVALON_PIO_DATA(RD_BASE,1);
     }
     //IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE,1);
     PRINT();
     IOWR_ALTERA_AVALON_PIO_DATA(CONVST_BASE,0);
     delay(5000);
     
    }
 }
 return 0;
}

⌨️ 快捷键说明

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