program stops after approx 4hrs

This

if (digitalRead(7)==HIGH) {pin7=1;} else {pin7=0;};

is a heap of obfuscation that could be

pin7 = digitalRead(7);