trouble with simple IF...ELSE

Make it static, or global. Actually it is erased when the function is exited, and recreated each time the function is called.

void BlinkLED13() 
{
  // blinks LED 13
  static int pinstate;