📄 ad_test.c
字号:
/*********************************************************************************************
* File: ad_test.c
* Author: embest
* Desc: ad_test source code
* History:
*********************************************************************************************/
#include "44b.h"
#include "44blib.h"
/*------------------------------------------------------------------------------------------*/
/* function declare */
/*------------------------------------------------------------------------------------------*/
int adc_value(void);
/*********************************************************************************************
* name: Main
* func: c code entry
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************
void Main(void)
{
int temp;
sys_init(); // Initial 44B0X's Interrupt,Port and UART
init_adc();
//user interface
uart_printf("\n\r Embest Arm EduKit II Evaluation Board");
uart_printf("\n S3C44B0x ADC Conversion Test Example\n");
for(;;){
temp=adc_test();
} // Test start
}
/*********************************************************************************************
* name: adc_test
* func: test adc
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int adc_value(void)
{
int i,value=0;
init_adc();
//AIN2 AD conversion
for(i=0;;i++)
{
rADCCON = 0x1 | (0x2<<2); // AIN2
while( !(rADCCON&0x40) ); // wait conversion finish
if((value-78)<0) {value=0;}
else {value=value-78;}
value+=rADCDAT;
if(i==20){
i=0;
value=(value/20);
uart_printf( "Ain2 = %d\n", value );
return(value);
}
}
}
void init_adc(void){
// Initialize adc
rCLKCON = 0x7ff8;
rADCCON = 0x1 | (0<<2); // Enable ADC
delay(100); // delay for 10ms for ADC reference voltage stabilization.
rADCPSR = 100;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -