This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Serial Full Duplex

Hi Community,
i have a big problem. I want to write something like a ECHO - Funktion. That means i recive a char an send it back like in this source ...

void serial_int (void) interrupt 4 using 3
{
    static char chr = '\0';

    if (RI == 1)
    {
        chr = SBUF;
        RI = 0;
        TI = 1;
            TL0 = 0xFF;
    }
    else if (TI == 1)
    {
        TI = 0;
        if (chr != '\0')
        {
            if (chr == '\r') chr = '\n';
            SBUF = chr;
            while(TI == 0);
            TL0 = 0xFF;
            chr = '\0';

        }

    }
}

The Problem is... i am using a Timer for multiplexing my LED-Digits.
Is there a faster methode for this application ?
(SRY FOR MY ENGLISH)

Parents
  • Hi Community, i am back with a new problem.
    The funktion is to slow, is there a better way for this source :

    static void com_isr (void) interrupt 4 using 1
    {
    unsigned char c;
        if (TI != 0)
            {
            TI = 0;                                 // clear interrupt request flag
            if (ostart != oend)
                {                                   // if characters in buffer and
                    SBUF = outbuf[ostart++ & (OLEN-1)]; // transmit character
                    sendfull = 0;                   // clear 'sendfull' flag
                }
                     else
                {                                   // if all characters transmitted
                sendactive = 0;                     // clear 'sendactive'
                }
        }
         if (RI)
           {
                if(echo=='1')
                {
                 putbuf(c);
    }
            RI = 0;
           if (istart + ILEN != iend)
                {
                    inbuf[iend++ & (ILEN-1)] = c;
    }
            }
    
    }
    



    void putbuf (char c)
    {
        if (!sendfull)
            {                       // transmit only if buffer not full
                if (!sendactive)
                        {           // if transmitter not active:
                            sendactive = 1; // transfer first character direct
                            SBUF = c; // to SBUF to start transmission
                        }
                else
                        {
                            ES = 0; // disable serial interrupts during buffer update
                            outbuf[oend++ & (OLEN-1)] = c; // put char to transmission buffer
                            if (((oend ^ ostart) & (OLEN-1)) == 0)
                                {
                                    sendfull = 1;
                                } // set flag if buffer is full
                            ES = 1; // enable serial interrupts again
                        }
                }
    }
    

Reply
  • Hi Community, i am back with a new problem.
    The funktion is to slow, is there a better way for this source :

    static void com_isr (void) interrupt 4 using 1
    {
    unsigned char c;
        if (TI != 0)
            {
            TI = 0;                                 // clear interrupt request flag
            if (ostart != oend)
                {                                   // if characters in buffer and
                    SBUF = outbuf[ostart++ & (OLEN-1)]; // transmit character
                    sendfull = 0;                   // clear 'sendfull' flag
                }
                     else
                {                                   // if all characters transmitted
                sendactive = 0;                     // clear 'sendactive'
                }
        }
         if (RI)
           {
                if(echo=='1')
                {
                 putbuf(c);
    }
            RI = 0;
           if (istart + ILEN != iend)
                {
                    inbuf[iend++ & (ILEN-1)] = c;
    }
            }
    
    }
    



    void putbuf (char c)
    {
        if (!sendfull)
            {                       // transmit only if buffer not full
                if (!sendactive)
                        {           // if transmitter not active:
                            sendactive = 1; // transfer first character direct
                            SBUF = c; // to SBUF to start transmission
                        }
                else
                        {
                            ES = 0; // disable serial interrupts during buffer update
                            outbuf[oend++ & (OLEN-1)] = c; // put char to transmission buffer
                            if (((oend ^ ostart) & (OLEN-1)) == 0)
                                {
                                    sendfull = 1;
                                } // set flag if buffer is full
                            ES = 1; // enable serial interrupts again
                        }
                }
    }
    

Children