Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

delay problem with pic 16f877

geboy

New Member
hai everyone I am using MPLABX IDE with hitech c compiler. I wrote a program to just blink a led at pin RD2. The delay time i programmed is 1second. But the actual delay time is more than 15 seconds . why is that?. How to solve it?
the program is as below
#include<pic.h>
#define _XTAL_FREQ 4000000
void main()
{
TRISD = 0x00;
PORTD=0x00;
while(1)
{
RD2=0;
__delay_ms(1000);
RD2 = 1;
__delay_ms(1000);
}

}
 
Last edited:
hi,
delay problems comes from the improper crystal connection or different value, and the microcontroller fuses setup.
 
Try this -

Code:
#include<htc.h>

__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT);

#define _XTAL_FREQ 4000000

void main(void)
{
	TRISD = 0x00;
	PORTD=0x00;

	while(1)
	{
		RD2=0;
		__delay_ms(1000);
		RD2 = 1;
		__delay_ms(1000);
	}

}
 
i found the problem. The problem was actually because of power supply. It was actually an adapter. I think it's output has ripples.Replaced it with battery then it became alright
 

Latest threads

New Articles From Microcontroller Tips

Back
Top