📄 ad2.c
字号:
/** ###################################################################
** THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : AD2.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-12, 下午 05:30
** Abstract :
** This device "ADC" implements an A/D converter,
** its control methods and interrupt/event handling procedure.
** Settings :
** AD control register : ATD0CTL2 [130]
** AD control register : ATD0CTL3 [131]
** AD control register : ATD0CTL4 [132]
** AD control register : ATD0CTL5 [133]
** AD control register : ATD0STAT0 [134]
** AD control register : ATD0STAT1 [139]
** AD control register : ATD0CTL23 [130]
** AD control register : ATD0CTL45 [132]
** AD control register : ATD0TEST1 [137]
** AD control register : ATD0DIEN [141]
** AD result register : ATD0DR0 [144]
** AD result register : ATD0DR1 [146]
** AD result register : ATD0DR2 [148]
** AD result register : ATD0DR3 [150]
** AD result register : ATD0DR4 [152]
** AD result register : ATD0DR5 [154]
** AD result register : ATD0DR6 [156]
** AD result register : ATD0DR7 [158]
** Interrupt name : Vatd0
** Interrupt enable reg. : ATD0CTL2 [130]
** Priority : 1
** User handling procedure : AD2_OnEnd
** Number of conversions : 1
** AD resolution : 8-bit
**
** Input pins
**
** Port name : AD0
** Bit number (in port) : 0
** Bit mask of the port : 1
** Port data register : PORTAD0 [143]
**
** Port name : AD0
** Bit number (in port) : 1
** Bit mask of the port : 2
** Port data register : PORTAD0 [143]
**
** Port name : AD0
** Bit number (in port) : 2
** Bit mask of the port : 4
** Port data register : PORTAD0 [143]
**
** Port name : AD0
** Bit number (in port) : 3
** Bit mask of the port : 8
** Port data register : PORTAD0 [143]
**
** Port name : AD0
** Bit number (in port) : 4
** Bit mask of the port : 16
** Port data register : PORTAD0 [143]
**
** Port name : AD0
** Bit number (in port) : 5
** Bit mask of the port : 32
** Port data register : PORTAD0 [143]
**
** Port name : AD0
** Bit number (in port) : 6
** Bit mask of the port : 64
** Port data register : PORTAD0 [143]
**
** Port name : AD0
** Bit number (in port) : 7
** Bit mask of the port : 128
** Port data register : PORTAD0 [143]
**
** Initialization:
** Conversion : Enabled
** Event : Enabled
** High speed mode
** Prescaler : divide-by-30
** Contents :
** Enable - byte AD2_Enable(void);
** Disable - byte AD2_Disable(void);
** Start - byte AD2_Start(void);
** Stop - byte AD2_Stop(void);
** Measure - byte AD2_Measure(bool WaitForResult);
** GetValue8 - byte AD2_GetValue8(byte *Values);
** GetChanValue8 - byte AD2_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 AD2. */
#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 "AD2.h"
#pragma DATA_SEG AD2_DATA
#pragma CODE_SEG AD2_CODE
#pragma CONST_SEG AD2_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 const byte Channels[] = { /* Contents for the device control register */
128,129,130,131,132,133,134,135};
static bool EnUser; /* Enable/Disable device */
static bool OutFlg; /* Measurement finish flag */
static byte SumChan; /* Number of measured channels */
volatile static byte ModeFlg; /* Current state of device */
static byte AD2_OutV[8]; /* Array of measured values */
/*
** ===================================================================
** Method : AD2_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(AD2_Interrupt)
{
if (ModeFlg == STOP) { /* Test if the device is in an allowed mode */
return; /* if not, return from the interrupt */
}
AD2_OutV[SumChan] = ATD0DR0L; /* Save measured value */
SumChan++; /* Number of measurement */
if (SumChan == 8) { /* Is number of measurement equal to the number of conversions? */
SumChan = 0; /* If yes then set the number of measurement to 0 */
OutFlg = TRUE; /* Measured values are available */
AD2_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 */
}
}
ATD0CTL5 = Channels[SumChan]; /* Start measurement of next channel */
}
#pragma CODE_SEG AD2_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 (!ATD0CTL2_ADPU) { /* Is device power down? */
ATD0CTL2_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 */
SumChan = 0; /* Set the number of measured channels to 0 */
/* ATD0CTL5: DJM=1,DSGN=0,SCAN=0,MULT=0,??=0,CC=0,CB=0,CA=0 */
ATD0CTL5 = 128; /* Start the conversion */
}
else {
/* ATD0CTL3: ??=0,S8C=0,S4C=0,S2C=0,S1C=1,FIFO=0,FRZ1=0,FRZ0=0 */
ATD0CTL3 = 8; /* Abort current measurement */
}
}
else {
ATD0CTL2_ADPU = 0; /* If no then device power down */
}
}
/*
** ===================================================================
** Method : AD2_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 AD2_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 : AD2_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 AD2_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 */
}
/*
** ===================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -