📄 adc_drv.c
字号:
/***************************************************************************
Project : TDA7540 Jig board
Compiler : ST7 HiCross C (HiWARE)
Module : Adc_drv.c
Version : V 1.0
Created : Jan.24th,2005
Author : Jerry HE / ST-ShenZhen
Description
- Analog converter handle program
Modified
-
***************************************************************************/
/* EXTERNAL DECLARATIONS *****************************************************/
/* List of all the variables defined in another module and used in this one. */
/* MODEL => #include [file_name].h */
#include "system.h"
/* STATIC DECLARATIONS *******************************************************/
/* List of all the variables/constant defined in another module and used in */
/* this one. */
/* MODEL => static type_name var_name; or #define */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : Read_ADKey
Input :
Output :
Description
- Analog key convertion
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void Read_ADKey()
{
if (ADKeyDelay!=0)
return;
if(!BitVal(ADC_COCO))
return;
if(F_ADKeyRead ==1)
return;
switch(ADStatus)
{
//The first line of switch
case AD_Key1:
ADKey[0]=ADC_DR;
ADStatus=AD_Key2;
ADC_CR =(ADC_START|ADStatus);
break;
case AD_Key2:
ADKey[1]=ADC_DR;
ADStatus=AD_Key1;
ADC_CR =(ADC_START|ADStatus);
F_ADKeyRead = 1;
break;
default:
ADStatus=AD_Key1;
ADC_CR =(ADC_START|ADStatus);
break;
}
ADKeyDelay = 4;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : Init_AD
Input :
Output :
Description
- Initial ST7 AD converter
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void Init_AD()
{
ADStatus= AD_Key1;
ADC_CR=(ADC_START|ADStatus);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : ADC_GetValue
Input : Channel No to be read [0..7]
Output : ADC_DR
Description
- A/D Conversion on the selected Channel.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
unsigned char ADC_GetValue (unsigned char adc_channel)
{
ADC_CR= ((adc_channel & 0x0F) | 0x20);
while ((ADC_CR&0x80)==0); /* Wait for End of Conversion */
return(ADC_DR); /* Return the value */
}
/*** (c) 2005 STMicroelectronics ************************************* END OF FILE ***/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -