On arduino it works but gives inadequate values because of Arduino runs code on frequency that is sufficiently lower than HSI's 16 MHz (16MHz is according to datasheet).
Then I tried to run the same code on ESP8266 but it does not work and instead of values writes following:
There is an exception encoder for ESP8266 that you can install for IDE 1.x (not sure if there is already an equivalent for IDE 2.x).
If you post your full code, somebody can have a look if there are obvious mistakes in your code; I'm not familiar enough with ESP8266 to advise on that.
Exception 4: Level1Interrupt: Level-1 interrupt as indicated by set level-1 bits in the INTERRUPT register
PC: 0x4010031c: __digitalRead(uint8_t) at C:\Users\hqoffice\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\cores\esp8266\core_esp8266_wiring_digital.cpp:98
EXCVADDR: 0x00000000
Decoding stack results
0x401002bc: is in __digitalWrite(uint8_t, uint8_t) (C:\Users\hqoffice\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\cores\esp8266\core_esp8266_wiring_digital.cpp:87).
0x402011c5: is in writeBit(bool, unsigned int) (C:\Users\hqoffice\Documents\Arduino\Sewer\Sewer/Sewer.ino:71).
0x402011d0: is in writeBit(bool, unsigned int) (C:\Users\hqoffice\Documents\Arduino\Sewer\Sewer/Sewer.ino:72).
0x40201262: is in writeByte(unsigned char) (C:\Users\hqoffice\Documents\Arduino\Sewer\Sewer/Sewer.ino:101).
0x40201654: activation_sequence() at C:\Users\hqoffice\Documents\Arduino\Sewer\Sewer\Sewer.ino:240
0x40201787: loop() at C:\Users\hqoffice\Documents\Arduino\Sewer\Sewer\Sewer.ino:382
0x402017d8: loop() at C:\Users\hqoffice\Documents\Arduino\Sewer\Sewer\Sewer.ino:392
0x40202338: loop_wrapper() at C:\Users\hqoffice\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\cores\esp8266\core_esp8266_main.cpp:258
But it's revealed that ESP8266 is incompatible with interesting for me 5V logic and goes into continously repeated reset when voltage on pins goes higher than 3.6 V
You can use a 3.3V microcontroller in a 5V context if you translate the logic levels from 3.3V to 5V and vice versa. There are small modules for this, and you can make them from discrete components as well. So don't let this stop you; it's easily overcome in virtually all instances.