| ??? 03/24/00 07:55 Read: times |
#1933 - RE: Figuring out a detail of DJNZ |
Hi,
you are asking more then one question, lets go one by one. 1- Yes the DJNZ instruction decrement the Register in real. 2- Your code has several mistakes. MOV RO, #233 MOV R1, #1 ; DELAY: DJNZ R0, DELAY DJNZ R1, DELAY ********** * WRONG ** ********** With the above code, R0 will be loaded with #233, R1 will be with #1. Then you tried to create a delay loop which appearantely shows that you want to decrement R0 233 times multiply by value of R1, which is 1. So ultimately you will get the same result if you was not using R1. DJNZ instruction will decrement the contents of the target register first than check whether it is zero or not! in this case we should have the R1 value = the actual number of times loop (as we require) + 1. So with the above code if you want to delay = 2(value of R1) x 233(value of R0). In this case your delay loop should loop two times. The second mistake in the above code is once R0 became zero, its value will be zero until you reload it again with the required value. So once R0 became 00 and R1 is not zero, the code will loop back and try to decrement R0, so R0 will become FFh or #255D, this way your delay loop will become unstable. The above code should be written like this: MOV R1,#02 ; load R1 the number of times of loop recall. LOOP: MOV R0,#233 ; load R0 with the delay DELAY: DJNZ R0,DELAY ; decrement R0 until it become zero. DJNZ R1,LOOP ; dec. R1 and jump to reload R0 to prepare again. With the above code, R0 will always be updated with our required delay time constant. Rauf |
| Topic | Author | Date |
| Figuring out a detail of DJNZ | 01/01/70 00:00 | |
| RE: Figuring out a detail of DJNZ | 01/01/70 00:00 | |
| RE: Figuring out a detail of DJNZ | 01/01/70 00:00 | |
| RE: Figuring out a detail of DJNZ | 01/01/70 00:00 | |
| RE: Figuring out a detail of DJNZ | 01/01/70 00:00 | |
RE: Figuring out a detail of DJNZ | 01/01/70 00:00 |



