环形队列中断方式 -- 不耗时,支持缓冲区
unsigned char SendItComm=1;
void SendCommBuffer(unsigned char *base, unsigned short size)
{
unsigned short i=0;
if (!size)
{
return;
}
while(i<size)
{
CommSendBuffer[CommSendBufferTail]=base[i];
i++;
CommSendBufferTail++;
if (CommSendBufferTail==DB_SENDMAXSIZE)
{
CommSendBufferTail=0;
}
}
if(SendItComm) //当SendItComm为零时,表示上一帧数据还未发送完毕
{
SBUF0=CommSendBuffer[CommSendBufferHead];
}
}
void CommISR(void) interrupt 4
{
if (TI0)
{
TI0=0;
CommSendBufferHead++;
if (CommSendBufferHead==DB_SENDMAXSIZE)
{
CommSendBufferHead=0;
}
if (CommSendBufferHead!=CommSendBufferTail)
{
SBUF0=CommSendBuffer[CommSendBufferHead]; // send the next byte
SendItComm=0;
}
else
{
SendItComm=1;
}
}
}