Buffered TX and RX (SX/B + Assembly)
JonnyMac
Posts: 9,522
My purpose in sharing this is two-fold:
1) I needed it; someone else may as well.
2) To demonstrate that with very little effort we mortals can take code from gurus like Guenter, Peter, etc., and fold it into our SX/B programs. Terry has done a great job constructing SX/B to allow the smooth incorporation of Assembly segments and I think this is a pretty good demonstration of that.
Notes:
-- TX and RX [noparse][[/noparse]circular] buffers are each eight bytes
-- TX and RX vars and code are independent of each other and can be pulled out and used separately
-- code prevents overrun of buffers when full
-- DELAY_MS used to replace PAUSE -- allows RX and TX while performing the delay
I've tested at the limits: 1200 and 38400 baud. Please let me know if you find any issues as this is getting folded into the latter chapters of my book. Thanks.
1) I needed it; someone else may as well.
2) To demonstrate that with very little effort we mortals can take code from gurus like Guenter, Peter, etc., and fold it into our SX/B programs. Terry has done a great job constructing SX/B to allow the smooth incorporation of Assembly segments and I think this is a pretty good demonstration of that.
Notes:
-- TX and RX [noparse][[/noparse]circular] buffers are each eight bytes
-- TX and RX vars and code are independent of each other and can be pulled out and used separately
-- code prevents overrun of buffers when full
-- DELAY_MS used to replace PAUSE -- allows RX and TX while performing the delay
I've tested at the limits: 1200 and 38400 baud. Please let me know if you find any issues as this is getting folded into the latter chapters of my book. Thanks.


Comments
When attempting to compile I got an error. See attached jpg screenshot.
You'll have to add a "RETURN __PARAM1" before the ENDFUNC to satisfy the compiler.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
Is that because the compiler expects the FUNC keyword to have an associated RETURN? I'm using 1.51.03 so I have not see the problem reported by T&E.
' ------------------------------------------------- ' Subroutine / Function Code ' ------------------------------------------------- ' 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 8) 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 CLRB rxTail.3 ' keep 0 to 7 DEC rxBufCnt ' update buffer count BANK 0 ENDASM [b]RETURN __PARAM1[/b] ENDFUNC· Yes, it is expecting to see a RETURN somewhere within FUNC...ENDFUNC (I'll have to change the wording of the error message since it references ENDSUB which CAN be used without a return).
· It probably should be a warning instead of an error, since it doesn't prevent anything from compiling.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·