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

📄 as1.c

📁 mc68HC12C64的CAN部件例子程序,不错的.
💻 C
📖 第 1 页 / 共 2 页
字号:
**         DMA mode:
**         If DMA controller is available on the selected CPU and
**         the receiver is configured to use DMA controller then
**         this method returns the number of characters in the
**         receive buffer.
**     Parameters  : None
**     Returns     :
**         ---             - The number of characters in the input
**                           buffer.
** ===================================================================
*/
word AS1_GetCharsInRxBuf(void)
{
  return (SerFlag & CHAR_IN_RX) != 0;  /* Return number of chars in the 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.
**         DMA mode:
**         If DMA controller is available on the selected CPU and
**         the transmitter is configured to use DMA controller then
**         this method returns the number of characters in the
**         transmit buffer.
**     Parameters  : None
**     Returns     :
**         ---             - The number of characters in the output
**                           buffer.
** ===================================================================
*/
word AS1_GetCharsInTxBuf(void)
{
  return (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
#pragma INLINE
void AS1_InterruptRx(void)
{
  AS1_TComData Data;                   /* Temporary variable for data */
  byte OnFlags = 0;                    /* Temporary variable for flags */

  Data = SCIDRL;                       /* Read data from the receiver */
  if(SerFlag & CHAR_IN_RX) {           /* Is a character already present in the receive buffer? */
    SerFlag |= OVERRUN_ERR;            /* If yes then set flag OVERRUN_ERR */
  }
  SerFlag |= CHAR_IN_RX;               /* Set flag "char in RX buffer" */
  if(!(SerFlag & OVERRUN_ERR )) {      /* Is an overrun detected? */
    BufferRead = Data;
    OnFlags |= ON_RX_CHAR;             /* Set flag "OnRxChar" */
  }
    if(OnFlags & ON_RX_CHAR) {         /* Is OnRxChar flag set? */
      AS1_OnRxChar();                  /* If yes then invoke user event */
    }
}

/*
** ===================================================================
**     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
#pragma INLINE
void AS1_InterruptTx(void)
{
  SerFlag &= ~FULL_TX;                 /* Reset flag "full TX buffer" */
  SCICR2_SCTIE = 0;                    /* Disable transmit interrupt */
}

/*
** ===================================================================
**     Method      :  AS1_Interrupt (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.
** ===================================================================
*/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
ISR(AS1_Interrupt)
{
  byte StatReg = getReg(SCISR1);

  if (StatReg & (SCISR1_OR_MASK | SCISR1_FE_MASK | SCISR1_NF_MASK)) { /* Is any error flag set? */
    SerFlag |= COMMON_ERR;             /* If yes then set an internal flag */
    (void) SCIDRL;                     /* Dummy read of data register - clear error bits */
    StatReg &= ~SCISR1_RDRF_MASK;      /* Clear the receive data flag to discard the errorneous data */
  }
  if (StatReg & SCISR1_RDRF_MASK) {    /* Is the receiver interrupt flag set? */
    AS1_InterruptRx();                 /* If yes, then invoke the internal service routine. This routine is inlined. */
  }
  if (SCICR2_SCTIE) {                  /* Is the transmitter interrupt enabled? */
    if (StatReg & SCISR1_TDRE_MASK) {  /* Is the transmitter interrupt flag set? */
      AS1_InterruptTx();               /* If yes, then invoke the internal service routine. This routine is inlined. */
    }
  }
  if (StatReg & SCISR1_IDLE_MASK) {    /* Was the idle line condition detected? */
    (void) SCIDRL;                     /* Dummy read of the data register - clear the IDLE flag */
    SerFlag |= IDLE_ERR;
  }
}

#pragma CODE_SEG AS1_CODE
/*
** ===================================================================
**     Method      :  AS1_Init (bean AsynchroSerial)
**
**     Description :
**         Initializes the associated peripheral(s) and internal 
**         variables of the bean. 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 */
  /* SCICR1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
  setReg8(SCICR1, 0);                   
  /* SCISR2: ??=0,??=0,??=0,??=0,??=0,BRK13=0,TXDIR=0,RAF=0 */
  setReg8(SCISR2, 0);                   
  (void) SCISR1;                       /* Reset interrupt request flags */
  /* SCICR2: SCTIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
  SCICR2 = 0;                          /* Disable error interrupts */
  SCIBD = 26;                          /* Set prescaler bits */
  SCICR2 |= (SCICR2_TE_MASK | SCICR2_RE_MASK | SCICR2_RIE_MASK | SCICR2_ILIE_MASK); /* Enable transmitter, Enable receiver, Enable receiver interrupt, Enable idle interrupt */
}

/*
** ===================================================================
**     Method      :  AS1_GetRxIdle (bean AsynchroSerial)
**
**     Description :
**         Returns the state of the receiver idle flag. This method
**         is available only if event <OnIdle> is disabled.
**     Parameters  : None
**     Returns     :
**         ---             - The state of the receiver idle flag.
** ===================================================================
*/
bool AS1_GetRxIdle(void)
{
  bool Result;

  EnterCritical();                     /* Save the PS register */
  Result = (SerFlag & IDLE_ERR)?1:0;   /* If idle signal has been received? */
  SerFlag &= ~IDLE_ERR;                /* Reset idle signal flag */
  ExitCritical();                      /* Restore the PS register */
  return Result;                       /* OK */
}

/*
** ===================================================================
**     Method      :  AS1_GetTxComplete (bean AsynchroSerial)
**
**     Description :
**         Returns whether the transmitter is finished transmitting
**         all data, preamble, and break characters and is idle. It
**         can be used to determine when it is safe to switch a line
**         driver (e.g. in RS-485 applications). This method is
**         available only if event <OnTxComplete> is disabled.
**     Parameters  : None
**     Returns     :
**         ---             - Transmission process completeness.
** ===================================================================
*/
/*
bool AS1_GetTxComplete(void)

**      This method is implemented as a macro. See header module. **
*/



/* END AS1. */


/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 2.96 [03.76]
**     for the Freescale HCS12 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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