?? main.c
字號(hào):
/************************************************\* 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;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -