adctest2.c

来自「周立功magic2200实验箱linux增补例子。包括(GPIO zlg7290」· C语言 代码 · 共 53 行

C
53
字号
#include "config.h"int main(){    int fd1,fd2;    volatile uint16 ad_data;    uint32 volt;    uint32 fadc = 4500000;     fd1 = open("/dev/ADC0.0",O_RDONLY);    if(fd1 == -1)    {        printf("\nCan't open ADC0.0!\n");        exit(-1);    }    fd2 = open("/dev/ADC0.1", O_RDONLY);    if(fd2 == -1)    {        printf("\nCan't open ADC0.1!\n");        exit(-1);    }    ioctl(fd1, ADC_SET_CLKDIV, (Fpclk + fadc - 1) / fadc);    ioctl(fd1, ADC_SET_BITS, 10);    while(1)    {        ad_data = 0;        read(fd1, &ad_data, sizeof(ad_data));        volt = (3300*(ad_data>>6));        volt = volt/1024;         printf("VIN1's voltage is: %d mV        ", volt);        sleep(1);            ad_data = 0;        read(fd2, &ad_data, sizeof(ad_data));        volt = (3300*(ad_data>>6));        volt = volt/1024;         printf("VIN2's voltage is: %d mV\n", volt);        sleep(1);    }    return 0;}/***********************************************************************************************************                            End Of File********************************************************************************************************/

⌨️ 快捷键说明

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