Jump to content

1ms Delay function or Similar help

Recommended Posts


I was wondering if someone could help me create or find a delay function.


I was thinking a 1ms delay function could work.


I would like to have this, so that I can have some timed prompts on an LCD that I have working.


Below is a fraction of my main.c 

I hope you guys can help me.

  LcdDispStrg("It is");
//-->Delay Function Here
  LcdDispStrg("Working :)");
//-->Delay Function Here


Link to post
Share on other sites

I have been using that, but it is not very accurate.


Here is what I was using:

	BCSCTL1 |= DIVA_3;				// ACLK/8

	BCSCTL1 = CAL_BC1_1MHZ;		// Set DCO to 1MHz

Having the external crystal installed, along witht this code would create a 1ms delay when the function is called as 



And assuming this works, would I go the same about creating a 1-second delay? Could I just add "1,000,000" to the function?


Thanks for the help.

I wish I had an oscilloscope or a logic analyzer to look at the signals.

Link to post
Share on other sites

I wouldn't use _delay_cycles do build a clock or implement time sensitive communication protocols.


But with 1MHz clock, _delay_cycles(1000) should be close enough to 1ms (and _delay_cycles(1000000) to 1 second) for basic delays, e.g. when blinking LEDs, waiting for some peripheral to do its thing etc.


Note, that if there are other things going on, e.g. interrupt routines, _delay_cycles() might take longer than expected. If you need more precise timing, you will have to setup a timer interrupt and implement delay() similar to what Energia does.


PS: @1MHz _delay_cycles(1) will wait 1 us (microsecond), not ms (millisecond).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...