Hello, I'm rather new to Keil C and just getting geared up to use it on my next project. ATM, I'm overwhelmed with the number of options and extensions that are available. I intend to write a C "library" that consists of 3 functions:
Delay() DelayMS() DelayUS()
Delay(2); // creates a 2 second delay DelayMS(500); // creates 500ms delay DelayUS(10); // creates a 10us delay
Is this even possible? Yep. I do this kind of thing all the time. I'd guess I will need to write a delay loop in assembly and call it from C correct? Why? There's no need to do that. You can do everything in C. You should create a separate C file for each function. For example: DELAY.C
void Delay(void) { /* insert code here */ }
#include <intrins.h> void DelayMS(unsigned char ms) { unsigned long us = 1000*ms; while (us--) { _nop_(); } }
#include <intrins.h> void DelayUS(unsigned char us) { while (us--) { _nop_(); } }
Yeah, I guess that would work just as well since no matter what you would need to "hand tweak" it anyway. Thanks for the tip! John
Why? There's no need to do that. You can do everything in C. That would make the delay dependent on: 1) optimiser settings 2) compiler version 3) memory model so, to make it 'future safe' you must do it in assembler. Erik PS It's dead easy
I am a newbie to Keil and I am using 8051 based USB 2.0 device. Both IFCLK and CLKOUT are at 48Mhz. I want to implement a function that would introduce 1 microsecond delay. Can you please help?
View all questions in Keil forum