Trying to understand PIC datasheet for the PIC 12F683

I'm new at asking questions on this forum so please forgive me if my format needs to be cleaned up. I have a PIC 12F683 datasheet. I'm trying to understand how, for instance, ANSEL=0 to set I/O to digital is obtained from a datasheet.

I have searched the web for some clues, but all I seem to find is "it just is." That's not helping me. I just need a little help getting past the bridge between the datasheet information and the actual code that manipulates these ports. Page 39 of "Programming PICs in Basic and page 32 (4-2) of the datasheet makes no sense to me... I'm not the first to post this sort of question from what I have found, but they didn't provide specifics. I'm hoping what I have provided will be enough for one of you folks to see what my question is and help.

I can see on page 31 (4.1 of the datasheet) that the TRISIO register determines direction and it seems clear that applying a "1" to that register will make the corresponding GPIO pin an input and so forth. But when it comes to the ANSEL=0 I'm lost- can't seem to make sense of this. Can someone please throw me a bone?

Taking this datasheet for the PIC12F683 (To ensure we're using the same version of datasheet): http://ww1.microchip.com/downloads/en/devicedoc/41211d_.pdf

Section 4.0 "GPIO PORT" offers a complete description on how the IO port works. You should read this On the right hand side of the page it says:

"Note: The ANSEL and CMCON0 registers must be initialized to configure an analog channel as a digital input. Pins configured as analog inputs will read ‘ 0 ’."

This means if ANSEL and CMCON0 are not configured, any reads on a IO pin that doubles as analog input will always return 0.

Further down in that section at 4.2 you get the detailed description about the ANSEL register and it's bit mask on the next page:

Bits 0 to 3
ANS<3:0>: Analog Select bits
Analog select between analog or digital function on pins AN<3:0>, respectively.
0 = Digital I/O. Pin is assigned to port or special function.


So, writing XXXX0000 to ANSEL makes all pins digital IO. XXXX0001 would make AN0 analog and the other 3 digital, and so on.

CMCOM0's bitmask is described under section 8.7

<snip>
111 = CIN pins are configured as I/O, COUT pin is configured as I/O, Comparator output disabled, Comparator off.


So you need to write XXXXX111 to CMCON0 to disable the comparator and free the pins for digital IO.

• Thank you for responding- before I get more into the datasheet I am confused by the <3:0>. Forgive me for coming across stupid- the colon is throwing me. Part 4.1 shows, for instance, bit 5:4 TRISIO<5:4>. what is the colon referencing? – SignusX1 Dec 31 '14 at 23:06
• Most everything else you have indicated is beginning to make sense- thank you so very much- this is wonderful. I'm beginning to have that "clue." It's that colon separating numeric that is still throwing me though. – SignusX1 Dec 31 '14 at 23:08
• <x:y> is a bitrange from bit X to Y in the given register. So TRISIO<5:4> means bits 5 & 4 of TRISIO. – Unimportant Dec 31 '14 at 23:13
• OK... that makes sense, but... oh boy here it comes... why not use the dash as in "bit 7-6" right above that statement on the same page (page 32)? then below, it states bit 2:0 TRISIO<2:0>- then in the notes (2 and 3) just below it says TRISIO<5:4> always reads etc... then below that it says TRISIO<5> always reads etc. That's why I'm confused. What you say makes sense- the datasheet is confusing me on this point. The note is repeating TRISIO 5 in both statements but saying different things for the same register. Can you shed some further clarification??? – SignusX1 Dec 31 '14 at 23:29
• BTW- thanks to you I understand now why I wasn't getting any output on GPIO 3 as it is clearly defined as an input- not capable of it being an output. Was completely pulling my hair out. – SignusX1 Dec 31 '14 at 23:36