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

📄 main.c

📁 博创arm 3000开发板实验
💻 C
字号:
/************************************************\*	by threewater<threewater@up-tech.com>	**		2003.12.18			**						*\***********************************************/#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/ioctl.h>#include <pthread.h>#include "hardware.h"#define ADCCON_FLAG		0x40#define ADCCON_SLEEP		0x20#define ADCCON_ADIN0		(0x0<<2)#define ADCCON_ADIN1		(0x1<<2)#define ADCCON_ADIN2		(0x2<<2)#define ADCCON_ADIN3		(0x3<<2)#define ADCCON_ADIN4		(0x4<<2)#define ADCCON_ADIN5		(0x5<<2)#define ADCCON_ADIN6		(0x6<<2)#define ADCCON_ADIN7		(0x7<<2)#define ADCCON_READ_START	0x2#define ADCCON_ENABLE_START	0x1void init_ADdevice(void){	ADCPSR=20;	ADCCON=ADCCON_SLEEP;}int GetADresult(int channel){	int i=0;	ADCCON=(channel<<2)|ADCCON_ENABLE_START;	//To avoid The first FLAG error case.	//(The START bit is cleared in one ADC clock.)//	while(ADCCON) &1);	for(;i<100;i++);	//To avoid The second FLAG error case	while(!( (ADCCON) & ADCCON_FLAG));	return ADCDAT;}static int stop=0;void* comMonitor(void* data){	getchar();	stop=1;	return NULL;}int main(void){	int i;	float d;	pthread_t th_com;	void * retval;	//set s3c44b0 AD register and start AD	init_ADdevice();	usleep(1);                                                                                	/* Create the threads */	pthread_create(&th_com, NULL, comMonitor, 0);	printf("\nPress Enter key exit!\n");	while( stop==0 ){		for(i=0; i<=3; i++){//采样0~3路A/D值			d=((float)GetADresult(i)*2.5)/1024.0;			printf("a%d=%f\t",i,d);			usleep(10);		}		printf("\r");	}	/* 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 + -