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

📄 as1.c

📁 用freescale 8bitMCU做的触摸屏软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : AS1.C
**     Project   : touchpanal
**     Processor : MC9S08QG8CDT
**     Beantype  : AsynchroSerial
**     Version   : Bean 02.420, Driver 01.21, CPU db: 2.87.115
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2007-10-9, 12:20
**     Abstract  :
**         This bean "AsynchroSerial" implements an asynchronous serial
**         communication. The bean supports different settings of
**         parity, word width, stop-bit and communication speed,
**         user can select interrupt or polling handler.
**         Communication speed can be changed also in runtime.
**         The bean requires one on-chip asynchronous serial channel.
**     Settings  :
**         Serial channel              : SCI
**
**         Protocol
**             Init baud rate          : 9020_689655baud
**             Width                   : 8 bits
**             Stop bits               : 1
**             Parity                  : none
**             Breaks                  : Disabled
**
**         Registers
**             Input buffer            : SCID      [$0027]
**             Output buffer           : SCID      [$0027]
**             Control register        : SCIC1     [$0022]
**             Mode register           : SCIC2     [$0023]
**             Baud setting reg.       : SCIBD     [$0020]
**             Special register        : SCIS1     [$0024]
**
**         Input interrupt
**             Vector name             : Vscirx
**             Priority                : undef
**
**         Output interrupt
**             Vector name             : Vscitx
**             Priority                : undef
**
**         Used pins:
**         ----------------------------------------------------------
**           Function | On package           |    Name
**         ----------------------------------------------------------
**            Input   |     12               |  PTB0_KBIP4_RxD_ADP4
**            Output  |     11               |  PTB1_KBIP5_TxD_ADP5
**         ----------------------------------------------------------
**
**
**
**     Contents  :
**         Enable          - byte AS1_Enable(void);
**         RecvChar        - byte AS1_RecvChar(AS1_TComData *Chr);
**         SendChar        - byte AS1_SendChar(AS1_TComData Chr);
**         GetCharsInRxBuf - word AS1_GetCharsInRxBuf(void);
**         GetCharsInTxBuf - word AS1_GetCharsInTxBuf(void);
**
**     (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 AS1. */

#pragma MESSAGE DISABLE C4002 /* WARNING C4002: Result not used is ignored */

#include "AS1.h"
#include "Events.h"




#define OVERRUN_ERR      0x01          /* Overrun error flag bit   */
#define COMMON_ERR       0x02          /* Common error of RX       */
#define CHAR_IN_RX       0x04          /* Char is in RX buffer     */
#define FULL_TX          0x08          /* Full transmit buffer     */


static byte SerFlag;                   /* Flags for serial communication */
                                       /* Bit 0 - Overrun error */
                                       /* Bit 1 - Common error of RX */
                                       /* Bit 2 - Char in RX buffer */
                                       /* Bit 3 - Full TX buffer */
static AS1_TComData BufferRead;        /* Input char for SCI commmunication */

/*
** ===================================================================
**     Method      :  AS1_Enable (bean AsynchroSerial)
**
**     Description :
**         Enables the bean - it starts the send and receive
**         functions. Events may be generated
**         ("DisableEvent"/"EnableEvent").
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte AS1_Enable(void)
{
  if(SCIS1_TDRE && !SCIS1_TC) {        /* Test if there is an unsent character in the shift register */
    SCIC2_TCIE = 1;                    /* Enable transmission complete interrupt */
  }
  SCIBDH = 0x00;                       /* Set high divisor register (enable device) */
  SCIBDL = 0x1D;                       /* Set low divisor register (enable device) */
      /* SCIC3: ORIE=1,NEIE=1,FEIE=1,PEIE=1 */
  SCIC3 |= 0x0F;                       /* Enable error interrupts */
  SCIC2 |= ( SCIC2_TE_MASK | SCIC2_RE_MASK | SCIC2_RIE_MASK); /*  Enable transmitter, Enable receiver, Enable receiver interrupt */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  AS1_RecvChar (bean AsynchroSerial)
**
**     Description :
**         If any data is received, this method returns one
**         character, otherwise it returns an error code (it does
**         not wait for data). This method is enabled only if the
**         receiver property is enabled.
**         [Note:] Because the preferred method to handle error and
**         break exception in the interrupt mode is to use events
**         <OnError> and <OnBreak> the return value ERR_RXEMPTY has
**         higher priority than other error codes. As a consequence
**         the information about an exception in interrupt mode is
**         returned only if there is a valid character ready to be
**         read.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Chr             - Pointer to a received character
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_RXEMPTY - No data in receiver
**                           ERR_BREAK - Break character is detected
**                           (only when the <Interrupt service>
**                           property is disabled and the <Break
**                           signal> property is enabled)
**                           ERR_COMMON - common error occurred (the
**                           <GetError> method can be used for error
**                           specification)
** ===================================================================
*/
byte AS1_RecvChar(AS1_TComData *Chr)
{
  byte Result = ERR_OK;                /* Return error code */

  if(!(SerFlag & CHAR_IN_RX)) {        /* Is any char in RX buffer? */
    return ERR_RXEMPTY;                /* If no then error */
  }
  EnterCritical();                     /* Save the PS register */
  *Chr = BufferRead;                   /* Received char */
  Result = (byte)((SerFlag & (OVERRUN_ERR|COMMON_ERR))?ERR_COMMON:ERR_OK);
  SerFlag &= ~(OVERRUN_ERR|COMMON_ERR|CHAR_IN_RX); /* Clear all errors in the status variable */
  ExitCritical();                      /* Restore the PS register */
  return Result;                       /* Return error code */
}

/*
** ===================================================================
**     Method      :  AS1_SendChar (bean AsynchroSerial)
**
**     Description :
**         Sends one character to the channel. If the bean is
**         temporarily disabled (Disable method) SendChar method
**         only stores data into an output buffer. In case of a zero
**         output buffer size, only one character can be stored.
**         Enabling the bean (Enable method) starts the transmission
**         of the stored data. This method is available only if the

⌨️ 快捷键说明

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