?? ndac_test.c
字號:
/*****************************************************************************
;Institue of Automation, Chinese Academy of Sciences
;www.hyesco.com
;Description: ADC driver on Linux for AT91RM9200
;Date: 2006-3-27
;Author: BHB
;E_mail:
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
typedef struct _DA_PARA
{
int Channel;
int Adc_value;
} AT91_DA_PARA;
static int fd=-1;
int main()
{
AT91_DA_PARA dapara;
float value;
location:
//輸入DA轉換的數(shù)值;
printf("please input the Value of DAC(-10~10)!\n");
scanf("%f",&value);
printf("value is:%f\r\n",value);
//判斷DA轉換數(shù)值的合法性,DA轉換數(shù)值為-10V~10V;
if((value<-10)||(value>10))
{
printf("The input value of the DAC is failed!\r\n");
goto location;
}
//設定DAC通道號為1,H9200F僅使用該通道;
dapara.Channel = 1;
//將輸入的數(shù)據(jù)轉化為DA數(shù)字量;
if(value>=0)
dapara.Adc_value=((int)((value*100)*32767.0/1000)<<16)&0x7fff0000;
else
dapara.Adc_value=((int)((value+10)*32767/10+32768.0)<<16)&0xffff0000;
//打開設備文件;
if((fd=open("/dev/dac0",O_WRONLY))==-1)
{
perror("open DAC error");
exit(1);
}
//送出DA轉換值;
write(fd,&dapara,sizeof(AT91_DA_PARA));
close(fd);
printf("DAC succeesfully!\r\n");
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -