📄 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转换的数值;
printf("please input the Value of DAC(-10~10)!\n");
scanf("%f",&value);
printf("value is:%f\r\n",value);
//判断DA转换数值的合法性,DA转换数值为-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;
//将输入的数据转化为DA数字量;
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 + -