本帖最后由 刘前辈 于 2012-1-14 11:48 编辑
下面摘自KEIL接收程序—中断+队列:
#define ILEN 8 /* size of serial receiving buffer */
unsigned char iend; /* receiving buffer end index */
idata char inbuf[ILEN ];
serial () interrupt 4 using 2 { /* use registerbank 2 for interrupt */
if (RI) { /* if receiver interrupt */
inbuf[iend++ & (ILEN-1)] = SBUF; /* read character */
RI = 0; /* clear interrupt request flag */
}
}
注释: inbuf[iend++ & (ILEN-1)] = SBUF; // 所谓(环形)队列,相当于下面环形缓冲器优化:
inbuf[ iend++ % ILEN ] = SBUF;
// |