* so it can run on devices with _little_ memory like at89cx051.
* - It won't overwrite characters which already are stored in the
* receive-/transmit-buffer.
-* - It checks receiver first to minimize probability for overruns
-* in the serial receiver.
*/
/* BUG: those definitions (and the #include) should be set dynamically
* (while linking or at runtime) to make this file a _real_ library.
*/
#include <8051.h>
-#define XBUFLEN 10
-#define RBUFLEN 10
+#define XBUFLEN 4
+#define RBUFLEN 8
-static unsigned char rbuf[RBUFLEN], xbuf[XBUFLEN];
+/* You might want to specify idata, pdata or xdata for the buffers */
+static unsigned char pdata rbuf[RBUFLEN], xbuf[XBUFLEN];
static unsigned char rcnt, xcnt, rpos, xpos;
-static unsigned char busy;
+static bit busy;
void ser_init (void)
{
RI = 0;
/* don't overwrite chars already in buffer */
if (rcnt < RBUFLEN)
- rbuf [(rpos+rcnt++) % RBUFLEN] = SBUF;
+ rbuf [(unsigned char)(rpos+rcnt++) % RBUFLEN] = SBUF;
}
if (TI) {
TI = 0;
;
ES = 0;
if (busy) {
- xbuf[(xpos+xcnt++) % XBUFLEN] = c;
+ xbuf[(unsigned char)(xpos+xcnt++) % XBUFLEN] = c;
} else {
SBUF = c;
busy = 1;
* so it can run on devices with _little_ memory like at89cx051.
* - It won't overwrite characters which already are stored in the
* receive-/transmit-buffer.
-* - It checks receiver first to minimize probability for overruns
-* in the serial receiver.
*/
/* BUG: those definitions (and the #include) should be set dynamically
#define CTS P3_6 // CTS & RTS can be assigned to any free pins
#define RTS P3_7
+// You might want to specify idata, pdata or xdata for the buffers
static unsigned char rxbuf[RXBUFLEN], txbuf[TXBUFLEN];
static unsigned char rxcnt, txcnt, rxpos, txpos;
-static unsigned char busy;
+static bit busy;
void ser_init()
{
if (RI) {
RI = 0;
/* don't overwrite chars already in buffer */
- if(rxcnt < RXBUFLEN) rxbuf [(rxpos + rxcnt++) % RXBUFLEN] = SBUF;
+ if(rxcnt < RXBUFLEN) rxbuf [(unsigned char)(rxpos + rxcnt++) % RXBUFLEN] = SBUF;
if(rxcnt >= (RXBUFLEN - THRESHOLD)) CTS = DISABLE;
}
ES = 0;
if (busy) {
- txbuf[(txpos + txcnt++) % TXBUFLEN] = c;
+ txbuf[(unsigned char)(txpos + txcnt++) % TXBUFLEN] = c;
} else {
SBUF = c;
busy = 1;