krtodoroff
Newbie level 5
I use this code with is not mine, but for my rogram i need 10MHz crystal.
Pleace help me how to change it. I'm using PIC 16F877A and 10Mhz crystal. My compiler is Mikroc.
code:
#define XTALHz 4000000 // 4 Mhz. (can trim this to fine-tune clock speed)
//=============================================================================
// POLL TIMER
//=============================================================================
void poll_timer(void)
{
//-----------------------------------------------------
// this function must be called often, don't allow more
// than 131 mS between calls.
// 8Mhz; TMR1 1:4 prescale overflows every 7.6Hz (131mS)
// (if 20Mhz TMR1 1:4 prescale overflows every 19Hz (53mS))
//
// TMR1 is at 1:4 prescaler, so 1 second = xtal Mhz / 16.
//-----------------------------------------------------
// if TMR1 overflowed, check if 1 second has passed
if(PIR1.TMR1IF)
{
// clear overflow flag
PIR1.TMR1IF = 0;
// add another overflow period to total
period += 65536;
// test if reached 1 second yet...
if(period >=(XTALHz / 16) )
{
period -= ((XTALHz / 16) );
new_second = 1;
}
}
}
poll_timer();
if (new_second)
{
new_second = 0;
....
}
...
} // Endless loop while
Pleace help me how to change it. I'm using PIC 16F877A and 10Mhz crystal. My compiler is Mikroc.
code:
#define XTALHz 4000000 // 4 Mhz. (can trim this to fine-tune clock speed)
//=============================================================================
// POLL TIMER
//=============================================================================
void poll_timer(void)
{
//-----------------------------------------------------
// this function must be called often, don't allow more
// than 131 mS between calls.
// 8Mhz; TMR1 1:4 prescale overflows every 7.6Hz (131mS)
// (if 20Mhz TMR1 1:4 prescale overflows every 19Hz (53mS))
//
// TMR1 is at 1:4 prescaler, so 1 second = xtal Mhz / 16.
//-----------------------------------------------------
// if TMR1 overflowed, check if 1 second has passed
if(PIR1.TMR1IF)
{
// clear overflow flag
PIR1.TMR1IF = 0;
// add another overflow period to total
period += 65536;
// test if reached 1 second yet...
if(period >=(XTALHz / 16) )
{
period -= ((XTALHz / 16) );
new_second = 1;
}
}
}
poll_timer();
if (new_second)
{
new_second = 0;
....
}
...
} // Endless loop while
Last edited: