Basic code to switch LED for PIC18f4550 XC8 not working!
If you are running your code at 20Mhz, and if I remember correctly, the Fcyc was a Fosc/4 which would mean that you are running your code at 5Mhz.

At 5Mhz thats 200ns per instruction.

Your delay function is ~ 500*165  = 82500 cycles = 16.5ms. It's 'not working' could be that it IS working, but its just not working the way you might have expected. It's probably just toggling too fast for you to see.

Try changing your msdelay(..) to the following

void msdelay(unsigned int ms)
{
   unsingned int x;
   unsigned int z;
   for(x = 0; x &lt; ms ; x++)
     for(z = 0; z &lt; 5000;z++);
}


How did I get 5000 ? 

Each cycle takes 200ns. So to get a delay of 500ms, first you can find out how much it is for 1ms
\$ \frac{1ms}{200ns} = 5000\$

Now when you pass your parameter in ms, for each ms it will run 5000 times.

Hopefully that helps.