📄 da_main.c
字号:
/************************************************* by zou jian guo<zounix@126.com> * 2004.9.27 14:30 * * the driver is s3c2410_da_max504.c in drivers/char*************************************************/#include <stdio.h>#include <fcntl.h>#include <string.h>#include <sys/ioctl.h>#define DA0_IOCTRL_WRITE 0x10#define DA1_IOCTRL_WRITE 0x11#define DA_IOCTRL_CLR 0x12#define Max504_FULL 4.096fstatic int da_fd = -1;char *DA_DEV="/dev/exio/0raw";void Delay(int t){ int i; for(;t>0;t--) for(i=0;i<400;i++);}/****************************************************************/int main(int argc, char **argv){ float v; unsigned int value;// char *da_dev;// unsigned int da_num=0; if(argc < 3){ printf("\n"); printf("Error parameter\n"); printf("Input as:\n"); printf("[~]./ad_main da_id num\n"); printf(" da_id: select between 0 and 1\n"); printf(" num: range 0.0 ~ 4.096\n"); printf("\n"); return 1; } sscanf(argv[2], "%f",&v); if(v<0 || v>Max504_FULL){ printf("DA out must between: 0 to %f\n", Max504_FULL); return 1; } value=(unsigned int)((v*1024.0f)/Max504_FULL); if((da_fd=open(DA_DEV, O_WRONLY))<0){ printf("Error opening /dev/exio/0raw device\n"); return 1; } if(strcmp(argv[1],"0") == 0){ ioctl(da_fd, DA_IOCTRL_CLR, 0); //clear da. ioctl(da_fd, DA0_IOCTRL_WRITE, &value); }else if (strcmp(argv[1],"1") == 0){ ioctl(da_fd, DA_IOCTRL_CLR, 1); //clear da. ioctl(da_fd, DA1_IOCTRL_WRITE, &value); } #if 0 ioctl(da_fd, DA_IOCTRL_CLR, 0); //clear da. for(;;) { ioctl(da_fd, DA0_IOCTRL_WRITE, &value); Delay(500); } #endif close(da_fd); printf("Current Voltage is %f v\n", v); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -