?? adc.c
字號:
//****************************************************************************
// @Module Analog / Digital Converter (ADC)
// @Filename ADC.C
// @Project LampBoard.dav
//----------------------------------------------------------------------------
// @Controller Infineon XC164CM-8F40
//
// @Compiler Keil
//
// @Codegenerator 1.1
//
// @Description This file contains functions that use the ADC module.
//
//----------------------------------------------------------------------------
// @Date 2008-12-11 14:56:13
//
//****************************************************************************
// USER CODE BEGIN (ADC_General,1)
// USER CODE END
//****************************************************************************
// @Project Includes
//****************************************************************************
#include "MAIN.H"
// USER CODE BEGIN (ADC_General,2)
// USER CODE END
//****************************************************************************
// @Macros
//****************************************************************************
// USER CODE BEGIN (ADC_General,3)
// USER CODE END
//****************************************************************************
// @Defines
//****************************************************************************
// USER CODE BEGIN (ADC_General,4)
// USER CODE END
//****************************************************************************
// @Typedefs
//****************************************************************************
// USER CODE BEGIN (ADC_General,5)
// USER CODE END
//****************************************************************************
// @Imported Global Variables
//****************************************************************************
// USER CODE BEGIN (ADC_General,6)
// USER CODE END
//****************************************************************************
// @Global Variables
//****************************************************************************
// USER CODE BEGIN (ADC_General,7)
// USER CODE END
//****************************************************************************
// @External Prototypes
//****************************************************************************
// USER CODE BEGIN (ADC_General,8)
// USER CODE END
//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************
// USER CODE BEGIN (ADC_General,9)
// USER CODE END
//****************************************************************************
// @Function void ADC_vInit(void)
//
//----------------------------------------------------------------------------
// @Description This is the initialization function of the ADC function
// library. It is assumed that the SFRs used by this library
// are in reset state.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2008-12-11
//
//****************************************************************************
// USER CODE BEGIN (Init,1)
// USER CODE END
void ADC_vInit(void)
{
// USER CODE BEGIN (Init,2)
// USER CODE END
/// - enhanced mode is selected
/// - auto scan continuous conversion mode is selected
/// - 8-bit resolution
/// - repeatedly converts a sequence beginning with channel 13
/// - ADC start bit is set
/// - wait for ADDAT read mode is enabled
/// - converter basic clock tbc is fpd / 64
/// - sample time tsc is tbc * 7.37869762948382E+19
/// - post calibration is enabled
/// - conversion time tc = 480.150 usec
/// - channel injection is disabled
ADC_CTR0 = 0x926D; // load ADC control register 0
ADC_CTR2 = 0x1FFF; // load ADC control register 2
/// -----------------------------------------------------------------------
/// Configuration of the used ADC Interrupts:
/// -----------------------------------------------------------------------
/// Conv service request node configuration:
/// - Conv interrupt priority level (ILVL) = 14
/// - Conv interrupt group level (GLVL) = 0
/// - Conv group priority extension (GPX) = 0
ADC_CIC = 0x0078;
/// -----------------------------------------------------------------------
/// Configuration of the used ADC Port Pins:
/// -----------------------------------------------------------------------
/// - P5.12 is used for Analog Input Pin (AN12)
/// - P5.13 is used for Analog Input Pin (AN13)
/// - digital input stage is disconnected from port line P5.12
/// - digital input stage is disconnected from port line P5.13
P5DIDIS = 0x3000; // load Port 5 digital input disable register
ADC_CTR0_ADST = 1; // set start bit
// USER CODE BEGIN (Init,3)
// USER CODE END
} // End of function ADC_vInit
//****************************************************************************
// @Function uword ADC_uwReadConv(void)
//
//----------------------------------------------------------------------------
// @Description This function returns the result of a conversion. This
// function must be called after each conversion. The lower 10
// bits contain the conversion result while the upper 4 bits
// identify the converted analog channel.
//
//----------------------------------------------------------------------------
// @Returnvalue Conversion result
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2008-12-11
//
//****************************************************************************
// USER CODE BEGIN (ReadConv,1)
// USER CODE END
uword ADC_uwReadConv(void)
{
return(ADC_DAT);
} // End of function ADC_uwReadConv
//****************************************************************************
// @Function void ADC_viConv(void)
//
//----------------------------------------------------------------------------
// @Description This is the interrupt service routine for the ADC. It is
// called at the end of each conversion. The user obtains the
// conversion result by calling the function ADC_uwReadConv().
// Please note that you have to add application specific code
// to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2008-12-11
//
//****************************************************************************
// USER CODE BEGIN (Conv,1)
// USER CODE END
void ADC_viConv(void) interrupt ADC_C_INT using RB_LEVEL14
{
// USER CODE BEGIN (Conv,2)
unsigned int adc_temp;
adc_temp = ADC_uwReadConv();
// USER CODE END
} // End of function ADC_viConv
// USER CODE BEGIN (ADC_General,10)
// USER CODE END
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -