freescale

来自「Freescale 系列单片机常用模块与综合系统设计」· 代码 · 共 260 行

TXT
260
字号
/** ###################################################################
**     THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : Turning.C
**     Project   : line_following_car
**     Processor : MC9S08JM60CLHE
**     Component : BitsIO
**     Version   : Component 02.102, Driver 03.22, CPU db: 3.00.046
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2010-1-19, 13:25
**     Abstract  :
**         This bean "BitsIO" implements a multi-bit input/output.
**         It uses selected pins of one 1-bit to 8-bit port.
**         Note: This bean is set to work in Output direction only.
**     Settings  :
**         Port name                   : PTB
**
**         Bit mask of the port        : $0078
**         Number of bits/pins         : 4
**         Single bit numbers          : 0 to 3
**         Values range                : 0 to 15
**
**         Initial direction           : Output (direction cannot be changed)
**         Initial output value        : 0 = 000H
**         Initial pull option         : up
**
**         Port data register          : PTBD      [$0002]
**         Port control register       : PTBDD     [$0003]
**
**             ----------------------------------------------------
**                   Bit     |   Pin   |   Name
**             ----------------------------------------------------
**                    0      |    37   |   PTB3_SS2_ADP3
**                    1      |    38   |   PTB4_KBIP4_ADP4
**                    2      |    39   |   PTB5_KBIP5_ADP5
**                    3      |    40   |   PTB6_ADP6
**             ----------------------------------------------------
**
**         Optimization for            : speed
**     Contents  :
**         GetDir - bool Turning_GetDir(void);
**         GetVal - byte Turning_GetVal(void);
**         PutVal - void Turning_PutVal(byte Val);
**         GetBit - bool Turning_GetBit(byte Bit);
**         PutBit - void Turning_PutBit(byte Bit, bool Val);
**         SetBit - void Turning_SetBit(byte Bit);
**         ClrBit - void Turning_ClrBit(byte Bit);
**         NegBit - void Turning_NegBit(byte Bit);
**
**     Copyright : 1997 - 2009 Freescale Semiconductor, Inc. All Rights Reserved.
**     
**     http      : www.freescale.com
**     mail      : support@freescale.com
** ###################################################################*/

/* MODULE Turning. */

#include "Turning.h"
  /* Including shared modules, which are used in the whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "Cpu.h"


/*
** ===================================================================
**     Method      :  Turning_GetMsk (component BitsIO)
**
**     Description :
**         The method returns a bit mask which corresponds to the 
**         required bit position.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static const  byte Turning_Table[4] = { /* Table of mask constants */
   0x08, 0x10, 0x20, 0x40
};

static byte Turning_GetMsk (byte PinIndex)
{
  return (byte)(PinIndex<4 ? Turning_Table[PinIndex] : 0); /* Check range and return appropriate bit mask */
}

/*
** ===================================================================
**     Method      :  Turning_GetVal (component BitsIO)
**
**     Description :
**         This method returns an input value.
**           a) direction = Input  : reads the input value from the
**                                   pins and returns it
**           b) direction = Output : returns the last written value
**         Note: This bean is set to work in Output direction only.
**     Parameters  : None
**     Returns     :
**         ---        - Input value (0 to 15)
** ===================================================================
*/
byte Turning_GetVal(void)
{
  return (byte)((getReg8(PTBD) & 0x78) >> 3); /* Return port data */
}

/*
** ===================================================================
**     Method      :  Turning_PutVal (component BitsIO)
**
**     Description :
**         This method writes the new output value.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Val        - Output value (0 to 15)
**     Returns     : Nothing
** ===================================================================
*/
void Turning_PutVal(byte Val)
{
  Val = (byte)((Val & 0x0F) << 3);     /* Mask and shift output value */
  setReg8(PTBD, (getReg8(PTBD) & (~0x78)) | Val); /* Put masked value on port */
}

/*
** ===================================================================
**     Method      :  Turning_GetBit (component BitsIO)
**
**     Description :
**         This method returns the specified bit of the input value.
**           a) direction = Input  : reads the input value from pins
**                                   and returns the specified bit
**           b) direction = Output : returns the specified bit
**                                   of the last written value
**         Note: This bean is set to work in Output direction only.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to read (0 to 3)
**     Returns     :
**         ---        - Value of the specified bit (FALSE or TRUE)
**                      FALSE = "0" or "Low", TRUE = "1" or "High"
** ===================================================================
*/
bool Turning_GetBit(byte Bit)
{
  byte const Mask = Turning_GetMsk(Bit); /* Temporary variable - bit mask to test */
  return (bool)((getReg8(PTBD) & Mask) == Mask); /* Test if specified bit of port register is set */
}

/*
** ===================================================================
**     Method      :  Turning_PutBit (component BitsIO)
**
**     Description :
**         This method writes the new value to the specified bit
**         of the output value.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit (0 to 3)
**         Val        - New value of the bit (FALSE or TRUE)
**                      FALSE = "0" or "Low", TRUE = "1" or "High"
**     Returns     : Nothing
** ===================================================================
*/
void Turning_PutBit(byte Bit, bool Val)
{
  byte const Mask = Turning_GetMsk(Bit); /* Temporary variable - put bit mask */
  if (Val) {
    setReg8Bits(PTBD, Mask);           /* [bit (Bit+3)]=0x01 */
  } else { /* !Val */
    clrReg8Bits(PTBD, Mask);           /* [bit (Bit+3)]=0x00 */
  } /* !Val */
}

/*
** ===================================================================
**     Method      :  Turning_ClrBit (component BitsIO)
**
**     Description :
**         This method clears (sets to zero) the specified bit
**         of the output value.
**         [ It is the same as "PutBit(Bit,FALSE);" ]
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to clear (0 to 3)
**     Returns     : Nothing
** ===================================================================
*/
void Turning_ClrBit(byte Bit)
{
  byte const Mask = Turning_GetMsk(Bit); /* Temporary variable - set bit mask */
  clrReg8Bits(PTBD, Mask);             /* [bit (Bit+3)]=0x00 */
}

/*
** ===================================================================
**     Method      :  Turning_SetBit (component BitsIO)
**
**     Description :
**         This method sets (sets to one) the specified bit of the
**         output value.
**         [ It is the same as "PutBit(Bit,TRUE);" ]
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to set (0 to 3)
**     Returns     : Nothing
** ===================================================================
*/
void Turning_SetBit(byte Bit)
{
  byte const Mask = Turning_GetMsk(Bit); /* Temporary variable - set bit mask */
  setReg8Bits(PTBD, Mask);             /* [bit (Bit+3)]=0x01 */
}

/*
** ===================================================================
**     Method      :  Turning_NegBit (component BitsIO)
**
**     Description :
**         This method negates (inverts) the specified bit of the
**         output value.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to invert (0 to 31)
**     Returns     : Nothing
** ===================================================================
*/
void Turning_NegBit(byte Bit)
{
  byte const Mask = Turning_GetMsk(Bit); /* Temporary variable - set bit mask */
  invertReg8Bits(PTBD, Mask);          /* [bit (Bit+3)]=invert */
}

/*
** ===================================================================
**     Method      :  Turning_GetDir (component BitsIO)
**
**     Description :
**         This method returns direction of the bean.
**     Parameters  : None
**     Returns     :
**         ---        - Direction of the bean (always TRUE, Output only)
**                      FALSE = Input, TRUE = Output
** ===================================================================
*/
/*
bool Turning_GetDir(void)

**  This method is implemented as a macro. See Turning.h file.  **
*/


/* END Turning. */
/*
** ###################################################################
**
**     This file was created by Processor Expert 3.07 [04.34]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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