#define MAXLEN 19
unsigned int ReadPtr = 0;//定义读指针
unsigned int WritePtr = 0;//定义写指针
int Arr[MAXLEN] = {0};//读取的数组
1、循环写入缓冲区
unsigned int BufAdd(int data)
{
Arr[*WritePtr] = data;//数据写入缓冲区
*WritePtr = ((*WritePtr) + 1) % MAXLEN;//指针+1
return 1; //Ok
}
2、计算缓冲区空闲可写个数
unsigned int EmptyNum(void)
{
unsigned int Num = 0;
Num = (ReadPtr + MAXLEN - WritePtr)%(Maxlen );
return Num;
}