📄 lpc_lib_ad.c
字号:
/*
**********************************************************************************************
*
* Embest Info&Tech Co., Ltd. All rights reserved.
* www.embedinfo.com
*
*file: xxx.c/xxx.h
*author: embest
*establish: 2006.xx.xx
*modify: xx
*notes: xx
**********************************************************************************************
*/
/*
**********************************************************************************************
* include files
**********************************************************************************************
*/
#include "..\..\com\lpc_lib_AD\lpc_lib_AD.h"
/*
**********************************************************************************************
* global variable define
**********************************************************************************************
*/
/*
**********************************************************************************************
* name: AD_init
* func: Initialize the AD change channel,include select AD change mode (soft/auto),
selecting channel.if under auto mode,select trigger mode for starting change.
* para: Chg_mode: 0 auto 1 soft ,AD_channel,AD_trigger_mode.
* ret: none
* modify:
* comment:
**********************************************************************************************
*/
void AD_init(INT8U Chg_mode,AD_channel ad_ch,AD_trigger_mode tri_mode,INT8U edge)
{
INT32U i;
INT32U ain_sel;
switch(ad_ch)
{
case AIN4: ain_sel=SEL_AIN4;
break;
case AIN5: ain_sel=SEL_AIN5;
break;
case AIN6: ain_sel=SEL_AIN6;
break;
case AIN7: ain_sel=SEL_AIN7;
break;
default:
break;
}
if(Chg_mode==0)
{
i=ain_sel+CLKDIV+BURST_A+CLKS_0+PDN_N+TEST_0+START_A;
ADCR=i;
}
else
{
}
}
/*
**********************************************************************************************
* name: AD_read
* func: Get the AD data
* para: none
* ret: data of INT32U types
* modify:
* comment:
**********************************************************************************************
*/
INT32U AD_read(void)
{
INT32U data;
while((ADDR&0x80000000)==0);
data=ADDR;
data=((data&DATA_MASK)>>6);
return data;
}
/*
**********************************************************************************************
* name: AD_close
* func: restore aint pin and all related register to reset value
* para: none
* ret: none
* modify:
* comment:
**********************************************************************************************
*/
void AD_close()
{
INT32U i;
i=SEL_DEFAULT;
ADCR=i;
}
/*
**********************************************************************************************
* name: AD_value
* func: Get the AD average value for 50 times
* para: none
* ret: data of INT32U types
* modify:
* comment:
**********************************************************************************************
*/
INT32U AD_value(void)
{
INT32U i,data;
for(i=0,data=0;i<50;i++) //get average value for 50 times
data+=AD_read();
data=data/i;
return data;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -