#define  GLOBALS_BSP_SCI
#include "../app_Headers/g_includes.h"

/*-------------------------------------------------------------------------
* Function Name  : bsp_SCI_Init
* Description    : SCI模块初始化
* Input          : 
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
void bsp_SCI_Init(void)
{
    SCICR1_LOOPS   = Disable;   //串口正常模式
    SCICR1_SCISWAI = Enable;    //禁止等待模式
    SCICR1_M       = Disable;   //8 byte 模式
    SCICR1_WAKE    = Enable;    //Adrress Wake
    SCICR1_PE      = Disable;   //禁止校验
    SCISR1_RDRF    = Disable;

    SCIACR1_RXEDGIE = Disable;  //
    SCIACR1_BERRIE  = Disable;
    SCIACR1_BKDIE   = Disable;
    SCIACR2 = Disable;

    SCIBDH_TNP     = div4;
/*
When IREN = 0 then,
SCI baud rate = SCI bus g_Clock / (16 x SBR[12:0])
When IREN = 1 then,
SCI baud rate = SCI bus g_Clock / (32 x SBR[12:1])
*/
    SCIBDH_IREN    = Disable;   //禁止红外线
    SCIBD_SBR      = 20;//baud_38400;

    SCICR2_TIE  = Disable;
    SCICR2_TCIE = Disable;
    SCICR2_ILIE = Disable;
    SCICR2_RE  = Enable;    //使能接收
    SCICR2_TE  = Enable;    //使能发送
    SCICR2_RWU = Disable;
    SCICR2_SBK = Disable;   //使能发送
  
    SCICR2_RIE = Enable;    //使能接收中断
}
/*-------------------------------------------------------------------------
* Function Name  : bsp_SCI_Trans_Bytes
* Description    : 串口发送
* Input          : INT8U *str,INT16U len
* Output         : None
* Return         : None
* onther         : str:发送字符串   len:发送数据长度
--------------------------------------------------------------------------*/
void bsp_SCI_Trans_Bytes(INT8U *str,INT8U len)
{
    INT8U i;    
    for(i=0;i<len;i++)
    {
       bsp_SCI_Trans_Byte((*str));
       str++;
    }
}
/*-------------------------------------------------------------------------
* Function Name  : bsp_SCI_Trans_Byte
* Description    : 串口发送
* Input          : INT8U data
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
void  bsp_SCI_Trans_Byte(INT8U data)
{
    while(SCISR1_TDRE == null);
    SCIDRL = data;
    while(!SCISR1_TC);    
}
/*-------------------------------------------------------------------------
* Function Name  : bsp_SCI_Rev_isr
* Description    : 串口接收中断
* Input          : 
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
interrupt void bsp_SCI_Rev_isr(void)
{    
    INT8U  m_SCIRV;
    m_SCIRV = SCIDRL;

    SCISR1_RDRF = ClearFlag;
}