SDCC compiler & accurate delay function
Discussion in "8051 Discussion Forum" started by Dan51 Oct 25, 2007.
Thu Oct 25 2007, 05:19 pm
Hello all
I have just started using the SDCC compiler for 8051.
I am trying to write an assembler function (Delay) inside a C file. It has to be written in assembler because the delay has to be accurate. I then want to call this function from a C function:
_asm
Delay:
mov r0, #FF
d100: djnz r0, d100
ret
_endasm
main()
{
_asm
call Delay
-endasm
}
The above code does not compile.
Is this possible to do some how?
Is there a better way to create an accurate delay function?
Thanks
I have just started using the SDCC compiler for 8051.
I am trying to write an assembler function (Delay) inside a C file. It has to be written in assembler because the delay has to be accurate. I then want to call this function from a C function:
_asm
Delay:
mov r0, #FF
d100: djnz r0, d100
ret
_endasm
main()
{
_asm
call Delay
-endasm
}
The above code does not compile.
Is this possible to do some how?
Is there a better way to create an accurate delay function?
Thanks
Thu Oct 25 2007, 06:00 pm
i guess it should be the other way
delay(){
_asm
mov r0, #FF
d100: djnz r0, d100
_endasm
}
and in main.. call delay as a function
delay(){
_asm
mov r0, #FF
d100: djnz r0, d100
_endasm
}
and in main.. call delay as a function
Thu Oct 25 2007, 08:05 pm
Thanks, this is correct, but then I am not sure I know how to calcuate the time (clocks) required for calling the delay function in C. This may cause a samll error in the delay time. Am I correct?
Thu Oct 25 2007, 08:41 pm
not much.. after compiling its just a call to the function nothing much.
calling a function takes about 3 machine cycles, ret need 2 and rest is whats inside your loop
i have explained someone regarding how to calculate delay.. you can check that thread..
calling a function takes about 3 machine cycles, ret need 2 and rest is whats inside your loop
i have explained someone regarding how to calculate delay.. you can check that thread..
Dan51 like this.
Powered by e107 Forum System