??? 03/08/04 21:47 Read: times |
#66297 - RE: I will wait for my victory Responding to: ???'s previous message |
I'm afraid that victory is when you are in a fight. You are not in a fight, you are trying to program a computer chip. The computer chip does not know you are fighting it, it merely does what you tell it to. If you tell it wrong, it will do the wrong thing.
You will have to get some fundamentals straight before you go back to rewriting your code again: - Timing. Your average 8051 will execute one instruction after the other without ever stopping (not even because you hope or think it will) at a rate of 1000000 cycles per second. - Timing. At 9600 baud, the UART will transmit data at a maximum of about 1000 bytes per second. - After putting a byte in the UART (move something to sbuf), you will have to leave the UART in peace for the time it takes to transmit the byte, which is at least 1/1000 of a second at 9600 baud, which comes down to 1000 instruction cycles. So that is why you MUST NOT keep loading stuff into sbuf in a tight loop. It simply will not work. - Fortunately, you don't have to use a delay loop to give the UART the time it needs to output the byte. There is a 'lamp' on the uart which goes ON after the UART is finished. This lamp is called TI. By watching TI, you can tell if it is safe to send a new byte. - Even better: the designers of the 8052 have not only put a lamp on the UART, they also gave it the possibility to interrupt the current program so you can write a piece of software called an isr to deal with the condition of the UART becoming empty, without having to watch the lamp all the time. I really can't help you any further than this. You have been given a lot of good suggestions. To summarize them: - Read the 8052 'bible'. It is the 8052 programmer's holy book, and every word in it is true, not once, but twice. - Throw your simulator away. Especially when it comes to timing and interrupts, a simulator is completely worthless. The best tool for understanding what is happening is in the bony protrusion between your sholders :-) - If you really insist on learning the truth from examples on 'the internet', make absolutely sure that they are from a reliable source. That means manufacturer's appnotes or Michael Karas. - Don't despair when you are stuck. It happens to all of us, and there is no magical cure against it. Only trust that, as Erik put it so nicely, one moment the lightbulb suddenly will go on. I wish you success. |