📄 adctest2.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -