noblockUartSend.c
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
#define _TX //发送寄存器
#define UART_SEND_LENGTH 200
typedef struct {
uint8_t Arr[UART_SEND_LENGTH];
uint16_t LowIndex;
uint16_t HighIndex;
uint8_t IsSendingFlag;//现在正常发送
}UartSendStruct;
UartSendStruct TxSend;
void SendString(uint8_t *p,uint16_t length)
{
int i;
for(i=0;i<length;i++)
{
SendOneDataToBuf(p[i]);
}
if(TxSend.IsSendingFlag == 0)
{
TxSend.IsSendingFlag = 1;
_TX = TxSend.Arr[TxSend.LowIndex];
TxSend.LowIndex++;
if(TxSend.LowIndex >= UART_SEND_LENGTH)TxSend.LowIndex = 0;
}
}
static SendOneDataToBuf(uint8_t dat)//不对外开发
{
TxSend.Arr[TxSend.HighIndex] = dat;
TxSend.HighIndex++;
if(TxSend.HighIndex >= UART_SEND_LENGTH)TxSend.HighIndex = 0;
}
void UartTxInterrupt(void)//发送中断
{
if(TxSend.LowIndex != TxSend.HighIndex)
{
_TX = TxSend.Arr[TxSend.LowIndex];
TxSend.LowIndex++;
if(TxSend.LowIndex >= UART_SEND_LENGTH)TxSend.LowIndex = 0;
}
else
{
TxSend.IsSendingFlag = 0;
}
}