ARM Linux S3C2440之ADC驱动实现(3)
![Rank: 8](images/default/star_level3.gif) ![Rank: 8](images/default/star_level3.gif)
- UID
- 1029342
- 性别
- 男
|
ARM Linux S3C2440之ADC驱动实现(3)
应用程序adc_test:
[cpp]
- #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) |
|
|
|
|
|