⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freescale

📁 Freescale 系列单片机常用模块与综合系统设计
💻
📖 第 1 页 / 共 2 页
字号:
/** ###################################################################
**     THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : Sensor.C
**     Project   : line_following_car
**     Processor : MC9S08JM60CLHE
**     Component : ADC
**     Version   : Component 01.580, Driver 01.26, CPU db: 3.00.046
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2010-1-19, 13:49
**     Abstract  :
**         This device "ADC" implements an A/D converter,
**         its control methods and interrupt/event handling procedure.
**     Settings  :
**         AD control register         : ADCSC1      [$0010]
**         AD control register         : ADCCFG      [$0016]
**         AD control register         : ADCRH       [$0012]
**         AD control register         : ADCRL       [$0013]
**         AD control register         : ADCCVH      [$0014]
**         AD control register         : ADCCVL      [$0015]
**         AD control register         : ADCSC2      [$0011]
**         AD control register         : APCTL1      [$0017]
**         AD control register         : APCTL2      [$0018]
**         User handling procedure     : not specified
**         Number of conversions       : 1
**         AD resolution               : 12-bit
**
**         Input pins
**
**              Port name              : PTB
**              Bit number (in port)   : 0
**              Bit mask of the port   : $0001
**              Port data register     : PTBD        [$0002]
**              Port control register  : PTBDD       [$0003]
**
**              Port name              : PTB
**              Bit number (in port)   : 1
**              Bit mask of the port   : $0002
**              Port data register     : PTBD        [$0002]
**              Port control register  : PTBDD       [$0003]
**
**              Port name              : PTB
**              Bit number (in port)   : 2
**              Bit mask of the port   : $0004
**              Port data register     : PTBD        [$0002]
**              Port control register  : PTBDD       [$0003]
**
**         Initialization:
**              Conversion             : Enabled
**              Event                  : Enabled
**         High speed mode
**             Prescaler               : divide-by-8
**     Contents  :
**         Enable         - byte Sensor_Enable(void);
**         Disable        - byte Sensor_Disable(void);
**         MeasureChan    - byte Sensor_MeasureChan(bool WaitForResult, byte Channel);
**         GetChanValue   - byte Sensor_GetChanValue(byte Channel, void* Value);
**         GetChanValue16 - byte Sensor_GetChanValue16(byte Channel, word *Value);
**
**     Copyright : 1997 - 2009 Freescale Semiconductor, Inc. All Rights Reserved.
**     
**     http      : www.freescale.com
**     mail      : support@freescale.com
** ###################################################################*/


/* MODULE Sensor. */

#include "Sensor.h"



static void Sensor_MainMeasure(void);
/*
** ===================================================================
**     Method      :  MainMeasure (component ADC)
**
**     Description :
**         The method performs the conversion of the input channels in 
**         the polling mode.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#define STOP            0              /* STOP state           */
#define MEASURE         1              /* MESURE state         */
#define CONTINUOUS      2              /* CONTINUOS state      */
#define SINGLE          3              /* SINGLE state         */

static const  byte Table[3] = {0x01,0x02,0x04};  /* Table of mask constants */

static const  byte Channels[3] = {0x00,0x01,0x02};  /* Contents for the device control register */

static bool EnUser;                    /* Enable/Disable device */
static byte OutFlg;                    /* Measurement finish flags */
static byte SumChan;                   /* Number of measured channels */
static byte ModeFlg;                   /* Current state of device */

volatile word Sensor_OutV[3];          /* Sum of measured values */



bool WaitForRes;                       /* Wait for result flag */


/*
** ===================================================================
**     Method      :  MainMeasure (component ADC)
**
**     Description :
**         The method performs the conversion of the input channels in 
**         the polling mode.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void Sensor_MainMeasure(void)
{

  ADCSC1 = Channels[SumChan];          /* Start measurement of next channel */
  if (!WaitForRes) {                   /* If doesn't wait for result */
    return;                            /* then return */
  }
  while (!ADCSC1_COCO) {}              /* Wait for AD conversion complete */
  ((TWREG*)(&Sensor_OutV[SumChan]))->b.high = ADCRH; /* Save measured value */
  ((TWREG*)(&Sensor_OutV[SumChan]))->b.low = ADCRL; /* Save measured value */
  OutFlg |= Table[SumChan];            /* Value of measured channel is available */
  ModeFlg = STOP;                      /* Set the device to the stop mode */
}
/*
** ===================================================================
**     Method      :  Sensor_HWEnDi (component ADC)
**
**     Description :
**         Enables or disables the peripheral(s) associated with the bean.
**         The method is called automatically as a part of the Enable and 
**         Disable methods and several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void Sensor_HWEnDi(void)
{
  if (EnUser) {                        /* Enable device? */
    if (ModeFlg) {                     /* Start or stop measurement? */
      OutFlg &= ~Table[SumChan];       /* Output value isn't available */
      Sensor_MainMeasure();
    }
  }
  else {
    ADCSC1 = 0x1F;                     /* Disable the device */
  }
}

/*
** ===================================================================
**     Method      :  Sensor_Enable (component ADC)
**
**     Description :
**         Enables A/D converter bean. <Events> may be generated
**         (<DisableEvent>/<EnableEvent>). If possible, this method
**         switches on A/D converter device, voltage reference, etc.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte Sensor_Enable(void)
{
  if (EnUser) {                        /* Is the device enabled by user? */
    return ERR_OK;                     /* If yes then set the flag "device enabled" */
  }
  EnUser = TRUE;                       /* Set the flag "device enabled" */
  Sensor_HWEnDi();                     /* Enable the device */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  Sensor_Disable (component ADC)
**
**     Description :
**         Disables A/D converter bean. No <events> will be generated.
**         If possible, this method switches off A/D converter device,
**         voltage reference, etc.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte Sensor_Disable(void)
{
  if (!EnUser) {                       /* Is the device disabled by user? */
    return ERR_OK;                     /* If yes then OK */
  }
  EnUser = FALSE;                      /* If yes then set the flag "device disabled" */
  Sensor_HWEnDi();                     /* Enable the device */
  return ERR_OK;                       /* OK */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -