adc.c
来自「阿根廷教授编写的嵌入式internet的实验教程的高质量代码」· C语言 代码 · 共 33 行
C
33 行
/******************************************************************************************
ADC.c (v1.0)
-------------------------------------------------------------------------------------
This code is from the book:
"Embedded Internet: TCP/IP Basics, Implementation and Applications" by Sergio Scaglia
[Pearson Education, 2006 - ISBN: 0-32-130638-4]
This code is copyright (c) 2006 by Sergio Scaglia, and it may only be used for educational
purposes. For commercial use, please contact me at sscaglia@intramarket.com.ar
For more information and updates, please visit www.embeddedinternet.org
******************************************************************************************/
#include "ADC.h"
#include "sysClock.h"
#include <iolpc2129.h>
void ADC_init(void) {
ADCR = ((int)(pClkFreq()) / 4500000) << 8;
ADCR |= 0x00270001; // Setup A/D
ADCR |= 0x01000000; // Start A/D Conversion
}
unsigned int ADC_Read(void) {
unsigned int val=0;
do{
val = ADDR; // Read A/D Data Register
}while ((val & 0x80000000) == 0); //Wait for the conversion to complete
return ((val >> 6) & 0x03FF);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?