adctest.c

来自「周立公smartarm 2200 数模转换例子」· C语言 代码 · 共 38 行

C
38
字号

#define IN_TGPIO
#include "config.h"

int main()
{
    int fd;
    volatile uint16 ad_data;
    uint32 volt;
    uint32 fadc = 4500000;
 
    fd = open("/dev/ADC0.0", O_RDONLY);
    if(fd == -1)
    {
        printf("\nCan't open ADC0.0!\n");
        exit(-1);
    }

    ioctl(fd, ADC_SET_CLKDIV, (Fpclk + fadc - 1) / fadc - 1);
    ioctl(fd, ADC_SET_BITS, 10);

    while(1)
    {
        ad_data = 0;
        read(fd, &ad_data, sizeof(ad_data));
        volt = (3300*(ad_data>>6));
        volt = volt/1024; 
        printf("VIN1's voltage is: %d mV\n", volt);
        sleep(1);
    }

    return 0;
}

/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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