I am using an ATmega328P with a 16MHz crystal.
Does this imply that you are not using a pre-assembled board, but instead have made your own board or have it wired on a breadboard? If that is the case, can you post a schematic or pictures of the hardware,
it's possible you have an intermittent connection, defective crystal, inappropriate components, lack of bypass capacitors, etc, that is causing erratic operation. If you have an ISP programmer, you might also want to try running at 8MHz using the internal oscillator instead of the crystal and see if the problem goes away.
Thank you Shannon.
If you know any link [about fuses], I will appreciate you tell me.