Author Topic: question for c  (Read 1551 times)

0 Members and 1 Guest are viewing this topic.

Offline minmxTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
question for c
« on: May 08, 2010, 11:33:00 AM »
hi, i have a question: how can i put the pause inb c code?

Offline amando96

  • Robot Overlord
  • ****
  • Posts: 187
  • Helpful? 1
Re: question for c
« Reply #1 on: May 08, 2010, 01:04:10 PM »
in milliseconds: delay();
in microseconds: delaymicroseconds();
Rorcle, 60% complete
AATV, 5% complete

Offline Benn

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: question for c
« Reply #2 on: May 08, 2010, 02:05:47 PM »
hmmm...depends...
There are some IDE that give you function like those amando96 said...but there are others that don't.
The most simple solution is something like this:

void delay(int a)
{
    int i;
    for (i = 0; i < a; i++)
    {
        _nop();
    }
}

main(void)
{
    ....
    delay(100000);
    ....
}

Also depends on what uC you use. The one i worh with has the _nop() function that does NOTHING, but wait for a tick. Here comes the frequency setup. But in my example, the function will delay around 1.25ms , with 80MHz frequency.
I say around, because there are others ticks lost when the compiler transforms the C code into ASM.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: question for c
« Reply #3 on: May 11, 2010, 05:15:42 AM »
Going from what Benn said . . . what microcontroller are you using?

 


Get Your Ad Here

data_list