??? 11/15/06 15:00 Read: times |
#128022 - More hints Responding to: ???'s previous message |
Dan said:
Thats much better! Do you have any other optimization suggestions for an 8051 newbie? A couple. For starters, take a look at your delay routine: delay_ms: mov r7, #00h loop_1: inc r7 mov a, r7 cjne a, #0ffh, loop_1 retIf you can arrange it so you count down instead of up in your loops, the DJNZ instruction can make them somewhat less clumsy, like this: delay_X: ; Delay for unknown time mov r7,#00h ; Initialize counter djnz r7,$ ; Decrement counter to zero ret ; DoneOf course this will give a shorter delay than the original. Hence the new name. The other problem with both of these delay loops is that the delay time will vary depending on the speed of the processor. So if you move your code to a different 8051 variant or even just change the clock speed, your program may no longer work because the delays will all be wrong. The solution is to use timer interrupts to establish your delay times. Your programs will be a little bit more complicated, but it will be much easier to reuse your code on different processors if you avoid delay loops like the ones above. -- Russ |