Check all of your TRIS statements. It looks like you're using a lot of pins as inputs, but you have them setup as outputs.

trisd=%11000000 ' this leaves D0 through D5 as outputs with only D6 and D7 as inputs.