应用程序adc_test:
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/ioctl.h>
- #include <fcntl.h>
- int main(void)
- {
- int fd;
- char buf[4];
- int i,res,adc_data;
- if ((fd = open("/dev/ADC_DEV",O_RDONLY)) < 0) {
- printf("open adc_dev failed\n");
- return 1;
- }
- printf("adc_test result:\n");
- for (i= 0; i< 5; i++) {
- if ((res =read(fd, buf, 4)) != 4) {
- printf("read adc_dev failed \n");
- return 1;
- }
- else {
- adc_data = buf[0] + (int)(buf[1]<<8);
- printf("adc value = %d (%.2f V) \n",adc_data, adc_data/1024.0*3.3);
- }
- }
- close(fd);
- return 0;
- }
测试结果:
[root@www.linuxidc.com /]# ./adc_test
adc_test result:
adc value = 740 (2.38 V)
adc value = 744 (2.40 V)
adc value = 744 (2.40 V)
adc value = 744 (2.40 V)
