Discussion in "8051 Discussion Forum" started by    Dan51    Oct 25, 2007.
Thu Oct 25 2007, 11:49 AM
#1
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
Thu Oct 25 2007, 12:30 PM
#2
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
Thu Oct 25 2007, 02:35 PM
#3
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, 03:11 PM
#4
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..
 Dan51 like this.
Thu Oct 25 2007, 04:51 PM
#5
OK, thanks a lot!

Get Social

Information

Powered by e107 Forum System

Conversation

Fri Apr 16 2021, 08:49 AM
Maria Campbell
It looks like you've misspelled the word "temprature" on your website. I thought you would like to know . Silly mistakes can ruin your site's credibility. I've used a tool called SpellScan.com in the past to keep mistakes off of my website.-Maria
Thu Apr 15 2021, 11:47 PM
Rachel Cohen
{
Wed Apr 14 2021, 07:42 PM
Harmanjsj
only
Wed Apr 14 2021, 05:05 PM
Valencia
Thank you for some other excellent article. Where else may anyone get that type of info in such a perfect manner of writing? I have a presentation subsequent week, and I'm on the search for such info. viagra otc https://viagrasildenafilok.com/
Wed Apr 14 2021, 03:56 PM
Maritza
Hello, i think that i noticed you visited my web site thus i came to return the prefer?.I am attempting to in finding issues to improve my website!I assume its good enough to make use of a few of your ideas!! https://auto.rifugiofiori.it/docbook-sample.pdf Katja

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 92, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123