Hello Every : I use AT89C52 and 11.059MHz oscillator. 1 instuction takes about 1 micro-second.(10^-6 sec.) I write a delay function in *.asm. It works well , but I want it adjustable. I want to delay according to the parameter I pass.My goal is to modify delay time for some protocol time slot testing. I found it some how difficult to achieve. Because the basic instruction , for example : _nop_ , take 1 micro-second. I can't add more decision. It will takes more time. How could I implement such kind of delay? Please give me a hand , thanks a lot~~
sample: void delay_us(unsigned char counter) { ACC = 255 - counter; #pragma asm mov dptr,#DELAYBEGIN; jmp @a+dptr DELAYBEGIN: REPT (255 - 9) nop; ENDM #pragma endasm } note: counter must be from 9 to 255.
#pragma asm Why on earth would you do that. Purt the subroutine in a .a51 module. also, the routine described is wrong ACC = 255 - counter; it should be ACC = 255 - counter - overhead jb acc.7,crash ; routine used for too short a delay Erik