hola ,
ok mira te dejo el código para los métodos rápidos o mejor dicho macros de asociar una función hardware a unos pines PPS
deberás solo mapear tus pines
y se usa asi
RX TX
SetUART1wpps(RP0,RP1); y ya tienes la uart sobre los rp que quieres
/*¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
¦¦__________________[RTOSys PPS for PIC24F ]_____________________
¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
¦¦
¦¦ FileName: OSpps24F.h
¦¦ Dependencies: ...
¦¦ Processor: MCU PIC24FJ64GA004
¦¦ Compiler: C30
¦¦ Hardware: Generic
¦¦
¦¦ Company: RTOSys project group
¦¦ OSCompany: RTOSys project group
¦¦
¦¦ Software License Agreement:
¦¦
¦¦ - Limited Use -
¦¦
¦¦¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
¦¦ Author ¦ Date ¦ Comment
¦¦¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¦¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¦¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
¦¦ Maurizio Spoto ¦ 10-06-2008 ¦ Start Project
¦¦ ¦ ¦
¦¦_______________________________________________________________
¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨*/
#define _PPS_P24FJ64GA004_
typedef enum _PPS_INPUT
{
INULL = (0u),
FINT1,
FINT2,
FINT3,
FINT4,
FT2CK,
FT3CK,
FT4CK,
FT5CK,
FIC1,
FIC2,
FIC3,
FIC4,
FIC5,
FOCFA,
FOCFB,
FU1RX,
FU1CTS,
FU2RX,
FU2CTS,
FSDI1,
FSCK1,
FSS1,
FSDI2,
FSCK2,
FSS2
}ppsInputFunction;
typedef enum _PPS_OUTPUT
{
ONULL = (0u),
FC1OUT,
FC2OUT,
FU1TX,
FU1RTS,
FU2TX,
FU2RTS,
FSDO1,
FSCK1OUT,
FSS1OUT,
FSDO2,
FSCK2OUT,
FSS2OUT,
FOC1 = (18u),
FOC2,
FOC3,
FOC4,
FOC5
}ppsOutputFunction;
typedef enum _PPS_PIN
{
RP0 = (0u),
RP1 ,RP2 ,RP3 ,RP4 ,RP5 ,
RP6 ,RP7 ,RP8 ,RP9 ,RP10,
RP11,RP12,RP13,RP14,RP15,
RP16,RP17,RP18,RP19,RP20,
RP21,RP22,RP23,RP24,RP25
}ppsPin;
//BIT INDEX FUNCTION TO PPS INPUT REG
#define IINT1 RPINR0bits.INT1R
#define IINT2 RPINR1bits.INT2R
#define IINT3 RPINR1bits.INT3R
#define IINT4 RPINR2bits.INT4R
#define IT2CK RPINR3bits.T2CKR
#define IT3CK RPINR3bits.T3CKR
#define IT4CK RPINR4bits.T4CKR
#define IT5CK RPINR4bits.T5CKR
#define IIC1 RPINR7bits.IC1R
#define IIC2 RPINR7bits.IC2R
#define IIC3 RPINR8bits.IC3R
#define IIC4 RPINR8bits.IC4R
#define IIC5 RPINR9bits.IC5R
#define IOCFA RPINR11bits.OCFAR
#define IOCFB RPINR11bits.OCFBR
#define IU1RX RPINR18bits.U1RXR
#define IU1CTS RPINR18bits.U1CTSR
#define IU2RX RPINR19bits.U2RXR
#define IU2CTS RPINR19bits.U2CTSR
#define ISDI1 RPINR20bits.SDI1R
#define ISCK1 RPINR20bits.SCK1R
#define ISS1 RPINR21bits.SS1
#define ISDI2 RPINR22bits.SDI2R
#define ISCK2 RPINR22bits.SCK2R
#define ISS2 RPINR23bits.SS2
//BIT OUTPUT
#define ORP0 RPOR0bits.RP0R
#define ORP1 RPOR0bits.RP1R
#define ORP2 RPOR1bits.RP2R
#define ORP3 RPOR1bits.RP3R
#define ORP4 RPOR2bits.RP4R
#define ORP5 RPOR2bits.RP5R
#define ORP6 RPOR3bits.RP6R
#define ORP7 RPOR3bits.RP7R
#define ORP8 RPOR4bits.RP8R
#define ORP9 RPOR4bits.RP9R
#define ORP10 RPOR5bits.RP10R
#define ORP11 RPOR5bits.RP11R
#define ORP12 RPOR6bits.RP12R
#define ORP13 RPOR6bits.RP13R
#define ORP14 RPOR7bits.RP14R
#define ORP15 RPOR7bits.RP15R
#define ORP16 RPOR8bits.RP16R
#define ORP17 RPOR8bits.RP17R
#define ORP18 RPOR9bits.RP18R
#define ORP19 RPOR9bits.RP19R
#define ORP20 RPOR10bits.RP20R
#define ORP21 RPOR10bits.RP21R
#define ORP22 RPOR11bits.RP22R
#define ORP23 RPOR11bits.RP23R
#define ORP24 RPOR12bits.RP24R
#define ORP25 RPOR12bits.RP25R
#if defined(_PPS_P24FJ64GA004_)
//RP0
#define PRP0_TRIS (TRISBbits.TRISB0)
#define PRP0_WR_IO (LATBbits.LATB0)
#define PRP0_RD_IO (PORTBbits.RB0)
//RP1
#define PRP1_TRIS (TRISBbits.TRISB1)
#define PRP1_WR_IO (LATBbits.LATB1)
#define PRP1_RD_IO (PORTBbits.RB1)
//RP2
#define PRP2_TRIS (TRISBbits.TRISB2)
#define PRP2_WR_IO (LATBbits.LATB2)
#define PRP2_RD_IO (PORTBbits.RB2)
//RP3
#define PRP3_TRIS (TRISBbits.TRISB3)
#define PRP3_WR_IO (LATBbits.LATB3)
#define PRP3_RD_IO (PORTBbits.RB3)
//RP4
#define PRP4_TRIS (TRISBbits.TRISB4)
#define PRP4_WR_IO (LATBbits.LATB4)
#define PRP4_RD_IO (PORTBbits.RB4)
//RP5
#define PRP5_TRIS (TRISBbits.TRISB5)
#define PRP5_WR_IO (LATBbits.LATB5)
#define PRP5_RD_IO (PORTBbits.RB5)
//RP6
#define PRP6_TRIS (TRISBbits.TRISB6)
#define PRP6_WR_IO (LATBbits.LATB6)
#define PRP6_RD_IO (PORTBbits.RB6)
//RP7
#define PRP7_TRIS (TRISBbits.TRISB7)
#define PRP7_WR_IO (LATBbits.LATB7)
#define PRP7_RD_IO (PORTBbits.RB7)
//RP8
#define PRP8_TRIS (TRISBbits.TRISB8)
#define PRP8_WR_IO (LATBbits.LATB8)
#define PRP8_RD_IO (PORTBbits.RB8)
//RP9
#define PRP9_TRIS (TRISBbits.TRISB9)
#define PRP9_WR_IO (LATBbits.LATB9)
#define PRP9_RD_IO (PORTBbits.RB9)
//RP10
#define PRP10_TRIS (TRISBbits.TRISB10)
#define PRP10_WR_IO (LATBbits.LATB10)
#define PRP10_RD_IO (PORTBbits.RB10)
//RP11
#define PRP11_TRIS (TRISBbits.TRISB11)
#define PRP11_WR_IO (LATBbits.LATB11)
#define PRP11_RD_IO (PORTBbits.RB11)
//RP12
#define PRP12_TRIS (TRISBbits.TRISB12)
#define PRP12_WR_IO (LATBbits.LATB12)
#define PRP12_RD_IO (PORTBbits.RB12)
//RP13
#define PRP13_TRIS (TRISBbits.TRISB13)
#define PRP13_WR_IO (LATBbits.LATB14)
#define PRP13_RD_IO (PORTBbits.RB15)
//RP14
#define PRP14_TRIS (TRISBbits.TRISB14)
#define PRP14_WR_IO (LATBbits.LATB14)
#define PRP14_RD_IO (PORTBbits.RB14)
//RP15
#define PRP15_TRIS (TRISBbits.TRISB15)
#define PRP15_WR_IO (LATBbits.LATB15)
#define PRP15_RD_IO (PORTBbits.RB15)
//RP16
#define PRP16_TRIS (TRISCbits.TRISC0)
#define PRP16_WR_IO (LATCbits.LATC0)
#define PRP16_RD_IO (PORTCbits.RC0)
//RP17
#define PRP17_TRIS (TRISCbits.TRISC1)
#define PRP17_WR_IO (LATCbits.LATC1)
#define PRP17_RD_IO (PORTCbits.RC1)
//RP18
#define PRP18_TRIS (TRISCbits.TRISC2)
#define PRP18_WR_IO (LATCbits.LATC2)
#define PRP18_RD_IO (PORTCbits.RC2)
//RP19
#define PRP19_TRIS (TRISCbits.TRISC3)
#define PRP19_WR_IO (LATCbits.LATC3)
#define PRP19_RD_IO (PORTCbits.RC3)
//RP20
#define PRP20_TRIS (TRISCbits.TRISC4)
#define PRP20_WR_IO (LATCbits.LATC4)
#define PRP20_RD_IO (PORTCbits.RC4)
//RP21
#define PRP21_TRIS (TRISCbits.TRISC5)
#define PRP21_WR_IO (LATCbits.LATC5)
#define PRP21_RD_IO (PORTCbits.RC5)
//RP22
#define PRP22_TRIS (TRISCbits.TRISC6)
#define PRP22_WR_IO (LATCbits.LATC6)
#define PRP22_RD_IO (PORTCbits.RC6)
//RP23
#define PRP23_TRIS (TRISCbits.TRISC7)
#define PRP23_WR_IO (LATCbits.LATC7)
#define PRP23_RD_IO (PORTCbits.RC7)
//RP24
#define PRP24_TRIS (TRISCbits.TRISC8)
#define PRP24_WR_IO (LATCbits.LATC8)
#define PRP24_RD_IO (PORTCbits.RC8)
//RP25
#define PRP25_TRIS (TRISCbits.TRISC9)
#define PRP25_WR_IO (LATCbits.LATC9)
#define PRP25_RD_IO (PORTCbits.RC9)
#endif
/* OS LOCK PPS:
|
| remap OSCCONL bit
|
| push reg
|
| free OSCCON
|
| pop reg
|
|_______________________________________*/
//
#define LOCKPPS() __builtin_write_OSCCONL(OSCCON | 0x40); \
asm volatile ( "push w1 \n push w2 \n push w3 \n" \
"mov #OSCCON,w1 \n" \
"mov #0x46, w2 \n" \
"mov #0x57, w3 \n" \
"mov.b w2,[w1] \n" \
"mov.b w3,[w1] \n" \
"bset OSCCON, #6 \n" \
"pop w3 \n pop w2 \n pop w1");
/* OS UNLOCK PPS:
|
| clear OSCCONL bit
|
| push reg
|
| free OSCCON
|
| pop reg
|
|_______________________________________*/
#define UNLOCKPPS() __builtin_write_OSCCONL(OSCCON & 0xbf); \
asm volatile ( "push w1 \n push w2 \n push w3 \n" \
"mov #OSCCON, w1 \n" \
"mov #0x46, w2 \n" \
"mov #0x57, w3 \n" \
"mov.b w2, [w1] \n" \
"mov.b w3, [w1] \n" \
"bclr OSCCON, #6 \n" \
"pop w3 \n pop w2 \n pop w1");
#define PIN_INPUT (1)
#define PIN_OUTPUT (0)
/* OS PPS SET:
|
| a = PPS Mode PIN (PIN_OUTPUT/PIN_INPUT)
|
| b = PPS PIN NUMBER (RP0,RP1,...)
|
| c = PPS INPUT FUNCTION (U1RX, U2RX,... )
|
| d = PPS OUTPUT FUNCTION (U1TX, U2TX,... )
|
| examples:
|
| SetPPS(PIN_INPUT,RP0,U1RX,ONULL);
|
| SetPPS(PIN_OUTPUT,RP1,INULL,U1TX);
|
|_______________________________________*/
#define SetPPS(a,b,c,d) P##b##_TRIS = (a); \
if(a) I##c = (b); \
else O##b = (c);
/* OS PPS SET input PIN:
|
| a = PPS PIN NUMBER (RP0,RP1,...)
|
| b = PPS INPUT FUNCTION (U1RX, U2RX,... )
|
| example:
|
| SetPPSinputFunction(RP0,U1RX);
|
|_______________________________________*/
#define SetPPSinputFuncition(a,b) P##a##_TRIS = 1; \
I##b = (a);
#define SetPPSinput(a) P##a##_TRIS = 1;
/* OS PPS SET output PIN:
|
| a = PPS PIN NUMBER (RP0,RP1,...)
|
| b = PPS OUTPUT FUNCTION (U1TX, U2TX,... )
|
| example:
|
| SetPPSoutputFunction(RP0,U1TX);
|
|_______________________________________*/
#define SetPPSoutputFunction(a,b) P##a##_TRIS = 0; \
O##a = (F##b);
#define SetPPSoutput(a) P##a##_TRIS = 0;
/* OS PPS WRITE PIN:
|
| a = PPS PIN NUMBER (RP0,RP1,...)
|
| b = value;
|
| example:
|
| WritePPSpin(RP0,0);
|
|_______________________________________*/
#define WritePPSpin(a,b) P##a##_WR_IO = b
/* OS PPS READ PIN:
|
| a = PPS PIN NUMBER (RP0,RP1,...)
|
| return value
|
| example:
|
| ReadPPSpin(RP0);
|
|_______________________________________*/
#define ReadPPSpin(a) P##a##_RD_IO
/* OS PPS SET FULL UART:
|
| a = RX PPS PIN (RP0,RP1,...)
|
| b = TX PPS PIN (RP0,RP1,...)
|
| c = CTS PPS PIN (RP0,RP1,...)
|
| d = RTS PPS PIN (RP0,RP1,...)
|
| examples:
| RX TX RTS CTS
| SetFullUART1wpps(RP0,RP2,RP1,RP3)
|
|_______________________________________*/
#define SetFullUART1wpps(a,b,c,d) \
P##a##_TRIS = 1; P##b##_TRIS = 0; \
P##c##_TRIS = 1; P##d##_TRIS = 0; \
IU1RX = a; IU1RTS = c; \
O##b = OU1TX; O##d = OU1CTS
#define SetFullUART2wpps(a,b,c,d) \
P##a##_TRIS = 1; P##b##_TRIS = 0; \
P##c##_TRIS = 1; P##d##_TRIS = 0; \
IU2RX = a; IU2RTS = c; \
O##b = OU2TX; O##d = OU2CTS
/* OS PPS SET HALF UART:
|
| a = RX PPS PIN (RP0,RP1,...)
|
| b = TX PPS PIN (RP0,RP1,...)
|
| examples:
| RX TX
| SetUART1wpps(RP0,RP1)
|
|_______________________________________*/
#define SetUART1wpps(a,b) \
P##a##_TRIS = 1; P##b##_TRIS = 0; \
IU1RX = a; O##b = FU1TX;
#define SetUART2wpps(a,b) \
P##a##_TRIS = 1; P##b##_TRIS = 0; \
IU2RX = a; O##b = FU2TX;
saludos.