?? adc.c
字號:
//****************************************************************************
// @Module Analog / Digital Converter (ADC)
// @Filename ADC.C
// @Project T12_T13_AD_PEC.dav
//----------------------------------------------------------------------------
// @Controller Infineon XC164CM-8F40
//
// @Compiler Keil
//
// @Codegenerator 0.2
//
// @Description This file contains functions that use the ADC module.
//
//----------------------------------------------------------------------------
// @Date 2006-7-8 23:19:35
//
//****************************************************************************
// 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)
unsigned int ADC_Result[10];
// 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 2006-7-8
//
//****************************************************************************
// USER CODE BEGIN (Init,1)
// USER CODE END
void ADC_vInit(void)
{
// USER CODE BEGIN (Init,2)
// USER CODE END
/// - enhanced mode is selected
/// - fixed channel single conversion mode is selected
/// - 10-bit resolution
/// - once converts channel 0
/// - ADC start bit is reset
/// - wait for ADDAT read mode is enabled
/// - converter basic clock tbc is fpd / 1
/// - sample time tsc is tbc * 8
/// - post calibration is enabled
/// - conversion time tc = 1.550 祍
/// - channel injection is enabled
/// - inject channel 0
/// - trigger input CCU6 selected
/// - resolution for injection mode is 10-bit
/// - converter basic clock tbc for injection mode is fpd / 1
/// - sample time tsc for injection mode is tbc * 8
/// - conversion time in injection mode tc = 1.550 祍
ADC_CTR0 = 0xA600; // load ADC control register 0
ADC_CTR2 = 0x0000; // load ADC control register 2
ADC_DAT2 = 0x0000; // load A/D converter 2 result register
ADC_CTR2IN = 0x0000; // load ADC injection control register 2
/// -----------------------------------------------------------------------
/// Configuration of the used ADC Interrupts:
/// -----------------------------------------------------------------------
/// Error service request node configuration:
/// - Error interrupt priority level (ILVL) = 12
/// - Error interrupt group level (GLVL) = 2
/// - Error group priority extension (GPX) = 0
ADC_EIC = 0x0072;
/// Use PEC channel 2 for ADC Error INT:
/// - decrement counter
/// - increment destination pointer
/// - transfer a word
/// - service End of PEC interrrupt by a EOP interrupt node is enabled
/// - End of PEC intrrupt request is enabled
PECC2 = 0x520A; // load PECC2 control register
SRCP2 = _sof_(&ADC_DAT2); //set source pointer
//// - DESTINATION-POINTER for PECC channel 2 is set because it is selected
//// for user defined
DSTP2 = _sof_(0x0000); //set destination pointer
/// -----------------------------------------------------------------------
/// Configuration of the used ADC Port Pins:
/// -----------------------------------------------------------------------
/// - P5.0 is used for Analog Input Pin (AN0)
/// - digital input stage is disconnected from port line P5.0
P5DIDIS = 0x0001; // load Port 5 digital input disable register
// USER CODE BEGIN (Init,3)
DSTP2 = _sof_(ADC_Result); //set destination pointer
// USER CODE END
} // End of function ADC_vInit
//****************************************************************************
// @Function void ADC_viError(void)
//
//----------------------------------------------------------------------------
// @Description This is the interrupt service routine for the overwrite
// error of the ADC (in standard mode) - the last measurement
// result was overwritten - , or the ISR for the end of an
// injected conversion - the result of the injected conversion
// has beenwritten to ADC_DAT2. An overrun is not possible in
// channel injection mode; in this case the A/D measurement is
// stopped. To get the injected conversion result the user can
// call the function ADC_uwReadInject().
// Please note that you have to add application specific code
// to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2006-7-8
//
//****************************************************************************
// USER CODE BEGIN (Error,1)
// USER CODE END
void ADC_viError(void) interrupt ADC_E_INT
{
// USER CODE BEGIN (Error,2)
// USER CODE END
} // End of function ADC_viError
// USER CODE BEGIN (ADC_General,10)
// USER CODE END
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -