📄 asc0.c
字号:
//****************************************************************************
// @Module Asynchronous/Synchronous Serial Interface 0 (ASC0)
// @Filename ASC0.C
// @Project ASC0.dav
//----------------------------------------------------------------------------
// @Controller Infineon XC164CS-16F20
//
// @Compiler Keil
//
// @Codegenerator 2.8
//
// @Description This file contains functions that use the ASC0 module.
//
//----------------------------------------------------------------------------
// @Date 2007-5-29 19:54:39
//
//****************************************************************************
// 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 2007-5-29
//
//****************************************************************************
// 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:
/// -----------------------------------------------------------------------
/// - fractional divider as prescaler for baud rate timer is used
ASC0_FDV = 0x00E8; // load ASC0 fractional divider register
/// - required baud rate = 9.600 kbaud
/// - real baud rate = 9.600 kbaud
/// - deviation = 0.001 %
ASC0_BG = 0x003A; // 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
/// - fractional divider is enabled
ASC0_CON = 0x0811; // load ASC0 control register
/// -----------------------------------------------------------------------
/// FIFO Configuration:
/// -----------------------------------------------------------------------
/// - receive FIFO is disabled
/// - transmit FIFO is enabled
/// - transmit interrupt trigger level = 4
ASC0_RXFCON = 0x0402; // load ASC0 receive FIFO control register
ASC0_TXFCON = 0x0403; // 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) = 13
/// - Rx interrupt group level (GLVL) = 0
/// - Rx group priority extension (GPX) = 0
ASC0_RIC = 0x0074;
// 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 2007-5-29
//
//****************************************************************************
// 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 2007-5-29
//
//****************************************************************************
// 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 2007-5-29
//
//****************************************************************************
// USER CODE BEGIN (Rx,1)
// USER CODE END
void ASC0_viRx(void) interrupt ASC0_RINT
{
// USER CODE BEGIN (Rx,2)
uword data; // 定义接收变量
data=ASC0_uwGetData(); // 读取数据
ASC0_vSendData(data+1); // 发送修改后的数据
// USER CODE END
} // End of function ASC0_viRx
// USER CODE BEGIN (ASC0_General,10)
// USER CODE END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -