You don't mention what processor you're using?, but assuming it's the 16F628?, then RA2 can be set as a voltage reference OUTPUT, or as a comparator input, as well as normal I/O - have you set the CMCON and VRCON registers correctly?.
That's why it doesn't work then, by default the comparators are ON, you don't normally need to alter VRCON (I never have!), but you need to set CMCON to turn the comparators OFF - see my tutorials that all do that!.