We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want a fast and simple delay routine:
#pragma OT(8,SPEED) // Switch to speed optimization for this routine void my_delay(BYTE count) { register BYTE i; for (i=count; i; i--); }
Is the best so far and becomes:
B02:0xB1F1 EF MOV A,R7 B02:0xB1F2 6003 JZ B02:B1F7 B02:0xB1F4 1F DEC R7 B02:0xB1F5 80FA SJMP I2C_delay(B02:B1F1) B02:0xB1F7 22 RET
but I was hoping there was a way to get C51 to do just a DJNZ instead of 4 instructions for each loop.
Is there a magic coding style or optimization level that will generate the DJNZ?
This is not a religious war.
Actually, in the usual figurative meaning of that phrase, it is.
Your side lost it decades ago, but every new generation of programmers refuses to admit it.
PLEASE STOP the discussion of the reasons not to use instruction delay loops! Please just answer the question!
You either ask questions, or you get to choose answers all to your liking. You won't have it both ways.
But in this case, I don't care about accuracy of the timing!
I just want the top end to be a little faster by using a DJNZ instead of 4 instructions.
You're contradicting yourself. If you really didn't care about the accuracy, it would make no difference whatsoever whether the granularity is one instruction or four.
That is very disturbing.
That is even more disturbing.
Eric,
I'd still suggest you consider writing your delay in assembler. Any seasoned low level programmer knows when the use of a software delay is sensible and would code it accordingly, so any statement by a person on whether it is right or wrong of it is just showing their ignorance.
Even if a zealous bigot responder here has a way of causing the compiler to use the DJNZ, it's really not sensible to rely on it. Any number of things could cause the compiler to change it's mind so your code could simply break at a future point in time. Write it in assembler, and you know it is safe from these compiler decisions.