When should I set and/or clear TI bit of SCON?
Submitted By: Craig Steiner FAQ Last Modified: 07/10/06
- Often, TI is initialized to 1 when the serial port is first configured. Then, the following code is used to send data to the serial port:
JNB TI,$ ;Wait for TI to go high CLR TI ;Clear TI MOV SBUF,A ;Send the accumulator out the serial port
The first line of this code waits until TI goes high. Since you initially set TI to 1, the first time you send a character TI will already be high so the first line won't loop at all. The second line then clears TI prior to sending out a character, and the third line sends it out. If you try to send out the next character before the previous character has been sent out, the first line (JNB) will cycle indefinitely waiting for TI go high (which means the previous character has been sent out). This approach protects you from sending out a character before the previous character has been completely transmitted.
NOTE: When using this approach, you must be sure that you set TI to 1 when you configure the serial port. Otherwise, the program will cycle indefinitely the first time you attempt transmit a character to the serial port.
Add Information to this FAQ: If you have additional information or alternative solutions to this question, you may add to this FAQ by clicking here.