.: EMICROS :.  Embedded Micro Software
Home CAN232 CANUSB I2C232 I2CUSB CanWiser Learn C
Add your text here
Contact

Email : info@emicros.com

Ordering Information

.: Ordering using our PayPal powered shopping cart (PayPal account not required).

CAN232 : $79
CANUSB : $89
I2C232 : $79

I2CUSB : $89

Click here to View Cart and check out.

 

 

 

 

The next statement in the main() function is the start of a while loop. A while loop performs a repeated operation while some condition contained within the parenthesizes is TRUE (or not FALSE depending how you look at things). While loops can repeat single statements or multiple statements as shown in the following examples.

Example #1

while( 1 );

This is an infinite loop because the constant 1 as the argument for the while statement evaluates to TRUE and there is no further statements to execute because the statement is terminated with the semicolon (;).

Example #2

while( 1 ) do_function1();

This is another infinite loop but in this case the function do_function1() is continually executed.

Example #3

while( 1 )
{
   do_function1();
   do_function2();
}

This while loop again goes on forever but shows how multiple statements can be executed, in this case 2 functions. The brackets enclose all the statements associated with the while loop.

Note : Try to adopt this general format for while loops because numerous organizations consider this easy to understand.

Example #4

x = 0;
while( x < 10 )
{
  delay_msec( 50 );
  x = x + 1;
}
do_more_function();

Now we have a while loop with a condition associated with it. Notice that the while is executed while the variable x is less than 10. When the variable x equals or exceeds 10 then the while loop is terminated and the program continues. More on variables later in the projects.

Now that a basic while loop is understood, the 4 statements that are executed continuously do the following;

  1. Set the output port pin C2 high which turns on the LED
  2. Delay
  3. Set the output port pin C2 low which turns off the LED
  4. Delay
  5. go back to #1

The _delay() function provides a delay of instruction cycles and is rather crude for now. A better delay function will be developed in a following section.

Try this program out.

 

 

 
 
Copyright 2010 Embedded Micro Software. All rights reserved