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

📄 as1.c

📁 用freescale 8bitMCU做的触摸屏软件
💻 C
📖 第 1 页 / 共 2 页
字号:
**         transmitter property is enabled.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Chr             - Character to send
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_TXFULL - Transmitter is full
** ===================================================================
*/
byte AS1_SendChar(AS1_TComData Chr)
{
  if(SerFlag & FULL_TX) {              /* Is any char is in TX buffer */
    return ERR_TXFULL;                 /* If yes then error */
  }
  EnterCritical();                     /* Save the PS register */
  (void)SCIS1;                         /* Reset interrupt request flag */
  SCID = (byte)Chr;                    /* Store char to transmitter register */
  SCIC2_TIE = 1;                       /* Enable transmit interrupt */
  SerFlag |= FULL_TX;                  /* Set the flag "full TX buffer" */
  ExitCritical();                      /* Restore the PS register */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  AS1_GetCharsInRxBuf (bean AsynchroSerial)
**
**     Description :
**         Returns the number of characters in the input buffer.
**         This method is available only if the receiver property is
**         enabled.
**     Parameters  : None
**     Returns     :
**         ---             - The number of characters in the input
**                           buffer.
** ===================================================================
*/
word AS1_GetCharsInRxBuf(void)
{
  return (word)((SerFlag & CHAR_IN_RX) != 0); /* Return number of chars in receive buffer */
}

/*
** ===================================================================
**     Method      :  AS1_GetCharsInTxBuf (bean AsynchroSerial)
**
**     Description :
**         Returns the number of characters in the output buffer.
**         This method is available only if the transmitter property
**         is enabled.
**     Parameters  : None
**     Returns     :
**         ---             - The number of characters in the output
**                           buffer.
** ===================================================================
*/
word AS1_GetCharsInTxBuf(void)
{
  return (word)((SerFlag & FULL_TX) != 0); /* Return number of chars in the transmitter buffer */
}

/*
** ===================================================================
**     Method      :  AS1_InterruptRx (bean AsynchroSerial)
**
**     Description :
**         The method services the receive interrupt of the selected 
**         peripheral(s) and eventually invokes the bean's event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#define ON_ERROR      1
#define ON_FULL_RX    2
#define ON_RX_CHAR    4
#define ON_IDLE_CHAR  8
ISR(AS1_InterruptRx)
{
  byte StatReg = SCIS1;                /* Temporary variable for status flags */
  AS1_TComData Data;                   /* Temporary variable for data */

  Data = SCID;                         /* Read data from the receiver */
  if(SerFlag & CHAR_IN_RX) {           /* Is any char already present in the receive buffer? */
    SerFlag |= OVERRUN_ERR;            /* If yes then set flag OVERRUN_ERR */
  }
  if(!(SerFlag & OVERRUN_ERR )) {      /* Is an overrun detected? */
    BufferRead = Data;
    SerFlag |= CHAR_IN_RX;             /* Set flag "char in RX buffer" */
  }
}

/*
** ===================================================================
**     Method      :  AS1_InterruptTx (bean AsynchroSerial)
**
**     Description :
**         The method services the receive interrupt of the selected 
**         peripheral(s) and eventually invokes the bean's event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#define ON_FREE_TX  1
#define ON_TX_CHAR  2
ISR(AS1_InterruptTx)
{
  if(SCIC2_TCIE && SCIS1_TC) {         /* Was the interrupt caused by the transmission complete flag? */
    SCIC2_TCIE = 0;                    /* Disable transmission complete interrupt */
      AS1_OnTxComplete();              /* Invoke user invent */
    return;
  }
  SerFlag &= ~FULL_TX;                 /* Reset flag "full TX buffer" */
  SCIC2_TIE = 0;                       /* Disable transmit interrupt */
  SCIC2_TCIE = 1;                      /* Enable transmission complete interrupt */
}

/*
** ===================================================================
**     Method      :  AS1_InterruptError (bean AsynchroSerial)
**
**     Description :
**         The method services the error interrupt of the selected 
**         peripheral(s) and eventually invokes the bean's event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
ISR(AS1_InterruptError)
{
  byte StatReg = getReg(SCIS1);

  (void)SCID;                          /* Dummy read of data register - clear error bits */
  if(StatReg & (SCIS1_OR_MASK|SCIS1_NF_MASK|SCIS1_FE_MASK|SCIS1_PF_MASK)) { /* Is an error detected? */
    SerFlag |= COMMON_ERR;             /* If yes then set an internal flag */
  }
}

/*
** ===================================================================
**     Method      :  AS1_Init (bean AsynchroSerial)
**
**     Description :
**         Initializes the associated peripheral(s) and the bean internal 
**         variables. The method is called automatically as a part of the 
**         application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void AS1_Init(void)
{
  SerFlag = 0;                         /* Reset flags */
  /* SCIC1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
  setReg8(SCIC1, 0x00);                /* Configure the SCI */ 
  /* SCIC3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
  setReg8(SCIC3, 0x00);                /* Disable error interrupts */ 
  /* SCIS2: ??=0,??=0,??=0,??=0,??=0,BRK13=0,??=0,RAF=0 */
  setReg8(SCIS2, 0x00);                 
  /* SCIC2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
  setReg8(SCIC2, 0x00);                /* Disable all interrupts */ 
  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 */
}



/* END AS1. */


/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 3.00 [03.89]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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