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

📄 ad1.c

📁 我在开发CC2500和CC1100时就用了SmartRF Studio调试软硬件,很好用的,我可以做出兼容chipcon的SmartRF 硬件,不知道有没人有兴趣?
💻 C
📖 第 1 页 / 共 2 页
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : AD1.C
**     Project   : Project_1
**     Processor : MC9S08QD4CPC
**     Beantype  : ADC
**     Version   : Bean 01.404, Driver 01.16, CPU db: 2.87.049
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2008-2-18, 13:59
**     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         : ADCR        [$0012]
**         AD control register         : ADCRL       [$0013]
**         AD control register         : ADCCV       [$0014]
**         AD control register         : ADCCVL      [$0015]
**         AD control register         : ADCSC2      [$0011]
**         AD control register         : APCTL1      [$0017]
**         AD result register          : ADCres      [$0012]
**         AD result register          : ADCres      [$0012]
**         AD result register          : ADCres      [$0012]
**         AD result register          : ADCres      [$0012]
**         User handling procedure     : not specified
**         Number of conversions       : 1
**         AD resolution               : 8-bit
**
**         Input pins
**
**              Port name              : PTA
**              Bit number (in port)   : 0
**              Bit mask of the port   : $0001
**              Port data register     : PTAD        [$0000]
**              Port control register  : PTADD       [$0001]
**              Port function register : KBIPE       [$000D]
**
**              Port name              : PTA
**              Bit number (in port)   : 1
**              Bit mask of the port   : $0002
**              Port data register     : PTAD        [$0000]
**              Port control register  : PTADD       [$0001]
**              Port function register : KBIPE       [$000D]
**
**              Port name              : PTA
**              Bit number (in port)   : 2
**              Bit mask of the port   : $0004
**              Port data register     : PTAD        [$0000]
**              Port control register  : PTADD       [$0001]
**              Port function register : KBIPE       [$000D]
**
**              Port name              : PTA
**              Bit number (in port)   : 3
**              Bit mask of the port   : $0008
**              Port data register     : PTAD        [$0000]
**              Port control register  : PTADD       [$0001]
**              Port function register : KBIPE       [$000D]
**
**         Initialization:
**              Conversion             : Enabled
**              Event                  : Enabled
**         High speed mode
**             Prescaler               : divide-by-8
**     Contents  :
**         MeasureChan          - byte AD1_MeasureChan(bool WaitForResult, byte Channel);
**         EnableIntChanTrigger - byte AD1_EnableIntChanTrigger(byte Channel);
**         GetChanValue         - byte AD1_GetChanValue(byte Channel, void* Value);
**         GetChanValue8        - byte AD1_GetChanValue8(byte Channel, byte *Value);
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2006
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/


/* MODULE AD1. */

#include "AD1.h"



static void AD1_MainMeasure(void);
/*
** ===================================================================
**     Method      :  MainMeasure (bean 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[4] = {0x01,0x02,0x04,0x08};  /* Table of mask constants */

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

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

byte AD1_OutV[4];                      /* Sum of measured values */



bool WaitForRes;                       /* Wait for result flag */


/*
** ===================================================================
**     Method      :  MainMeasure (bean 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 AD1_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 */
  AD1_OutV[SumChan] = ADCRL;           /* Save measured value */
  OutFlg |= Table[SumChan];            /* Value of measured channel is available */
  if(!ADCSC2_ADTRG)                    /* If the device is not in trigger mode */
    ModeFlg = STOP;                    /* Set the device to the stop mode */
}
/*
** ===================================================================
**     Method      :  AD1_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.
** ===================================================================
*/
void AD1_HWEnDi(void)
{
  if (ModeFlg) {                       /* Start or stop measurement? */
    OutFlg &= ~Table[SumChan];         /* Output value isn't available */
    AD1_MainMeasure();
  }
}

/*
** ===================================================================
**     Method      :  AD1_MeasureChan (bean ADC)
**
**     Description :
**         This method performs measurement on one channel. (Note:
**         If the <number of conversions> is more than one the
**         conversion of the A/D channel is performed specified
**         number of times.)
**     Parameters  :
**         NAME            - DESCRIPTION
**         WaitForResult   - Wait for a result
**                           of conversion. If the <interrupt service>
**                           is disabled and at the same time a
**                           <number of conversions> is greater than
**                           1, the WaitForResult parameter is
**                           ignored and the method waits for each
**                           result every time.
**         Channel         - Channel number. If only one
**                           channel in the bean is set this
**                           parameter is ignored, because the
**                           parameter is set inside this method.
**     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
**                           running
**                           ERR_RANGE - Parameter "Channel" out of
**                           range
** ===================================================================
*/
byte AD1_MeasureChan(bool WaitForResult,byte Channel)
{
  if (Channel >= 4) {                  /* Is channel number greater than or equal to 4 */
    return ERR_RANGE;                  /* If yes then error */
  }
  if (ModeFlg != STOP) {               /* Is the device in different mode than "stop"? */
    return ERR_BUSY;                   /* If yes then error */
  }
  ModeFlg = SINGLE;                    /* Set state of device to the measure mode */
  SumChan = Channel;                   /* Set required channel */
  WaitForRes = WaitForResult;          /* Save Wait for result flag */
  ADCSC2_ADTRG = 0;                    /* Select SW trigger */

⌨️ 快捷键说明

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