help me to understand ANSEL register in PIC
You should set the ANSEL bit high for any pin for which you want to use the analog function. Otherwise set it low to use the digital function. 

If you leave it low and need analog functionality it won't work at all.  

If you leave it high, in this particular chip, the digital output will still work, however the pin will read zero. If this is a chip without the LAT function, a read-modify-write instruction will cause incorrect operation. 

For example, you write 0xFF to the port and the ANSEL bit corresponding to bit 1 is 1, then all pins will indeed go high. However if I try to set bit 0 to 0 (a read-modify-write instruction - BCF in assembly language) so the port is expected to go to 0xFE then both bits 0 and 1 will go to zero (0xFC), because the instruction will write back the value it read from bit 1. This is usually very undesirable- it changes a bit that you had no intention of modifying. 

Here is the machine cycle activity of a BCF instruction in a midrange PIC: 



In cycle Q2 the register (a port in this case) is read, the desired bit is cleared, and then it is written back to the same register. 

In the above example, the machine language instruction for clearing bit 0 of PORTA would be: 

 BCF PORTA, 0  


A compiler will add a layer on top of the machine language instructions, but unless they implement a shadow register (which slows things down so it would probably be an undesirable default) the RMW issue exists.