/*
** ###################################################################
**
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**
**     Filename  : Byte1.C
**
**     Project   : Full1
** 
**     Processor : MC68HC908AZ60MFU
**
**     Beantype  : ByteIO
**
**     Version   : Bean 02.013, Driver 02.10, CPU db: 2.81.019
**
**     Compiler  : Metrowerks HC08 C Compiler V-5.0.13
**
**     Date/Time : 2.4.2002, 9:36
**
**     Abstract  :
**
**         This bean "ByteIO" implements an one-byte input/output.
**         It uses one 8-bit port.
**         Methods of this bean are mostly implemented as a macros 
**         (if supported by target langauage and compiler).
**
**     Settings  :
**
**         Port name                   : PTA
**
**         Initial direction           : Output (direction can be changed)
**         Safe mode                   : yes
**         Initial output value        : 0 = 000H
**         Initial pull option         : off
**
**         8-bit data register         : PTA       [0]
**         8-bit control register      : DDRA      [4]
**
**             ----------------------------------------------------
**                   Bit     |   Pin   |   Name
**             ----------------------------------------------------
**                    0      |    26   |   PTA0
**                    1      |    27   |   PTA1
**                    2      |    28   |   PTA2
**                    3      |    29   |   PTA3
**                    4      |    30   |   PTA4
**                    5      |    31   |   PTA5
**                    6      |    32   |   PTA6
**                    7      |    33   |   PTA7
**             ----------------------------------------------------
**
**     Contents  :
**
**         GetDir - bool Byte1_GetDir(void);
**         SetDir - void Byte1_SetDir(bool Dir);
**         GetVal - byte Byte1_GetVal(void);
**         PutVal - void Byte1_PutVal(byte Val);
**         GetBit - bool Byte1_GetBit(byte Bit);
**         PutBit - void Byte1_PutBit(byte Bit,bool Val);
**         SetBit - void Byte1_SetBit(byte Bit);
**         ClrBit - void Byte1_ClrBit(byte Bit);
**         NegBit - void Byte1_NegBit(byte Bit);
**
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2002
**
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
**
** ###################################################################
*/

#include "Byte1.h"

/*Including shared modules, which are used for all project*/
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "PE_Timer.h"
#include "PE_Cnvrt.h"
#include "Cpu.h"

/*
** ===================================================================
**     Method      :  Byte1_GetMsk (bean ByteIO)
**
**     Description :
**         This method is internal. It is used by Processor Expert
**         only.
** ===================================================================
*/
byte Byte1_Table[8]={ 1, 2, 4, 8, 16, 32, 64, 128 }; /* Table of mask constants */

byte Byte1_GetMsk(byte Value)
{
  return((Value<8)?Byte1_Table[Value]:0); /* Return appropriate bit mask */
}

/*
** ===================================================================
**     Method      :  Byte1_GetVal (bean ByteIO)
**
**     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
**     Parameters  : None
**     Returns     :
**         ---        - Input value (0 to 255)
** ===================================================================
*/
/*
byte Byte1_GetVal(void)

**  This method is implemented as a macro. See Byte1.inc file.  **
*/

/*
** ===================================================================
**     Method      :  Byte1_PutVal (bean ByteIO)
**
**     Description :
**         This method writes the new output value.
**           a) direction = Input  : sets the new output value;
**                                   this operation will be shown on
**                                   output after the direction has
**                                   been switched to output
**                                   (SetDir(TRUE);)
**           b) direction = Output : directly writes the value to the
**                                   appropriate pins
**     Parameters  :
**         NAME       - DESCRIPTION
**         Value      - Output value (0 to 255)
**     Returns     : Nothing
** ===================================================================
*/
/*
void Byte1_PutVal(byte Value)

**  This method is implemented as a macro. See Byte1.inc file.  **
*/

/*
** ===================================================================
**     Method      :  Byte1_GetBit (bean ByteIO)
**
**     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
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bitnum     - Number of the bit to read (0 to 7)
**     Returns     :
**         ---        - Value of the specified bit (FALSE or TRUE)
**                      FALSE = "0" or "Low", TRUE = "1" or "High"
** ===================================================================
*/
bool Byte1_GetBit(byte BitNum)
{
  byte Mask=Byte1_GetMsk(BitNum);      /* Temporary variable - bit mask */
  byte Val;                            /* Temporary variable */
  byte Result=0;                       /* Temporary variable */

  if (Mask) {                          /* Is bit mask correct? */
    Val = PTA;                         /* Load of actual value of the port */
    Val &= Mask;                       /* Mask appropriate bit */
    Result = (Val == Mask);            /* If value of masked bit is non-zero then store logical one to the variable Result */
  }
  return(Result);                      /* Return input value */
}

/*
** ===================================================================
**     Method      :  Byte1_PutBit (bean ByteIO)
**
**     Description :
**         This method writes the new value to the specified bit
**         of the output value.
**           a) direction = Input  : sets the value of the specified
**                                   bit; this operation will be
**                                   shown on output after the
**                                   direction has been switched to
**                                   output (SetDir(TRUE);)
**           b) direction = Output : directly writes the value of the
**                                   bit to the appropriate pin
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bitnum     - Number of the bit (0 to 7)
**         Val        - New value of the bit (FALSE or TRUE)
**                      FALSE = "0" or "Low", TRUE = "1" or "High"
**     Returns     : Nothing
** ===================================================================
*/
void Byte1_PutBit(byte BitNum, byte Value)
{
  byte Mask=Byte1_GetMsk(BitNum);      /* Temporary variable - bit mask */

  if (Mask)                            /* Is bit mask correct? */
    if (Value) {                       /* Is it one to be written? */
      Shadow_PTA |= Mask;              /* Set appropriate bit in shadow variable */
      PTA |= Mask;                     /* Set appropriate bit on port */
    }
    else {                             /* Is it zero to be written? */
      Shadow_PTA &= ~Mask;             /* Clear appropriate bit in shadow variable */
      PTA &= ~Mask;                    /* Clear appropriate bit on port */
    }
}

/*
** ===================================================================
**     Method      :  Byte1_SetBit (bean ByteIO)
**
**     Description :
**         This method sets (sets to one) the specified bit of the
**         output value.
**         [ It is the same as "PutBit(Bit,TRUE);" ]
**           a) direction = Input  : sets the specified bit to "1";
**                                   this operation will be shown on
**                                   output after the direction has
**                                   been switched to output
**                                   (SetDir(TRUE);)
**           b) direction = Output : directly writes "1" to the
**                                   appropriate pin
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bitnum     - Number of the bit to set (0 to 7)
**     Returns     : Nothing
** ===================================================================
*/
void Byte1_SetBit(byte BitNum)
{
  byte Mask=Byte1_GetMsk(BitNum);      /* Temporary variable - bit mask */

  if (Mask) {                          /* Is bit mask correct? */
    Shadow_PTA |= Mask;                /* Set appropriate bit in shadow variable */
    PTA |= Mask;                       /* Set appropriate bit on port */
  }
}

/*
** ===================================================================
**     Method      :  Byte1_ClrBit (bean ByteIO)
**
**     Description :
**         This method clears (sets to zero) the specified bit
**         of the output value.
**         [ It is the same as "PutBit(Bit,FALSE);" ]
**           a) direction = Input  : sets the specified bit to "0";
**                                   this operation will be shown on
**                                   output after the direction has
**                                   beenswitched to output
**                                   (SetDir(TRUE);)
**           b) direction = Output : directly writes "0" to the
**                                   appropriate pin
**     Parameters  :
**         NAME       - DESCRIPTION
**         BitNum     - Number of the bit to clear (0 to 7)
**     Returns     : Nothing
** ===================================================================
*/
void Byte1_ClrBit(byte BitNum)
{
  byte Mask=Byte1_GetMsk(BitNum);      /* Temporary variable - bit mask */

  if (Mask) {                          /* Is bit mask correct? */
    Shadow_PTA &= ~Mask;               /* Clear appropriate bit in shadow variable */
    PTA &= ~Mask;                      /* Clear appropriate bit on port */
  }
}

/*
** ===================================================================
**     Method      :  Byte1_NegBit (bean ByteIO)
**
**     Description :
**         This method negates (invertes) the specified bit of the
**         output value.
**           a) direction = Input  : invertes the specified bit;
**                                   this operation will be shown on
**                                   output after the direction has
**                                   been switched to output
**                                   (SetDir(TRUE);)
**           b) direction = Output : directly invertes the value
**                                   of the appropriate pin
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to invert (0 to 7)
**     Returns     : Nothing
** ===================================================================
*/
void Byte1_NegBit(byte BitNum)
{
  byte Mask=Byte1_GetMsk(BitNum);      /* Temporary variable - bit mask */

  if (Mask) {                          /* Is bit mask correct? */
    Shadow_PTA ^= Mask;                /* Negate appropriate bit in shadow variable */
    PTA ^= Mask;                       /* Negate appropriate bit on port */
  }
}

/*
** ===================================================================
**     Method      :  Byte1_SetDir (bean ByteIO)
**
**     Description :
**         This method sets direction of the bean.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Dir        - Direction to set (FALSE or TRUE)
**                      FALSE = Input, TRUE = Output
**     Returns     : Nothing
** ===================================================================
*/
void Byte1_SetDir(byte Output)
{
  if (Output) {                        /* Is given direction output? */
    PTA = Shadow_PTA;                  /* Restore correct value of output from shadow variable */
    DDRA = 255;                        /* Set direction to output */
  }
  else                                 /* Is direction input? */
    DDRA = 0;                          /* Set direction to input */
}

/*
** ===================================================================
**     Method      :  Byte1_GetDir (bean ByteIO)
**
**     Description :
**         This method returns direction of the bean.
**     Parameters  : None
**     Returns     :
**         ---        - Direction of the bean (FALSE or TRUE)
**                      FALSE = Input, TRUE = Output
** ===================================================================
*/
/*
bool Byte1_GetDir(void)

**  This method is implemented as a macro. See Byte1.inc file.  **
*/

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 02.84 for 
**     the Motorola HC08 series of microcontrollers.
**
** ###################################################################
*/
