Please Need Help to combine two codes

What are you getting as opposed to what your not getting?

From what I see, your getting some confliction here.
DDRB = B00000000; // set pins 8 to 13 as inputs
pinMode(13,OUTPUT);
pinMode(11,OUTPUT);

I can't look at all of if right now, myself, but just skimming through it, there are a few mistakes.

You know both codes work indepently, so try some debugging with the serial monitor.

Post any and all errors.