??? 08/06/06 13:32 Read: times |
#121731 - killing bad habits from the onset Responding to: ???'s previous message |
This is the first time I'm writing a c code for the keil c51 void delay(void) { int i,j; for(j=0;j<10;j++) for(i=0;i<32767;i++) i=i; } void main(void) {while(1) { P1=0x00; delay(); P1=0x0ff; delay(); } }let us try to kill some bad habits from the onset. 1) 'i' and 'j' are 'educational' names for vatiables, use descriptive names. 2) C is NOT 'self documenting' where are the comments? 3) the time it takes to execute a c operation may vary based on ANYTHING when you use C. As an example, once someone go flabbergasted that his 'delay' which he did not change changes because he cahnged something totally unrelated somewhere else. NEVER rely on C for timing. Now, as to your question Also please tell me who to calculate exact delay for c code NOBODY can answer that. Yes, somebody may be able to answer what it for this compile, but NOBODY can answer what it will be after next compile. In addition, how do you expect anybody to answer when you do not state derivative and clock, if you change from a 12 clocker to a 6 clocker, your delay will be half, id you cange from 12MHz to ..., if you ... do you believe that C is friggin macic?. Erik |