📄 lib_lpc_ad.c
字号:
/*
***********************************************************************
Embest Info&Tech Co., Ltd. All rights reserved.
www.embedinfo.com
***********************************************************************
---------------- file information -------------------------------------
file name: lib_lpc_ad.c
version : v0
author : zhangxuquan
peter pan / panqan@hotmail.com
panqian@embedinfo.com
begin : 2006-02-10
finish : 2006-02-10
define : lpc ad convert lib
notes :
---------------- modify information -----------------------------------
version :
modify :
begin :
finish :
define :
-----------------------------------------------------------------------
*/
/*-------------------------------------------------------------------*/
/* include files */
/*---------------------------------------------------------------- --*/
#include "lib_lpc_ad.h"
/*-------------------------------------------------------------------*/
/* function code */
/*-------------------------------------------------------------------*/
/**********************************************************************
* name : port_toad_en
* func : connect the port to ad part
* para : channel
* ret :
* glob : xxxx
* inc :
* author:
* date :
* modify:
* comment:
**********************************************************************/
void port_toad_en(AD_channel AD_channel_v)
{
INT32U i,j,k;
switch (AD_channel_v)
{
case AIN0:
break;
case AIN1:
break;
case AIN2:
break;
case AIN3:
break;
case AIN4:
//AIN4/5
i=PINSEL2;
i &= ~P2_30_31_AIN_4_5_PINSEL2_M;
i |= P2_30_31_AIN_4_5_PINSEL2_V;
PINSEL2 = i;
//EN 4
i=PINSEL2;
i &= ~P2_30_AIN_4_PINSEL2_M;
i |= P2_30_AIN_4_PINSEL2_V;
i=PINSEL2;
break;
case AIN5:
//AIN4/5
i=PINSEL2;
i &= ~P2_30_31_AIN_4_5_PINSEL2_M;
i |= P2_30_31_AIN_4_5_PINSEL2_V;
PINSEL2 = i;
//EN 5
i=PINSEL2;
i &= ~P2_31_AIN_5_PINSEL2_M;
i |= P2_31_AIN_5_PINSEL2_V;
i=PINSEL2;
break;
case AIN6:
//AIN4/5
i=PINSEL2;
i &= ~P2_30_31_AIN_4_5_PINSEL2_M;
i |= P2_30_31_AIN_4_5_PINSEL2_V;
PINSEL2 = i;
//EN6
i=PINSEL2;
i &= ~P3_29_AIN_6_PINSEL2_M;
i |= P3_29_AIN_6_PINSEL2_V;
i=PINSEL2;
break;
case AIN7:
//AIN4/5
i=PINSEL2;
i &= ~P2_30_31_AIN_4_5_PINSEL2_M;
i |= P2_30_31_AIN_4_5_PINSEL2_V;
PINSEL2 = i;
//EN7
i=PINSEL2;
i &= ~P3_28_AIN_7_PINSEL2_M;
i |= P3_28_AIN_7_PINSEL2_V;
i=PINSEL2;
break;
default: break;
}
}
/*
AIN0=0,
AIN1
AIN2
AIN3
AIN4,
AIN5,
AIN6,
AIN7
*/
/**********************************************************************
* 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 : xxxx
* glob : xxxx
* inc :
* author:
* date :
* modify:
* comment:
**********************************************************************/
void AD_init(INT8U Chg_mode,AD_channel ad_ch,AD_trigger_mode tri_mode,INT8U edge)
{
INT32U i;
INT32U ain_sel;
//set pinsel to ad convert
port_toad_en(ad_ch);
switch (ad_ch)
{
case AIN0:
break;
case AIN1:
break;
case AIN2:
break;
case AIN3:
break;
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 convort data
* para : Chg_mode: 0 auto 1 soft ,AD_channel,AD_trigger_mode.
* ret : data of INT32U types
* glob : xxxx
* inc :
* author:
* date :
* 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 : close the ad convert
* para :
* ret :
* glob : xxxx
* inc :
* author:
* date :
* modify:
* comment:
**********************************************************************/
void AD_close()
{
INT32U i;
i=SEL_DEFAULT;
ADCR=i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -