3
\$\begingroup\$

For example, one pin's name is RA2/AN2/VREF so I wondered what the order is of the functions on this pin. Are they the same or left to right or reverse?

Thank you for your answer.

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

Seems that in general, Microchip I/O ports default to analog input where analog-to-digital converters are available on-chip. This PIC16F877 seems no exception. The configuration of I/O pin function is in 8-bit register ADCON1 (from microchip's pic16f87x data sheet): from microchip pic16f87x data sheet



Note that upon power-up, register ADCON1 defaults to all 0's, which means that if you do no writing to ADCON1, AN2 is analog input, not digital.
To configure RA2 so that it becomes digital input, you would write to register ADCON1 one of:

  • X0000100
  • X0000101
  • X000011X
  • X0001110

where "X" denotes don't care (could be either low or high). If you want RA2 to be digital output, you would also clear a bit in register TRISA.
Awkward? yes...Configuring a limited # of pins for various uses can be confusing, especially so when the methods vary from chip family to chip family. A careful reading of these data sheets is required to see what options are available.

\$\endgroup\$
5
\$\begingroup\$

There is no "order of functions" for pins. Pins that are configurable usually have a "default" configuration, and then you can use the control registers to select an alternate function.

So in your example, the pin is named RA2, it probably defaults to GPIO and has alternate functions as analog input 2 or VREF. There is no "order" there, which one it is depends on which configuration you select.

Usually in naming they are given as:

[Name]/[Alternate 1]/[Alternate 2]/.../[Alternate N]

The order that they appear on a symbol is completely up to the person creating that symbol but is usually the same as the data sheet, although some will just put the name (ie RA2) and some may have them in different order. They are the same pin if they have the same name though (you shouldn't have 2 pins with RA2 in them, but you may have 2 pins with AN2).

\$\endgroup\$
5
  • \$\begingroup\$ Thank you. My teacher asked me this. He also asked for the logic of arranging the pin on the pic, i find so difficult to look up for this request... \$\endgroup\$ Commented Apr 10, 2020 at 15:09
  • 2
    \$\begingroup\$ +1 If the power-on default configuration was ever important, it's no longer so since PICs with ANSEL registers default to analog inputs but the GPIO numbering is shown first (eg. RB5/AN13/T1G on the [PIC16F882](RB5/AN13/T1G). Probably more like a primary function/secondary function kind of thing. \$\endgroup\$ Commented Apr 10, 2020 at 15:17
  • 1
    \$\begingroup\$ @NguyễnPhúc The physical arrangement of the pins on the processor deals more with the arrangement of the actual silicon die and the functions that the wire-bonded "block" that it attaches to has. \$\endgroup\$
    – Ron Beyer
    Commented Apr 10, 2020 at 15:44
  • \$\begingroup\$ Oh, so the arrangement of the pins and its function is based on the area of material on the pic?? \$\endgroup\$ Commented Apr 10, 2020 at 15:57
  • 1
    \$\begingroup\$ Not really the "area of material", a silicon die is made up of (standard in the manufacturer) logical blocks of functions, die manufacturers (like Microchip) take these "blocks" and place them around the chip in logical locations around a core logic block. The physical arrangement of these blocks dictates the physical pin layout. It's kind of like building a microchip with logical "lego" bricks. You choose the bricks, arrange them on the die, then connect the pins to make a microcontroller. \$\endgroup\$
    – Ron Beyer
    Commented Apr 10, 2020 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.