?? asc0.c
字號:
//****************************************************************************
// @Module Asynchronous/Synchronous Serial Interface 0 (ASC0)
// @Filename ASC0.C
// @Project can_configure.dav
//----------------------------------------------------------------------------
// @Controller Infineon XC164CS-16F20
//
// @Compiler Keil
//
// @Codegenerator 2.8
//
// @Description This file contains functions that use the ASC0 module.
//
//----------------------------------------------------------------------------
// @Date 2009-4-4 17:03:46
//
//****************************************************************************
// USER CODE BEGIN (ASC0_General,1)
// USER CODE END
//****************************************************************************
// @Project Includes
//****************************************************************************
#include "MAIN.H"
// USER CODE BEGIN (ASC0_General,2)
// USER CODE END
//****************************************************************************
// @Macros
//****************************************************************************
// USER CODE BEGIN (ASC0_General,3)
// USER CODE END
//****************************************************************************
// @Defines
//****************************************************************************
// USER CODE BEGIN (ASC0_General,4)
// USER CODE END
//****************************************************************************
// @Typedefs
//****************************************************************************
// USER CODE BEGIN (ASC0_General,5)
// USER CODE END
//****************************************************************************
// @Imported Global Variables
//****************************************************************************
// USER CODE BEGIN (ASC0_General,6)
// USER CODE END
//****************************************************************************
// @Global Variables
//****************************************************************************
// USER CODE BEGIN (ASC0_General,7)
// USER CODE END
//****************************************************************************
// @External Prototypes
//****************************************************************************
// USER CODE BEGIN (ASC0_General,8)
// USER CODE END
//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************
// USER CODE BEGIN (ASC0_General,9)
// USER CODE END
//****************************************************************************
// @Function void ASC0_vInit(void)
//
//----------------------------------------------------------------------------
// @Description This is the initialization function of the ASC0 function
// library. It is assumed that the SFRs used by this library
// are in its reset state.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2009-4-4
//
//****************************************************************************
// USER CODE BEGIN (Init,1)
// USER CODE END
void ASC0_vInit(void)
{
// USER CODE BEGIN (Init,2)
// USER CODE END
/// -----------------------------------------------------------------------
/// Configuration of the ASC0 Baudrate Generator:
/// -----------------------------------------------------------------------
/// - additionally reduce serial clock to 2
/// - required baud rate = 19.200 kbaud
/// - real baud rate = 18.939 kbaud
/// - deviation = -1.357 %
ASC0_BG = 0x0020; // load ASC0 baud rate time reload register
/// -----------------------------------------------------------------------
/// Configuration of the ASC0 Operation Mode:
/// -----------------------------------------------------------------------
/// - 8-bit data asychronous operation with one stop bit
/// - receiver is enabled
ASC0_CON = 0x0011; // load ASC0 control register
/// -----------------------------------------------------------------------
/// FIFO Configuration:
/// -----------------------------------------------------------------------
/// - receive FIFO is disabled
/// - transmit FIFO is disabled
ASC0_RXFCON = 0x0102; // load ASC0 receive FIFO control register
ASC0_TXFCON = 0x0102; // load ASC0 transmit FIFO control register
/// -----------------------------------------------------------------------
/// Configuration of the used ASC0 Port Pins:
/// -----------------------------------------------------------------------
/// - P3.10 is used for ASC0 Transmit Data Output (TxDA0)
/// - P3.11 is used for ASC0 Receive data Input (RxDA0)
ALTSEL0P3 |= 0x0400; // select alternate output function
P3 = (P3 & ~(uword)0x0400) | 0x0400; //set data register
DP3 = (DP3 & ~(uword)0x0400) | 0x0400; //set direction register
/// -----------------------------------------------------------------------
/// Configuration of the used ASC0 Interrupts:
/// -----------------------------------------------------------------------
/// Rx service request node configuration:
/// - Rx interrupt priority level (ILVL) = 12
/// - Rx interrupt group level (GLVL) = 1
/// - Rx group priority extension (GPX) = 0
ASC0_RIC = 0x0071;
// -----------------------------------------------------------------------
// Default Settings for Service Request Flags:
// -----------------------------------------------------------------------
ASC0_TIC_IR = 1; // indicates that the transmit register is
// empty
// USER CODE BEGIN (ASC0_Function,3)
// USER CODE END
ASC0_CON |= 0x8000; // enable baud rate generator
} // End of function ASC0_vInit
//****************************************************************************
// @Function void ASC0_vSendData(uword uwData)
//
//----------------------------------------------------------------------------
// @Description This function writes a send data initialization word into
// the transmit buffer register.
//
// Note:
// In a multiprocessor system the master with this function
// has the possibility to send data to the selected slave. To
// achieve this, the 9th bit must set on zero.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters uwData:
// Data to be send
//
//----------------------------------------------------------------------------
// @Date 2009-4-4
//
//****************************************************************************
// USER CODE BEGIN (SendData,1)
// USER CODE END
void ASC0_vSendData(uword uwData)
{
ASC0_TBIC_IR = 0; // reset transmit buffer interrupt request
ASC0_TBUF = uwData; // load transmit buffer register
} // End of function ASC0_vSendData
//****************************************************************************
// @Function uword ASC0_uwGetData(void)
//
//----------------------------------------------------------------------------
// @Description This function reads out the content of the receive buffer
// register which contains the received data.
//
//----------------------------------------------------------------------------
// @Returnvalue data that has been received
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2009-4-4
//
//****************************************************************************
// USER CODE BEGIN (GetData,1)
// USER CODE END
uword ASC0_uwGetData(void)
{
return(ASC0_RBUF); // return receive buffer register
} // End of function ASC0_uwGetData
//****************************************************************************
// @Function void ASC0_viRx(void)
//
//----------------------------------------------------------------------------
// @Description This is the receive interrupt service routine for the ASC0.
// It is called if the data has been received.
// Please note that you have to add application specific code
// to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2009-4-4
//
//****************************************************************************
// USER CODE BEGIN (Rx,1)
unsigned char i=0;
// USER CODE END
void ASC0_viRx(void) interrupt ASC0_RINT
{
// USER CODE BEGIN (Rx,2)
unsigned char rec;
rec = ASC0_uwGetData(); //rec_data[1,2]-->radius;recdata[3,4]-->vehicle velocity
if (rec == 0xaf)
i=0;
rec_data[i]=rec;
i++;
if ((rec == 0xbf)&&(i == 6))
{ i=0;
asc0_rec=1;
}
// USER CODE END
} // End of function ASC0_viRx
//****************************************************************************
// @Function ubyte ASC0_ubTxDataReady(void)
//
//----------------------------------------------------------------------------
// @Description This function can be used for checking up the status of the
// ASC0 transmit interrupt flags. This shows when the sending
// of data has terminated. By continuously polling this flag
// after the function ASC0_vSendData has been called, it is
// possible to establish when the ASC0 has terminated its task.
//
//----------------------------------------------------------------------------
// @Returnvalue 0 if transmitter is busy, else 1
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2009-4-4
//
//****************************************************************************
// USER CODE BEGIN (TxDataReady,1)
// USER CODE END
ubyte ASC0_ubTxDataReady(void)
{
ubyte ubReturnValue;
ubReturnValue = 0;
if(ASC0_TIC_IR) // if sending of data is terminated
{
ubReturnValue = 1;
ASC0_TIC_IR = 0;
}
return(ubReturnValue); // return receive buffer register
} // End of function ASC0_ubTxDataReady
// USER CODE BEGIN (ASC0_General,10)
// USER CODE END
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -