Electronic – PIC pinout function

picprogramming

My device controlling motor using PWM and read data from serial (uart).
Previously I was using 40 pin and now only 14-pin.
It happenned the "RX" and CCP1 (PWM) are on the same pin. RC5, pin 5.
There is another "RX" on RA1, pin 12.
But I didn't manage to make it work.

I'm using mikroC Pro.

By setting TRISA = 1, does this make Pin 12 as an input?
Could anyone help me on this?

Thank you in advance!

Data sheets and other details can be found here:
PIC16F1824 details

enter image description here

Best Answer

Quote from the data sheet:

The Alternate Pin Function Control 0 (APFCON0) and Alternate Pin Function Control 1 (APFCON1) registers are used to steer specific peripheral input and output functions between different pins. The APFCON0 and APFCON1 registers are shown in Register 12-1 and Register 12-2. For this device family, the following functions can be moved between different pins.

  • RX/DT/TX/CK
  • SDO
  • SS (Slave Select)
  • T1G
  • P1B/P1C/P1D/P2B
  • CCP1/P1A/CCP2

These bits have no effect on the values of any TRIS register. PORT and TRIS overrides will be routed to the correct pin. The unselected pin will be unaffected.

And for the APFCON0 register:

bit 7 RXDTSEL: Pin Selection

  • For 14 Pin Devices (PIC16F/LF1824)
    • 0 = RX/DT function is on RC5
    • 1 = RX/DT function is on RA1
  • For 20 Pin Devices (PIC16F/LF1828)
    • 0 = RX/DT function is on RB5
    • 1 = RX/DT function is on RC5

So setting RXDTSEL to 1 will move the RX to the same pin as RC5

And by setting TRISA to 1 you will be setting all of port A to be output except RA0 which will be input.

Either set it to 2, or set TRISA1 to 1, to set RA1 as an input.

EDIT:

Some other things from the data sheet to note:

If the RX/DT function is on an analog pin, the corresponding ANSEL bit must be cleared for the receiver to function.

... so to use RA1 you have to set ANSEL properly to ensure RA1 is switched to digital input not analog (it defaults to analog IIRC)