Цитата(Tech @ Aug 29 2012, 17:21)

Проект посмотреть не могу т.к. не зарегистрирован, а регистрироваться мне лень.
Разглядывать показания лог.анализатора это как смотреть кино на ч/б ЖК.
Код
/* ------------------------------------------------------------------------- */
/* ------------------------ Oscillator Calibration ------------------------- */
/* ------------------------------------------------------------------------- */
/*
Note: This calibration algorithm may try OSCCAL values of up to 192 even if
the optimum value is far below 192. It may therefore exceed the allowed clock
frequency of the CPU in low voltage designs!
You may replace this search algorithm with any other algorithm you like if
you have additional constraints such as a maximum CPU clock.
For version 5.x RC oscillators (those with a split range of 2x128 steps, e.g.
ATTiny25, ATTiny45, ATTiny85), it may be useful to search for the optimum in
both regions.
*/
void usbEventResetReady(void)
{
#if 1
uchar optVal = 0;
int optDelta = 0x0fff;
int delta;
int targetValue = (unsigned)(1499 * (double)F_CPU / 10.5e6 + 0.5);
uchar i;
uchar j;
if ( _osccal == 0 )
{
// first search for the right OSCCAL
i = 0x20;
j = 0x7c;
}
else
{
// subsequent corrections
i = _osccal - 2;
j = _osccal + 2;
}
for(; i<=j; i++)
{
OSCCAL = i;
delta = usbMeasureFrameLength() - targetValue;
if ( delta<0 )
{
delta = -delta;
}
if ( delta < optDelta )
{
optVal = i;
optDelta = delta;
}
}
_osccal = optVal;
OSCCAL = optVal;
#else
uchar step = 128;
uchar trialValue = 0, optimumValue;xfqybr negj&
int x, optimumDev, targetValue = (unsigned)(1499 * (double)F_CPU / 10.5e6 + 0.5);
/* do a binary search: */
do{
OSCCAL = trialValue + step;
x = usbMeasureFrameLength(); /* proportional to current real frequency */
if(x < targetValue) /* frequency still too low */
trialValue += step;
step >>= 1;
}while(step > 0);
/* We have a precision of +/- 1 for optimum OSCCAL here */
/* now do a neighborhood search for optimum value */
optimumValue = trialValue;
optimumDev = x; /* this is certainly far away from optimum */
for(OSCCAL = trialValue - 1; OSCCAL <= trialValue + 1; OSCCAL++){
x = usbMeasureFrameLength() - targetValue;
if(x < 0)
x = -x;
if(x < optimumDev){
optimumDev = x;
optimumValue = OSCCAL;
}
}
OSCCAL = optimumValue;
#endif
}
Брак - это такой вид отношений, в которых один всегда прав, - а другой - муж.