⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad_p.c

📁 minigui PDA系统 可实现手机功能
💻 C
字号:
/************************************************\
*	by threewater<threewater@up-tech.com>	*
*		2004.06.18			*
*						*
\***********************************************/

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/ioctl.h>
#include <pthread.h>
#include <fcntl.h>
#include "s3c2410-adc.h"

#define ADC_DEV		"/dev/adc/0raw"
static int adc_fd = -1;

int init_ADdevice(void)
{
	if((adc_fd=open(ADC_DEV, O_RDWR))<0){
		printf("Error opening %s adc device\n", ADC_DEV);
		return -1;
	}
}

int GetADresult(int channel)
{
	int PRESCALE=0XFF;
	int data=ADC_WRITE(channel, PRESCALE);
	write(adc_fd, &data, sizeof(data));
	read(adc_fd, &data, sizeof(data));
	return data;
}
static int stop=0;

static void* comMonitor(void* data)
{
	getchar();
	stop=1;
	return NULL;
}

static int Ad(float data[])
{
	int i;
	float d;
	while( stop==0 ){
		for(i=0; i<=2; i++){//采样0~2路A/D倄1¤7			d=((float)GetADresult(i)*3.3)/1024.0;
			data[i]=d;
			printf("a%d=%8.4f\t",i,data[i]);
		}
		usleep(500000);
		printf("\r");
		}
		return 0;

}

int OpenDev (void)
{
	
	pthread_t th_com;
	void * retval;

	//set s3c44b0 AD register and start AD
	if(init_ADdevice()<0)
		return -1;
                                                                                
	/* Create the threads */
	pthread_create(&th_com, NULL, comMonitor, 0);

	printf("\nPress Enter key exit!\n");	
		//Ad();
	/* Wait until producer and consumer finish. */
	pthread_join(th_com, &retval);

	//printf("\n");
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -