| ??? 02/08/02 21:28 Read: times |
#19574 - RE: In summary |
Marco, the original code you posted is indeed missing a CLR TI instruction in the line after the INC A instruction and in the line before the RETI instruction. That's the only difference I see between the code you posted and the code you mention in MacKenzie's book--other than the missing SJMP..
That being said, this program is useful for understanding interrupt-driven serial communication. But be sure to refer to my previous message regarding the CJNE instruction and protecting the PSW/Accumulator/other registers within an interrupt routine. In reviewing MacKenzie's chapter on Interrupts I'm surprised to see he doesn't touch on this--at least I don't see him mentioning it. He says "Some of the most difficult bugs in system design often involved interrupts" but doesn't go on to explain why that is... It's often because registers aren't properly protected and restored. In this serial ISR example he is actually counting on the accumulator not being restored. Since the program doesn't do anything else that's ok. But if, instead of executing SJMP $, your main loop was doing anything else you'd almost certainly provoke weird stuff by modifying the accumulator and PSW without restoring them when you exit the subroutine. Craig Steiner |



