thanks for the input to all. The problem was that my MCLR pin was not made high and was left floating. Its working now.