//****************************************************************************
// @Module Analog / Digital Converter (ADC)
// @Filename ADC.C
// @Project can.dav
//----------------------------------------------------------------------------
// @Controller Infineon XC164CS-16F40
//
// @Compiler Keil
//
// @Codegenerator 2.8
//
// @Description This file contains functions that use the ADC module.
//
//----------------------------------------------------------------------------
// @Date 2007-4-12 11:03:44
//
//****************************************************************************
// 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)
extern ubyte ub_ADCFinishFlag;
extern ubyte ub_ADCFlag;
extern uword Vehicle_Speed_AD;
extern uword Steering_Rate_AD;
// 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 its reset state.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2007-4-12
//
//****************************************************************************
// USER CODE BEGIN (Init,1)
// USER CODE END
void ADC_vInit(void)
{
// USER CODE BEGIN (Init,2)
// USER CODE END
/// - compatibility 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 disabled
/// - converter basic clock tbc is fcpu / 1
/// - sample time tsc is tbc * 8
/// - conversion time tc = 1.550 �s
ADC_CON = 0x0000; // load ADC control register
ADC_CON1 = 0x8000; // load ADC control register 1
/// -----------------------------------------------------------------------
/// Configuration of the used ADC Interrupts:
/// -----------------------------------------------------------------------
/// Conv service request node configuration:
/// - Conv interrupt priority level (ILVL) = 13
/// - Conv interrupt group level (GLVL) = 0
/// - Conv group priority extension (GPX) = 0
ADC_CIC = 0x0074;
/// -----------------------------------------------------------------------
/// Configuration of the used ADC Port Pins:
/// -----------------------------------------------------------------------
/// - P5.0 is used for Analog Input Pin (AN0)
/// - P5.1 is used for Analog Input Pin (AN1)
/// - digital input stage is disconnected from port line P5.0
/// - digital input stage is disconnected from port line P5.1
P5DIDIS = 0x0003; // load Port 5 digital input disable register
// USER CODE BEGIN (Init,3)
// USER CODE END
} // End of function ADC_vInit
//****************************************************************************
// @Function void ADC_vConfConv(ubyte ubMode, ubyte ubChannel)
//
//----------------------------------------------------------------------------
// @Description This function configures a new A/D conversion. In fixed
// channel single conversion mode (ADC_FIXED) the forwarded
// channel is converted once. In fixed channel continuous
// conversion mode (ADC_FIXED_CONTI) the forwarded channel is
// converted continuously. In auto scan single conversion mode
// (ADC_SCAN) a sequence beginning with the forwarded channel
// and ending with channel 0 is converted. In auto scan
// continuous conversion mode (ADC_SCAN_CONTI) the sequence is
// converted continuously. To start the conversion it is
// necessary to call ADC_vStartConv().
// Note:
// While a conversion is in progress, the mode and the channel
// may be changed. The new mode will be evaluated after the
// current conversion. The new channel will be evaluated after
// the current conversion (fixed channel modes) or after the
// current conversion sequence (auto scan modes). The
// following constants are available for ubMode:
// ADC_FIXED
// ADC_FIXED_CONTI
// ADC_SCAN
// ADC_SCAN_CONTI
//
// The following constants are available for ubChannel:
// ADC_ANA_0 .. ADC_ANA_7 and
// ADC_ANA_10 .. ADC_ANA_15 (see @Defines in header file)
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters ubMode:
// Conversion mode
// @Parameters ubChannel:
// Channel number
//
//----------------------------------------------------------------------------
// @Date 2007-4-12
//
//****************************************************************************
// USER CODE BEGIN (ConfConv,1)
// USER CODE END
void ADC_vConfConv(ubyte ubMode, ubyte ubChannel)
{
ADC_CON = (ADC_CON & 0xFF80) | (ubMode << 4) | (ubChannel);
} // End of function ADC_vConfConv
//****************************************************************************
// @Function uword ADC_uwRea