Transmitting

Basic transmission is very simple, the byte to be transmit is placed in the Transmit Register (TXREG).  This will cause the peripheral to transmit the byte.  The TXREG register data is moved in to the shift register as soon as the shift register is empty, therefore it is possible to put another data byte into the TXREG before the previous one has completely been transmit.  The TXIF flag that is low whilst data is in the TXREG and high when the TXREG is empty, therefore this flag can be monitored [or used to trigger an interrupt] to determine when a new byte can be placed in the TXREG. 

To ensure that the TXREG is always empty before we put a byte into it, the TXIF status can be checked before placing data into the TXREG e.g.

  1. Read TXIF
  2. If TXIF is low (TSR full) goto 1.
  3. TXREG = data
  4. END

Code

The following code extract can be used to transmit a byte to to the PC
 
void transmit(unsigned char byte)
{
    while(!TXIF)     //wait until TXIF is high
        continue;  
    TXREG = byte;    //put byte into Transmit Register             
}

See using interrupts in Advanced Tutorial

 

Copyright © 2010 AVIT Research ltd. Last modified: 22/02/10