In SX Microcontrollers, SX/B Compiler and SX-Key Tool, robotworkshop wrote: Here is an extra function to go along with the ISR based serial code. There are times when I want to take a peek in the serial input buffer to see what the next character is but I don't want to pull it out just yet. To do so I just made a copy of RX_BYTE and called it RX_CHKBYTE to check the next character in the buffer. Before calling the RX_CHKBYTE function I usually just check rxBufCnt to see if it is greater than 0. If not I don't bother calling it as I have other processing to do. Adding the extra function was pretty simple as is just doesn't update the pointer and leaves the count alone. Hopefully others will find this extra function useful. ' Use: aByte = RX_BYTE ' -- returns "aByte" from 8-byte circular buffer ' -- will wait if buffer is presently empty ' -- rxBufCnt holds byte count of receive buffer (0 to 7) FUNC RX_BYTE ASM BANK rxSerial TEST rxBufCnt ' check buffer count JZ @RX_BYTE ' wait if empty MOV W, #rxBuf ' point to tail ADD W, rxTail MOV FSR, W MOV __PARAM1, IND ' get byte at tail INC rxTail ' update tail AND rxTail, #%00000111 ' keep 0 to 7 DEC rxBufCnt ' update buffer count BANK 0 ENDASM ENDFUNC ' Use: aByte = RX_CHKBYTE ' -- returns the tail value from 8-byte circular buffer but leaves ' -- it alone. Will wait if buffer is presently empty ' -- rxBufCnt holds byte count of receive buffer (0 to 7) ' -- 2/21/2008 RLD FUNC RX_CHKBYTE ASM BANK rxSerial TEST rxBufCnt ' check buffer count JZ @RX_CHKBYTE ' wait if empty MOV W, #rxBuf ' point to tail ADD W, rxTail MOV FSR, W MOV __PARAM1, IND ' get byte at tail BANK 0 ENDASM ENDFUNC Best Regards, Robert ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=251974 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)