pic 16F876A is running slow on 20MHZ crystal i want to get 1 second delay

Status
Not open for further replies.
Using hardware timer or delay counter? Is your crystal oscillator High speed type, ceramic resonator; did you select the correct capacitors with the type of crystal in use?
 

check the config bits and use HS for 20MHz..

in hitech compiler use

Code C - [expand]
1
2
3
4
#define _XTAL_FREQ 20000000 // in top
 
for(i = 0; i < 40; i++)
__delay_ms(25);

 

Use timers for proper delay. If you need , I can help you with code.
Or you can use :-
Code:
#define _XTAL_FREQ 20000000 // in top
// OR you can use configuration bits also
#pragma config FOSC=HSMP ,PLLCFG=OFF,IESO=OFF
void delay_ms(unsigned int time) // Here TIME is in MILLISECONDS
{
//Delay part
    unsigned char pause, i = 0; //DECLARE PAUSE AS UNSIGNED CHAR
    short int temp = 0;

    temp = time;
    for (i = 0; i < 4; i++) {
        time = temp;
        while (time > 0) //LOOP UNTIL TIME IS GREATER THAN ZERO
        {
            pause = 112; //INITIALIZE PAUSE TO 255
            while (pause--); //DECREMENT PAUSE UNTIL IT BECOMES ZERO
            time--; //DECREMENT TIME AND LOOP BACK UNTIL IT BECOMES ZERO
        }
    }

}
 
Last edited:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…