Connecting Arduino to PIC

What exactly is the PIC supposed to do.
You have set Port A and Port E to inputs.
Are you setting all the pins of Port A and Port E to some combination of logic levels.
The code seems to need a combination of logic to make something happen.
If you set pins to input, then you must connect either a 1 or a 0 to all the pins, or enable pullups ,otherwise they will float
and give erratic results.