|
Infinite LoopNext Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author Aquib Fateh Posted 22-Jan-2005 23:26 GMT Toolset C51 |  Infinite Loop Aquib Fateh I am using the following code to blink a LED 10 times and then stop. But it goes on blinking even after 10 counts. please let me know where i have gone wrong in the code
#include <stdio.h>
#include <chipcon/hal.h>
#include <chipcon/cc1010eb.h>
#define Wait_Time 200
void main()
{
int a=0;
// Set Port 1 Bit 2 as O/P
halSetPortBitDir(1, 2, POUT);
// Initialise Counter
while(a!=10) {
// Wait period between blinks
halWait(Wait_Time, CC1010EB_CLKFREQ);
//Toggle LED
halSetPortBit(1, 2, FALSE);
a++;
}
} //main
| | Read-Only Author Dan Henry Posted 23-Jan-2005 00:19 GMT Toolset C51 |  RE: Infinite Loop Dan Henry Most embedded environments are not like a PC where a program that exits main() implicitly or explicitly via a return statement or call to exit(), exits back to an operating system. You have to prevent main() from terminating by adding some kind of forever loop before main()'s closing brace. For example:
for (;;);
| | Read-Only Author Aquib Fateh Posted 23-Jan-2005 22:37 GMT Toolset C51 |  RE: Infinite Loop Aquib Fateh Hi Dan thanks for helping again. I tried putting a infinite loop just before the closing braces of main(), but the LED still blinks infdefinitely. I still cant figure out how to get this code fixed. please help
#include <stdio.h>
#include <chipcon/hal.h>
#include <chipcon/cc1010eb.h>
#define Wait_Time 200
void main()
{
int a=0;
// Set Port 1 Bit 2 as O/P
halSetPortBitDir(1, 2, POUT);
// Initialise Counter
while(a!=10) {
// Wait period between blinks
halWait(Wait_Time, CC1010EB_CLKFREQ);
//Toggle LED
halSetPortBit(1, 2, FALSE);
a++;
}
//A forever loop
for (;;);
} //main
| | Read-Only Author Dan Henry Posted 23-Jan-2005 23:11 GMT Toolset C51 |  RE: Infinite Loop Dan Henry "... the LED still blinks infdefinitely."
Perhaps the watchdog is periodically resetting the MCU, causing your program to start over again. The watchdog timer is enabled by default. You need to either keep the watchdog happy or disable it. | | Read-Only Author al bradford Posted 23-Jan-2005 01:50 GMT Toolset C51 |  RE: Infinite Loop al bradford As Dan pointed out, you must have some type of forever loop in some task. By default, Keil adds a jump to main for all of us that might forget the forever loop. This keeps our program from running wild through bad code. For the task that must run one time only such as initialization, place the forever loop with careful thought. Bradford | | Read-Only Author Andrew Neil Posted 24-Jan-2005 01:51 GMT Toolset C51 |  RE: Infinite Loop Andrew Neil "By default, Keil adds a jump to main for all of us that might forget the forever loop."
Eh??
Where??? | | Read-Only Author Al Bradford Posted 24-Jan-2005 15:23 GMT Toolset C51 |  RE: Infinite Loop Al Bradford Andrew; Look at the Hello World example code. Remove the while(1) and look at the disassembly. At the bottom of the code you will see a LJMP to Main put there by the closing brace. | |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|