There was a timing problem with delay() function which is tested only in Proteus simulation.
I think that it's an issue of the official Arduino core.
I changed the implementation of delay(ms) function and now the problem is resolved.
Here is the official Arduino core code in wiring.c:
void delay(unsigned long ms)
{
uint32_t start = micros();
while (ms > 0) {
yield();
while ( ms > 0 && (micros() - start) >= 1000) {
ms--;
start += 1000;
}
}
}
And this is my code:
void delay(signed long ms)
{
if (ms > 0)
{
unsigned long start = micros();
unsigned long stop = start + ms * 1000UL;
while (micros() <= stop)
{
yield();
}
}
}