|
发表于 2014-4-10 09:34:05
|
显示全部楼层
我简单的程序都这么用应该很好理解。有BUG的,我程序简单当然是不会出问题的
typedef struct
{
unsigned char cBuff[MaxSize];
unsigned char in,out,count;
}queue1;
void InitQueue(queue1 *pQ)
{
pQ->in = 0;
pQ->out = 0;
pQ->count = 0;
}
unsigned char InQueue1(queue1 *pQ,unsigned char cInData)
{
GIE = 0;/* disable interrupts */
if (pQ->count == MaxSize)
{
GIE = 1;/* enable interrupts */
return 0;
}
pQ->cBuff[pQ->in++] = cInData;
pQ->in %= MaxSize;
pQ->count++;
GIE = 1;/* enable interrupts */
return 1;
}
unsigned char OutQueue1(queue1 *pQ)
{
unsigned char ret;
GIE = 0;/* disable interrupts */
if (pQ->count==0)
{
GIE = 1;/* enable interrupts */
return(0xff);
}
pQ->count--;
ret = pQ->cBuff[pQ->out];
pQ->out++;
pQ->out %= MaxSize;
GIE = 1;/* enable interrupts */
return(ret);
}
当然我也没有其他的用法,我的都是小项目![](static/image/smiley/default/smile.gif)
|
|