How to make a delay in assembly for 8051 microcontrollers? -
i having problem in calculating delays. want make delay 0.5 sec when using 1mhz clock speed 8051 microcontroller.
i use proteus simulation , avr studio coding in assembly atmel microcontroller.
for example code 8mhz clock microcontroller
delay_15ms: ldi dly1, 120 ; delay1: ldi dly2, 250 ; delay2: dec dly2 ; nop ; brne delay2 ; dec dly1 ; brne delay1 ; ret
can teach me how calculate time delay take? make 1 0.5 sec delay @ 1 mhz
thank you
0,5 s eternity in life of (even slow) microcontroller.
do realize not able while waiting ? ( called passive wait )
phil wetzel gave in comment link post describing interrupts. that's need.
it require read datasheet know how configure clocking system, how configure timer, how set , write interrupt timer...
however answer question ( if code snippet correct (?) ): 15 ms timeout on 8 mhz system realize 120 times second loop (delay2).
so have 8 times slower system want wait 0.5/0.015 = 33.33... times more.
so wait 120 / 8 * 0.5 / 0.015 = 500 delay1 loops
but µc 8 bit one, can not store such value in 8 bits register.
so fear asking impossible ( unless write code handle 16 bits variable ). may create delay0 loop , wait 2 times 250 delay1 loops.
not sure accuracy !!
Comments
Post a Comment