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 Port Routine

To avoid the overhead of printf() I have created the following routine:

void write_0(unsigned char* c)
{


     int cnt = 0;
     int len = strlen( c );

//   Disable interrupts
     EA = 0 ;

     for ( cnt = 0; cnt < len; cnt++ )
     {

          tx_buffer_0[ tx_write_0++ ] = c[ cnt ];


      } //__for ( i = 0; i < len; i++ )__

      EA = 1;

//    Prime buffer
      if ( sys_tx_0_ready )
      {

          sys_tx_0_ready = 0;
          TI_0 = 1;

      } //__if ( sys_tx_0_ready )__

}

In my serial ISR I have the following:


void Serial_isr(void) interrupt 4
{

//   Handle port 0 tx
     if ( TI_0 )
     {
         TI_0 = 0;

         if ( sys_tx_0_ready == 0 )
         {

             SBUF0 = tx_buffer_0[ tx_read_0++ ];

             if ( tx_write_0 == tx_read_0 )
                 sys_tx_0_ready = 1;

         }//__if ( sys_tx_0_ready == 0 )__

     } //__if ( TI_0 )__

}

The code works, I was just wondering if anyone could suggest a better way of doing this.

Thanks.