??? 02/11/05 01:32 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#87115 - tracing your code manually.... Responding to: ???'s previous message |
is a useful exercise for short programs in assembly. Take a piece of paper and write a column heading for each of the registers that you use, in your case R0, R1, R2, R3, R4, P1, P2, TL0, Th0, DPTR, and ACC. Then mentally step through your code one instruction at a time and write down the contents of that register as a result of the execution of the instruction.
In the case of your code, the first time it goes through the loop P1= <4400h> ( the "<4400h>" means "contents of location 4400h") P2 = <4401h> TL0 = <4200h> TH0 = <4201h> the next pass through the "again" loop results in: P1= <4402h> P2= <4403h> TL0 = <4202h> TH0 = <4203h> Is this what you want? In order for you to have this work correctly for you, you would have had to have filled 322 bytes (161 x 2) with the timer counts starting at address 4400h and going up. If you only intended the low and high bytes of the timer to be stored at 4200h and 4201h, respectively, and only reload the timer from these two locations, the problem is that the pointer for the high and low bytes are incremented by two on every pass through "again". There are a few ways you can fix this. In the "again" routines, three instructions before the MOVC for that you use to look up the value for TL0, change the MOV DPH,R2 to MOV DPH,#0x42 and change the MOV DPL,R3 to MOV DPL,#0. An alternative is to remove the "MOV R2,DPH" and "MOV R3,DPL" instructions that follow the JNB, CLR TR0, CLR TF0 instructions after the label "here:". I hope this helps - Bill |