I have successfully figured out how to keep an LED on for around 1 sec (actual circuit, not a simulation) given a crystal of 3.57945 MHz. As you can see in the code snippet below, I have created algorithms for a 1 sec delay, 10 msec delay, 100 usec delay, and 1 usec delay. What I'm having difficulty understanding is exactly how this works. 1 cycle is around 279 nsec. But the code it took to create the 1 sec delay makes it appear that it only takes .25 psec to increment the value of a variable. That implies a speed of 4 THz, and I know that can't be possible for a through-hole microcontroller. What's going on? Does the microcontroller have a mechanism for streamlining the process? In applications for which timing is critical, how do you make sure the timing is correct? THE CODE SNIPPET: #define __16F872 #include #include __CONFIG (XT&WDTDIS&PWRTDIS&BORDIS&UNPROTECT & LVPDIS); // Set the configuration bits: // LVP must be disabled for LED8 to work. unsigned char count, count1; void delay_10_nsec (void) { count = 0; while (count < 200) { count1=0; while (count1 <200) {count1++;} count++; } } void delay_1_usec (void) { count=0; while (count<100) { delay_10_nsec(); count++; } } void delay_100_usec (void) { count = 0; while (count<100) { delay_1_usec(); // 100 delays of 1 usec each. count++; } } void delay_10_msec (void) { count = 0; while (count<100) { delay_100_usec(); // 100 delays of 100 usec each. count++; } } void delay_1_sec (void) { count = 0; while (count<100) { delay_10_msec(); // 100 delays of 10 msec each. count++; } } -- Jason Hsu http://www.jasonhsu.com/swrwatt.html http://www.jasonhsu.com/swrwatt-c.txt http://www.jasonhsu.com/swrwatt-asm.txt -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist