the led doesn't blinking every second but like a wifi modem led( i mean it blinks completely irregularly not one second on and one second off just like a wifi router LED). If i write the code like blow it works perfectly:
Sorry its my bad.
I mean normally it must be one second on and one second off. But t's blinking irregularly. Once its on for second then off for millisecond then rapidly blinking for some seconds then off for second and so on, just like a modem led
If that code results in irregular blinking, AND YOU HAVE NOTHING CONNECTED TO THE LED PIN CIRCUITRY, then the most likely culprit is a damaged LED, likely a cracked solder joint. There's not much else that can cause the issue you're describing, barring a varying CPU oscillator or something equally off-the-wall.
Led works well in certain conditions. As i mentioned above when i use direct register addressing (i mean using something like potb |= 1<<x) or just enabling serial it works well. So i don't think it is hardware
And forgot to say, i have this problem in all pins. I mean if i change the pin the other pins acts like this too.
There is only one pin connected to the onboard LED ("L" LED). Are you talking about using external LEDs? If so, please post a schematic showing your circuit.
Yes i used external LED with a resistor. The end of resistor connected to Gnd and led connected to the pin. Sorry can't send schematic right now but suppose something like this
I just loaded your first sketch up into a Mega here (after removing the errant text you added after posting), and the onboard L LED (which is hooked up to pin 13) is blinking one second on, one second off.