📄 rs485.c
字号:
#include "..\APP\config.h"
/*
*********************************************************************************************************
** 函数名称 :UART0_GetByte()
** 函数功能 :从串口接收1字节数据,使用查询方式接收。
** 入口参数 :无
** 出口参数 :接收到的数据
*********************************************************************************************************
*/
uint8 UART0_GetByte (void)
{
uint8 rcv_dat;
IO0CLR |=1<<31;
while ((U0LSR & 0x01) == 0);
rcv_dat = U0RBR;
return (rcv_dat);
}
/*
*********************************************************************************************************
** 函数名称 :UART0_GetStr()
** 函数功能 :从串口接收
** 入口参数 : s 指向接收数据数组的指针
** n 接收的个数
** 出口参数 : 无
*********************************************************************************************************
*/
void UART0_GetStr (uint8 *s, uint32 n)
{
for ( ; n>0; n--)
{
*s++ = UART0_GetByte();
}
}
/*
*********************************************************************************************************
** 函数名称 :UART0_SendByte()
** 函数功能 :向串口发送字节数据,并等待发送完毕,查询方式。
** 入口参数 :dat 要发送的数据
** 出口参数 :无
*********************************************************************************************************
*/
void UART0_SendByte (uint8 dat)
{
IO0SET |=1<<31;
U0THR = dat;
while ((U0LSR & 0x40) == 0); // 等待数据发送完毕
}
/*
*********************************************************************************************************
** 函数名称 :UART0_SendStr()
** 函数功能 :向串口发送一字符串
** 入口参数 :str 要发送的字符串的指针
** 出口参数 :无
*********************************************************************************************************
*/
void UART0_SendStr (uint8 const *str)
{
while (1)
{
if (*str == '\0') break; // 遇到结束符,退出
UART0_SendByte(*str++); // 发送数据
}
}
/*
*********************************************************************************************************
** 函数名称 :UART0_GetByte()
** 函数功能 :从串口接收1字节数据,使用查询方式接收。
** 入口参数 :无
** 出口参数 :接收到的数据
*********************************************************************************************************
*/
uint8 UART1_GetByte (void)
{
uint8 rcv_dat;
IO0CLR |=1<<10;
while ((U1LSR & 0x01) == 0);
rcv_dat = U1RBR;
return (rcv_dat);
}
/*
*********************************************************************************************************
** 函数名称 :UART0_GetStr()
** 函数功能 :从串口接收
** 入口参数 : s 指向接收数据数组的指针
** n 接收的个数
** 出口参数 : 无
*********************************************************************************************************
*/
void UART1_GetStr (uint8 *s, uint32 n)
{
for ( ; n>0; n--)
{
*s++ = UART1_GetByte();
}
}
/*
*********************************************************************************************************
** 函数名称 :UART0_SendByte()
** 函数功能 :向串口发送字节数据,并等待发送完毕,查询方式。
** 入口参数 :dat 要发送的数据
** 出口参数 :无
*********************************************************************************************************
*/
void UART1_SendByte (uint8 dat)
{
IO0SET |=1<<10;
U1THR = dat;
while ((U1LSR & 0x40) == 0); // 等待数据发送完毕
}
/*
*********************************************************************************************************
** 函数名称 :UART0_SendStr()
** 函数功能 :向串口发送一字符串
** 入口参数 :str 要发送的字符串的指针
** 出口参数 :无
*********************************************************************************************************
*/
void UART1_SendStr (uint8 const *str)
{
while (1)
{
if (*str == '\0') break; // 遇到结束符,退出
UART1_SendByte(*str++); // 发送数据
}
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -