Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Neil Kurzman
11/04/11 22:03
Read: 658 times
Ny
USA


 
#184553 - The Example is for one UART
Responding to: ???'s previous message
You would need to duplicate it for the second UART.

Example:
static xdata unsigned char tbuf1 [TBUF_SIZE];
static xdata unsigned char rbuf1 [RBUF_SIZE];

static xdata unsigned char t_in1 = 0;
static xdata unsigned char t_out1 = 0;
static xdata unsigned char t_disabled1 = 0;

static xdata unsigned char r_in1 = 0;
static xdata unsigned char r_out1 = 0;

static xdata unsigned char tbuf2 [TBUF_SIZE];
static xdata unsigned char rbuf2 [RBUF_SIZE];

static xdata unsigned char t_in2 = 0;
static xdata unsigned char t_out2 = 0;
static xdata unsigned char t_disabled2 = 0;

static xdata unsigned char r_in2 = 0;
static xdata unsigned char r_out2 = 0;


/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
unsigned char com_rbuflen1 (void)
{
   return (r_in1 - r_out1);
}
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
unsigned char com_rbuflen2 (void)
{
   return (r_in2 - r_out2);
}


or maybe:
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
unsigned char com_rbuflen2 (unsigned char port)
{
    if(port == 0)
    {   
       return (r_in1 - r_out1);
    }
    else
    {
       return (r_in1 - r_out1);
    }
}


 




Note:
#define TBUF_SIZE 256 /* DO NOT CHANGE */
Is Not 100% True. It does to be a power of 2, And you will need to make other changes to make it work.
Same if you want to move it out of XDATA. The optimal values for you, have to be determined by you.

This assumes that you need to send and receive on both UARTs simultaneously with out having the main loop stalling.
It may be overkill for you depending on your needs.

If you are using printf you will need to make a single putch() function.




List of 12 messages in thread
TopicAuthorDate
Both UARTs simultaneous works      Alex Volk      11/04/11 08:16      
   yes      Erik Malund      11/04/11 09:49      
      Both with Queues      Michael Karas      11/04/11 12:50      
         C code      Alex Volk      11/04/11 15:11      
         Or C      Neil Kurzman      11/04/11 16:54      
            No simultaneous work      Alex Volk      11/04/11 21:09      
               The Example is for one UART      Neil Kurzman      11/04/11 22:03      
               Duplicate or Generalise      Andy Neil      11/05/11 04:45      
   at89c51RE2      Alex Volk      11/08/11 23:48      
      Start a new thread      Andy Neil      11/09/11 00:08      
         The same      Alex Volk      11/09/11 05:19      
            but not same problem      Erik Malund      11/09/11 06:30      

Back to Subject List