2
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ "Note 1: Pin function is selectable via the APFCON0 or APFCON1 registers" \$\endgroup\$ – markrages Jun 18 '11 at 17:34
5
\$\begingroup\$

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)

\$\endgroup\$
  • \$\begingroup\$ Thanks @Matt. This is very helpful. But I still didn't manage to get it work. If I put serial pin out to RC5, it works fine. But if I moved to RA1 even by setting RXDSEL, it doesn't work. The funny thing, for RC5 I don't have to anything, even the TRISC = 0 and PORTC = 0. This is my code: TRISA = 255; PORTA = 255; APFCON0.RXDTSEL = 1; //0:RX is on RC5 1:RX is on RA1' \$\endgroup\$ – mlam Jun 19 '11 at 14:59
  • \$\begingroup\$ Have you switched RA1 to digital input? See my edit. \$\endgroup\$ – Majenko Jun 19 '11 at 15:15
  • \$\begingroup\$ @Matt, yes. It's sitting together with AN1. How do I clear it? I know I asked a lot. I'm a hobbyist. \$\endgroup\$ – mlam Jun 19 '11 at 15:17
  • \$\begingroup\$ @mlam hey, don't sweat it - I'm new to the PICs too and am still learning. The data sheets often take a bit of decrypting ;) Try setting TRISA to 0xFD so that RA1 is set to an output - I think this may be needed on some PICs, but I haven't used the PIC you are using so far. \$\endgroup\$ – Majenko Jun 19 '11 at 15:26
  • \$\begingroup\$ @Matt, You are awesome dude :)) I really appreciate your help and fast reply. Thanks a lot. It works now. I added ANSELA = 0x00; \$\endgroup\$ – mlam Jun 19 '11 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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