📄 uart.c.bak
字号:
/*************************************************************************
* Function Name : BusyUART1 *
* Description : This returns status whether the transmission *
* is in progress or not, by checking Status bit TRMT *
* Parameters : None *
* Return Value : char info whether transmission is in progress *
*************************************************************************/
char BusyUART1(void)
{
return(!U1STAbits.TRMT);
}
void OpenUART1(unsigned int config1,unsigned int config2, unsigned int ubrg)
{
U1BRG = ubrg; /* baud rate */
U1MODE = config1; /* operation settings */
U1STA = config2; /* TX & RX interrupt modes */
}
/*********************************************************************
* Function Name : CloseUART1 *
* Description : This function disables the UART and clears the *
* Interrupt enable & flag bits *
* Parameters : None *
* Return Value : None *
*********************************************************************/
void CloseUART1(void)
{
U1MODEbits.UARTEN = 0;
IEC0bits.U1RXIE = 0;
IEC0bits.U1TXIE = 0;
IFS0bits.U1RXIF = 0;
IFS0bits.U1TXIF = 0;
}
/*********************************************************************
* Function Name : WriteUART1 *
* Description : This function writes data into the UxTXREG, *
* Parameters : unsigned int data the data to be written *
* Return Value : None *
*********************************************************************/
void WriteUART1(unsigned int data)
{
if(U1MODEbits.PDSEL == 3)
U1TXREG = data;
else
U1TXREG = data & 0xFF;
}
/**********************************************************************
* Function Name : ConfigIntUART1 *
* Description : This function sets priority for RX,TX interrupt *
* and enable/disables the interrupt *
* Parameters : unsigned int config enable/disable and priority *
* Return Value : None *
**********************************************************************/
void ConfigIntUART1(unsigned int config)
{
/* clear IF flags */
IFS0bits.U1RXIF = 0;
IFS0bits.U1TXIF = 0;
/* set priority */
IPC2bits.U1RXIP = 0x0007 & config;
IPC2bits.U1TXIP = (0x0070 & config) >> 4;
/* enable/disable interrupt */
IEC0bits.U1RXIE = (0x0008 & config) >> 3;
IEC0bits.U1TXIE = (0x0080 & config) >> 7;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -