|
各位大虾,我使用TQ2416开发板带的ad驱动的测试程序,使用NFS文件挂载的方式调试,SecureCRT上面显示的读取ad的数值总是读不到,我根据论坛上提供的PDA源码修改了测试程序,还是读不到,帮帮忙啊,为什么啊
代码如下:
/*************************************
NAME:EmbedSky_beep.c
COPYRIGHT:www.embedsky.net
*************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <errno.h>
#include <string.h>
int main(void)
{
int fd ;
char temp = 1;
int i;//lkh
//fd = open("/dev/adc", 0);
fd = open("/dev/adc", O_RDWR);//lkh
if (fd < 0)
{
perror("open ADC device !");
exit(1);
}
for( i=0; i<30; i++)//lkh
{
char buffer[30];
int len ;
ioctl(fd, 1, 2);//璁剧疆閫氬彿
//len = read(fd, buffer, sizeof buffer -1);
len = read(fd, buffer, sizeof(buffer) -1);//lkh
if (len > 0)
{
buffer[len] = '\0';
int value;
double dvalue;//lkh
sscanf(buffer, "%d", &value);
dvalue = (float) value * 3.3/1023;//lkh
//printf("ADC Value: %d\n", value);
printf("ADC Value: %f\n", dvalue);//lkh
}
else
{
perror("read ADC device !");
exit(1);
}
sleep(1);
}
adcstop:
close(fd);
}
|
|