Угу, вот такое УГ
volatile uint8_t background;
volatile uint16_t valve_close_delay;
volatile uint8_t blink_count;
volatile uint8_t blink_flag;
volatile uint16_t sec_count;
volatile uint8_t wdt_count;
volatile uint16_t _500ms_count;
volatile uint16_t _100ms_count;
volatile uint16_t _200ms_count;
volatile uint16_t capt_timer;
volatile uint32_t op_count;
volatile uint32_t beep_time;
volatile uint16_t beeps_count;
volatile uint16_t sound_count;
// #define bSound 0x01
#define b100ms 0x02
#define b200ms 0x04
#define b500ms 0x08
#define bSec 0x10
#define bOpOver 0x20
#define bWdt 0x40
#define bMin 0x80
//******* DELAY SUPPORT *******//
volatile uint32_t delay_count;
// volatile u8 wdt_flag;
// volatile s32 last_CU_time;
void StartDelay(uint32_t ms)
{ __disable_interrupt();
delay_count=ms;
__enable_interrupt();}
void DelayMs(uint32_t ms)
{ StartDelay( ms * 10L );
while(delay_count>0)
CheckTimeAndResetWDT()
;
// WDT_RESET();
}
void Delay(uint32_t _100us)
{ StartDelay( _100us );
while(delay_count>0)
CheckTimeAndResetWDT()
;
}
void StartOperation(uint32_t time)
{ op_count = time;
background&=~bOpOver;
}
char DelayOver(void)
{ return (delay_count==0); }
void Restart100ms(void) { _100ms_count=N10Hz; background&=~b100ms; }
void Restart500ms(void) { _500ms_count=N2Hz; background&=~b500ms; }
void RestartSecond(void) { sec_count=N1Hz; background&=~bSec; }
#ifdef APPL
/*
void Beep (uint16_t ms, char beeps)
{ if (se[nSound] == sndALWAYS_OFF)
return;
beep_time=ms;
beeps_count=beeps<<1;
sound_count=ms;
}
*/
#endif
void BackgroundService100us(void)
{
/*
if (com1.timeout)
com1.timeout--;
if (com1.rx_timeout<255)
com1.rx_timeout++;
if (com3.timeout)
com3.timeout--;
*/
if (opto_tx_busy)
{ opto_rx_disable=1;
opto_rx_delay = 0;
}
else
{ if (opto_rx_delay < OPTO_RX_DELAY)
opto_rx_delay++;
else
opto_rx_disable = 0;
}
if (valve_close_delay)
valve_close_delay--;
if (delay_count)
delay_count--;
if (op_count)
op_count--;
if (opto_timeout)
opto_timeout--;
if (sec_count)
sec_count--;
else
{ sec_count=N1Hz;
background|=bSec;
}
if (_500ms_count)
_500ms_count--;
else
{ _500ms_count=N2Hz;
background|=b500ms;
}
if (_200ms_count)
_200ms_count--;
else
{ _200ms_count=N5Hz;
background|=b200ms;
}
if (_100ms_count)
_100ms_count--;
else
{ _100ms_count=N10Hz;
background|=b100ms;
}
if (wdt_count)
wdt_count--;
else
{ wdt_count=N50Hz;
background|=bWdt;
}
}
tEVENT GetTimerEvent(void)
{
if (background&b100ms) { background&=~b100ms; return (ev100ms); }
if (background&b200ms) { background&=~b200ms; return (ev200ms); }
if (background&b500ms) { background&=~b500ms; return (ev500ms); }
if (background&bSec) { background&=~bSec; return (evSec); }
if (background&bMin) { background&=~bMin; return (evMin); }
return(evNo);
}
void CheckTimeAndResetWDT(void)
{if (background&bWdt)
{ background&=~bWdt;
// TogglePin(PulseWdt);
}
}
void BackgroundInit(void)
{ background=0;
wdt_count=1;
_100ms_count=2;
_500ms_count=4;
sec_count=5;
// min_count=6;
}