??? 03/07/04 14:10 Read: times |
#66182 - RE: What I have understood till now Responding to: ???'s previous message |
I prepared this, but Patrick beat me to it. Nevertheless, it's interesting that we both hint at using a fifo. There must be some truth to it...
You are beginning to understand. What you say is basically correct, but... You are confused between polling and interrupts. If you wait for the TI flag with jnb ti,$, there is no need to enable any interrupts, and so no need for an isr. If you are using interrupts, the whole point of the isr is to eliminate the need to do the stupid jnb ti,$! But in no case should there be any need for having these two methods together. the whole point of using interrupts is this: Set and forget. So you set up your serial communications, and go do other things. The TI and RI interrupts (to 0023h) will enable you to build a piece of software which will handle the communications automatically. What you want to do is: Send 3 bytes without having to waste time polling some stupid flag. This is a very good thought, especially for a beginner. I think you must have some talent! You should see what some people come up with on this site in terms of jnb flag,$! So how should you go about it? Do it exactly this way: The answer is, if you want to do it exactly this way, you are going to need a "transmit buffer" capable of holding at least three charaters which you can fill in one go, and the sending of the characters in the buffer will then be handled automatically by the serial interrupt service routine. Such a buffer is also known as a 'fifo' and is often constructed as a 'circular buffer' (search this site for these terms!) Your will use it like this: Put the three characters in the fifo. Then ((Call a routine which will)) take the first character out of the fifo and into sbuf. That's it. The rest will be done by your serial interrupt service routine, which will do the following: If there is a transmitter interrupt, that means that the transmitter is ready to send another character. See if the fifo is empty. If it is, set a flag that the fifo is empty and reti. The buffer has been completely sent. We're ready. But if there are still characters waiting in the fifo, take the next one out, put it in sbuf and reti. As you can see, there is no stupid waiting here. So your thought that jnb ti,$ is a waste of time is absolutely correct. But to make it work, you will actually need quite a bit of software. Anyway, this is the general idea behind any ISR, that it will work pretty much autonomous, so you can go about your other business in the main loop without ever having to waste time waiting for anything. The alternative: simplify it. You can always choose NOT to send three bytes, but only one. This will make it easier, and there will not be any need for a fifo. |