We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Without use the RTOS noticed that the clock processing decreases. Using the RTOS does not work.
Sorry. This is the correct code:
/***************************************************************************** ** Function name: Bibliotecas incluidas ** Descriptions: None ** parameters: None ** Returned value: None *****************************************************************************/ #include <LPC23xx.H> /***************************************************************************** ** Function name: Delay ** Descriptions: None ** parameters: None ** Returned value: None *****************************************************************************/ void delay(unsigned int t){ unsigned int n; unsigned long i; for ( n=0x00;n<t;n++ ) { for ( i=0x00;i<4900;i++ ) { }; } } /***************************************************************************** ** Function name: MAIN ** Descriptions: None ** parameters: None ** Returned value: None *****************************************************************************/ int main (void) { SCS = 0x00000031; FIO1DIR |=1<<28; for(;;){ FIO1SET = 1<<28; delay(1000); FIO1CLR = 1<<28; delay(1000); } }
Now why do you think that it is ok to write a delay loop in C and expect a known delay?
If you want to busy-loop for 1000ms, program a timer to tick at 1kHz, and have the loop wait for 1000 ticks. Either use an interrupt, or constantly poll the timer. But you have to base the delay on a known constant. If you really do want to delay based on instruction cycles, do use assembler so you know exactly how many instruction cycles your loop takes.
With your code, the produced instructions may change between two compiler versions. Having register variables or volatile variables will make a great change. Flash acceleration on or off may make a big difference too. In the end, you may even get a zero-delay loop because the compiler may throw away all code when it notices that your delay function doesn't have any side effects.
And also remember that the instructions produced for the loop will be greatly affected by any optimization switches. And any change of clock speed will require you to spend a lot of time adjusting your loop constants.
Another thing: Why bother with comments that are not comments? Your comments "Bibliotecas incluidas", "Delay" and "MAIN" don't exactly add any extra value to the program. Do write comments about the purpose of the functions. Your delay function most definitely takes a parameter. And you haven't described why you think it will produce a 1ms delay.
And how will you, three monthrs from now know what the following line does?
SCS = 0x00000031;
Especially after changing tool version!!
See: www.8052.com/.../162556
the OP indeed made some mistakes, BUT I do have a problem with 3.70: compiling one of my projects after a total clean works fine (controller starts up - FSFlash 'finit' always succeeds), but compiling once more (optinizations unchanged) causes my 'finit' to ALWAYS fail! I have reported this issue to Keil and still need to run a few tests on samples. This did not happen with 3.50.