This should work... but as we don't se the whole code, it's hard to tell if you don't have anything missing in it. Make sure you have disabled all analog stuff on the pin you're using and it should be ok... unless i missed something