can't assign PORTD a variable value on PIC18F
On PICs, you read from PORT and write to LAT. Replace PORTD with LATD. It's also not a bad idea to declare counter as volatile int counter = 0;. Don't forget {} after for(counter = 0; counter&lt;1000; counter++).