hey kerry i used your code and found some weird results here i used both (ur code for delay and delay_ms(10)) n the result was 10ms delay loop gave a delay of approx. 6 seconds while delay_ms gave a delay of 2 seconds and after that i changed the clock freq in code to 20MHz(using same 4MHz crystal) and here both delays gave a delay of 10seconds. i think the crystal oscillator is definitely not giving 4MHz but why delay loop and delay function are not giving same results? code used=20 #include <16F877A.h> #use delay(clock=3D20000000) void main() { int16 i,j; while(1) { output_D(255); for(i=3D0;i<10;i++) //gave a delay 6sec { for(j=3D0;j<100;j++) =20 { #asm nop nop nop nop nop nop nop nop nop nop #endasm } }; output_D(0); delay_ms(10); // gave a delay of 2sec. } } Kerry Wentworth wrote: >=20 > My somewhat outdated CCS compiler does delays using NOPs in a loop, not=20 > a timer. Also, the 877 has no internal oscillators. >=20 > Since you don't enable interrupts (and they default to 'off'), it seems=20 > to me it can only be 2 things: >=20 > 1) The debugger is using a LOT of time (seems unlikely) >=20 > 2) The oscillator is not really running at 4MHz. >=20 > Try running without the debugger (config=3D0F09), because that's easy. > If that doesn't do it, write your own delay >=20 > ms_delay(int d) // Only works with 4MHz clock!!! > { > for(i=3D0;i { > for(j=3D0;j<100;j++) > { > #asm > nop > nop > nop > nop > nop > nop > nop > nop > nop > nop > #endasm > } > } > } >=20 > If that gives you the correct delay, the problem is the delay_ms()=20 > routine, otherwise, it is the clock frequency. >=20 > Kerry >=20 > geetansh arora wrote: >> sorry i missed some details which might be important in solving this >> problem. >> >> I started with my first project but it didn't worked so i decided to go >> back >> and blink leds,now the problem is when the delay between on off was set >> 10ms the leds took 2.3sec(used a stopwatch n delay was approx. 2.3sec). >> At first delay was set to 500ms but it took too much time to blink so >> delay >> was set to 10ms. >> CCS compiler demo version was used for compiling , 4MHz crystal >> oscillator >> was used with 22pF capacitors and configuration bits 2F09 were entered i= n >> PICKIT 2 v2.61 (not used in the code) >> >> #include <16F877A.h> >> #use delay(clock=3D4000000) >> void main() >> { >> while(1) >> { >> output_D(255); >> delay_ms(10); >> output_D(0); >> delay_ms(10); >> } >> } >> please solve my problem guys. >> thank you and sorry again for missing the details in previous post. >> =20 >=20 > --=20 > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist >=20 >=20 --=20 View this message in context: http://old.nabble.com/--delay-time-problem%28= details-added%29-tp31874045p31878500.html Sent from the PIC - [PIC] mailing list archive at Nabble.com. --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .