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

📄 ad3.c

📁 飞思卡尔智能车的程序。红外循迹
💻 C
📖 第 1 页 / 共 2 页
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : AD3.C
**     Project   : che_free
**     Processor : MC9S12DG128BCPV
**     Beantype  : ADC
**     Version   : Bean 01.354, Driver 01.09, CPU db: 2.87.280
**     Compiler  : Metrowerks HC12 C Compiler
**     Date/Time : 2008-3-13, 下午 09:15
**     Abstract  :
**         This device "ADC" implements an A/D converter,
**         its control methods and interrupt/event handling procedure.
**     Settings  :
**         AD control register         : ATD1CTL2    [290]
**         AD control register         : ATD1CTL3    [291]
**         AD control register         : ATD1CTL4    [292]
**         AD control register         : ATD1CTL5    [293]
**         AD control register         : ATD1STAT0   [294]
**         AD control register         : ATD1STAT1   [299]
**         AD control register         : ATD1CTL23   [290]
**         AD control register         : ATD1CTL45   [292]
**         AD control register         : ATD1TEST1   [297]
**         AD control register         : ATD1DIEN    [301]
**         AD result register          : ATD1DR0     [304]
**         Interrupt name              : Vatd1
**         Interrupt enable reg.       : ATD1CTL2    [290]
**         Priority                    : 0
**         User handling procedure     : AD3_OnEnd
**         Number of conversions       : 1
**         AD resolution               : 8-bit
**
**         Input pins
**
**              Port name              : AD1
**              Bit number (in port)   : 0
**              Bit mask of the port   : 1
**              Port data register     : PORTAD1     [303]
**
**         Initialization:
**              Conversion             : Enabled
**              Event                  : Enabled
**         High speed mode
**             Prescaler               : divide-by-30
**     Contents  :
**         Enable        - byte AD3_Enable(void);
**         Disable       - byte AD3_Disable(void);
**         Start         - byte AD3_Start(void);
**         Stop          - byte AD3_Stop(void);
**         Measure       - byte AD3_Measure(bool WaitForResult);
**         GetValue8     - byte AD3_GetValue8(byte *Values);
**         GetChanValue8 - byte AD3_GetChanValue8(byte Channel,byte *Value);
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2005
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/


/* MODULE AD3. */

#pragma MESSAGE DISABLE C5703          /* Disable warning C5703 "Parameter is not referenced" */
#pragma MESSAGE DISABLE C4002          /* Disable warning C4002 "Result not used is ignored" */
#pragma MESSAGE DISABLE C12056         /* Disable warning C12056 "SP debug info incorrect because of optimization or inline assembler" */

#include "Events.h"
#include "AD3.h"

#pragma DATA_SEG AD3_DATA
#pragma CODE_SEG AD3_CODE
#pragma CONST_SEG AD3_CONST            /* Constant section for this module */

#define STOP            0              /* STOP state           */
#define MEASURE         1              /* MESURE state         */
#define CONTINUOUS      2              /* CONTINUOUS state      */
#define SINGLE          3              /* SINGLE state         */

static bool EnUser;                    /* Enable/Disable device */
static bool OutFlg;                    /* Measurement finish flag */
volatile static byte ModeFlg;          /* Current state of device */
static byte AD3_OutV;                  /* Array of measured values */
/*
** ===================================================================
**     Method      :  AD3_Interrupt (bean ADC)
**
**     Description :
**         The method services the interrupt of the selected peripheral(s)
**         and eventually invokes of the bean event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
ISR(AD3_Interrupt)
{
  if (ModeFlg == STOP) {               /* Test if the device is in an allowed mode */
    return;                            /* if not, return from the interrupt */
  }
  AD3_OutV = ATD1DR0L;                 /* Save measured value */
  OutFlg = TRUE;                       /* Measured values are available */
  AD3_OnEnd();                         /* Invoke user event */
  if (ModeFlg == MEASURE) {            /* Is the device in the measure state? */
    ModeFlg = STOP;                    /* Set the device to the stop mode */
    return;                            /* Return from interrupt */
  }
  /* ATD1CTL5: DJM=1,DSGN=0,SCAN=0,MULT=0,??=0,CC=0,CB=0,CA=0 */
  ATD1CTL5 = 128;                      /* Restart measurement */
}

#pragma CODE_SEG AD3_CODE
/*
** ===================================================================
**     Method      :  HWEnDi (bean 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.
** ===================================================================
*/
static void HWEnDi(void)
{
  volatile byte i;

  if (EnUser) {                        /* Enable device? */
    if (!ATD1CTL2_ADPU) {              /* Is device power down? */
      ATD1CTL2_ADPU = 1;               /* If yes then device power up */
      for (i=0;i<100;i++) {}           /* Recovery time */
    }
    if (ModeFlg) {                     /* Start or stop measurement? */
      OutFlg = FALSE;                  /* Output values aren't available */
      /* ATD1CTL5: DJM=1,DSGN=0,SCAN=0,MULT=0,??=0,CC=0,CB=0,CA=0 */
      ATD1CTL5 = 128;                  /* Start the conversion */
    }
    else {
      /* ATD1CTL3: ??=0,S8C=0,S4C=0,S2C=0,S1C=1,FIFO=0,FRZ1=0,FRZ0=0 */
      ATD1CTL3 = 8;                    /* Abort current measurement */
    }
  }
  else {
    ATD1CTL2_ADPU = 0;                 /* If no then device power down */
  }
}

/*
** ===================================================================
**     Method      :  AD3_Enable (bean 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 AD3_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" */
  HWEnDi();                            /* Enable the device */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  AD3_Disable (bean 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 AD3_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" */
  HWEnDi();                            /* Enable the device */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  AD3_Start (bean ADC)
**
**     Description :
**         This method starts continuous conversion on all channels
**         that are set in the bean inspector. When each measurement
**         on all channels has finished the <OnEnd > event may be
**         invoked. This method is not available if the <interrupt
**         service> is disabled and the device doesn't support the
**         continuous mode. Note: If time of measurement is too
**         short and the instruction clock is too slow then the
**         conversion complete interrupt and its handler may cause a
**         system overflow.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED - Device is disabled
**                           ERR_BUSY - A conversion is already

⌨️ 快捷键说明

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