• AVR Freaks

DSPIC33F - Remappable pins

Page: 12 > Showing page 1 of 2
Author
cts_casemod
Junior Member
  • Total Posts : 112
  • Reward points : 0
  • Joined: 2014/07/06 15:26:22
  • Location: 0
  • Status: offline
2014/12/04 18:19:47 (permalink)
0

DSPIC33F - Remappable pins

Hi folks,
I need configure some remap. pins on a DSPIC33FJ12MC202
 
I found this code for C, would someone be kind enough to see the asm output of the compiler? I'm not sure how to do that.
 
Many Thanks
 
     //Unlock the registers
     __builtin_write_OSCCONL(OSCCON & ~(1<<6));
 
     // Mapp to RP pin input
     RPINR22bits.SDI2R = 0b01111; // SDI2 uses RP15, device pin #26, RPINR22: PERIPHERAL PIN SELECT INPUT REGISTER 22
     // Mapp to RP pin output
     RPOR7bits.RP14R = 0b01010; // SDO2 uses RP14, device pin #25, RPOR14: PERIPHERAL PIN SELECT OUTPUT REGISTERS 14
     RPOR5bits.RP11R = 0b01011; // SCK2 uses RP11, device pin #22, RPOR11: PERIPHERAL PIN SELECT OUTPUT REGISTERS 11
     RPOR3bits.RP7R = 0b01100; // SS2 uses RP7, device pin #16, RPOR7: PERIPHERAL PIN SELECT OUTPUT REGISTERS 7
 
     //Lock the registers
     __builtin_write_OSCCONL(OSCCON | (1<<6));

 
post edited by cts_casemod - 2014/12/04 18:21:06
#1

21 Replies Related Threads

    MBedder
    Circuit breaker
    • Total Posts : 6750
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 02:02:11 (permalink)
    4 (2)
    Forget it. Everything is already done for you:
    #include <PPS.h>
     
    #define PPSin(fn,pin)    iPPSInput(IN_FN_PPS##fn,IN_PIN_PPS##pin)
    #define PPSout(fn,pin)    iPPSOutput(OUT_PIN_PPS##pin,OUT_FN_PPS##fn)
     
    PPSUnLock;
     
    PPSin (_SDI2,_RP15);
    PPSin (_SS2,_RP7);
     
    PPSout (_SDO2,_RP14);
    PPSout (_SCK2,_RP11);
     
    PPSLock;

     
    See this post for details.
    post edited by MBedder - 2014/12/05 02:10:09
    #2
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 03:35:00 (permalink)
    0
    Hi, perhaps I didn't ask correctly. What I am looking is the compiled assembly output code

    I am programming in asm and have seen no examples to set up the remappable pins, so I'm not really sure what goes where, that's the reason I'm want to look at the compiled assembly output.
    #3
    balmerjd
    Super Member
    • Total Posts : 554
    • Reward points : 0
    • Joined: 2011/03/31 09:18:20
    • Location: Urbana, Ohio
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 05:23:11 (permalink)
    4 (1)
    cts_casemod
    Hi, perhaps I didn't ask correctly. What I am looking is the compiled assembly output code

    I am programming in asm and have seen no examples to set up the remappable pins, so I'm not really sure what goes where, that's the reason I'm want to look at the compiled assembly output.

    Are you saying that you do not know how to do masking operations in ASM?  Because all the information you need is right there in your first post.
     
    I will give you one example.  Your first PPS setting from above.  If you open up the include file for your processor you will notice after all of the register declarations that for each register there are a set of equates written for each bit that defines the function of that bit as a number.  This is so you can do simple shift operations.  So that being said. That means that:
     
    RPINR22bits.SDI2R = 0b01111;
    Translates to this
     
    MOV    #~(0b11111 << SDI2R0),W0    ;<---generate a mask that is the width of SDI2R to clear the SDI2R bits in RPINR22
    AND    RPINR22         ; Apply mask to clear specified bits.
    MOV    #(0b01111 << SDI2R0),W0      ;<---take desired value and move it over the need number of bits
    IOR    RPINR22         ; Or the value into the register to prevent disturbing the other bits.

     
    The other way if you know what you want all the bits in the register to be is to generate a single value and simply move that value into one of the working registers and then move it into RPINR22.
     
    Another way yet, if you are a REAL glutton for punishment is to take the pps.h file and translate it into an assembly based include file that will give you access to the PPSin and PPSout macros in assembly.  (which is what I did...)
    #4
    MBedder
    Circuit breaker
    • Total Posts : 6750
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 06:02:43 (permalink)
    4.5 (2)
    Next time please be more specific. Here is an ASM30 version of the above.
    #5
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 09:36:58 (permalink)
    0
    I'm not sure if I have to do any modification on that library. The compiler complains about this line:
     
    .macro enum_rpx
    .if (\@ < 32)
    RP\@ = \@
    .else
    RPI\@ = \@
    .endif
    .if (\@ < 63)
    enum_rpx
    .endif
    .endm

     
    Even the reference manual sows how to do the register lock/unlock in asm, but the actual port mapping is done in C, which hides what actually needs to be done in low level.
     
    Say for example, i want to map SDI pin.
    According to the reference manual, this pin is set by using register RPINR20, bits 0...4, which i would set in accordance to the RPn pin to be mapped to that peripheral.
     
    So I would do:
    Set the corresponding pins as inputs/Outputs:

    ;Set PORTB 10-15, outputs for the power module
    ;Set PORTB9 as Output for SPI (SDO)
    ;Set PORT8...6 as Inputs for SPI (SDI, SCK,SS)
    mov #0b0000000111111111,W0
    ; Load this variable into TRISB Register
    mov W0,TRISB


    ;Unlock the register

    mov #0x742,w1
    mov #0x46,w2
    mov #0x57,w3
    mov.b w2,[w1]
    mov.b w3,[w1]
    bclr 0x742,#6

    ; Mapp to RP pin input
      RPINR22bits.SDI2R = 0b01111; SDI2 uses RP15, device pin #26, RPINR22: PERIPHERAL PIN SELECT INPUT REGISTER 22
    ; Mapp to RP pin output
      RPOR7bits.RP14R = 0b01010; SDO2 uses RP14, device pin #25, RPOR14: PERIPHERAL PIN SELECT OUTPUT REGISTERS 14
      RPOR5bits.RP11R = 0b01011; // SCK2 uses RP11, device pin #22, RPOR11: PERIPHERAL PIN SELECT OUTPUT REGISTERS 11
      RPOR3bits.RP7R = 0b01100; // SS2 uses RP7, device pin #16, RPOR7: PERIPHERAL PIN SELECT OUTPUT REGISTERS 7

    ;Lock the register
    mov #0x742,w1
    mov #0x46,w2
    mov #0x57,w3
    mov.b w2,[w1]
    mov.b w3,[w1]
    bset 0x742,#6

     
    Is this correct?
     
     
     
     
     
     
    #6
    balmerjd
    Super Member
    • Total Posts : 554
    • Reward points : 0
    • Joined: 2011/03/31 09:18:20
    • Location: Urbana, Ohio
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 10:49:42 (permalink)
    4 (1)
    cts_casemod
    I'm not sure if I have to do any modification on that library. The compiler complains about this line:

    what "library" are you talking about??
     
    cts_casemod
    Even the reference manual sows how to do the register lock/unlock in asm, but the actual port mapping is done in C, which hides what actually needs to be done in low level.

    That's because the port mapping is considered to be somewhat self explanatory. The register names match those names that you are already used to using, just sans the "bits" portion.  And the bit field designations have also been defined as a number according to their bit position in the registers so you can use them in the various bit instructions or as shift operators if you want to set multiple bits at a time using bit masks.   They also have numerous other uses as well based on what your particular application is.
     
    cts_casemod
    Say for example, i want to map SDI pin.
    According to the reference manual, this pin is set by using register RPINR20, bits 0...4, which i would set in accordance to the RPn pin to be mapped to that peripheral.

    I already gave you an example of how to set one of the registers you need and if you have any understanding of ASM you should be able to easily expand that to modify the other registers as well.  And in fact the example I gave you covers this EXACT scenario. MBedder also gave you a link to a post that contains an assembly include file that does all the mapping work for you and allows you to do it through the use of simple macros.
     
     
    But... That aside.
    cts_casemod
    So I would do:

    ; Mapp to RP pin input
      RPINR22bits.SDI2R = 0b01111; SDI2 uses RP15, device pin #26, RPINR22: PERIPHERAL PIN SELECT INPUT REGISTER 22
    ; Mapp to RP pin output
      RPOR7bits.RP14R = 0b01010; SDO2 uses RP14, device pin #25, RPOR14: PERIPHERAL PIN SELECT OUTPUT REGISTERS 14
      RPOR5bits.RP11R = 0b01011; // SCK2 uses RP11, device pin #22, RPOR11: PERIPHERAL PIN SELECT OUTPUT REGISTERS 11
      RPOR3bits.RP7R = 0b01100; // SS2 uses RP7, device pin #16, RPOR7: PERIPHERAL PIN SELECT OUTPUT REGISTERS 7

     
    Is this correct?

    No. This is dead wrong and presenting something like this makes me question how well you understand programming in assembly.  Structures and bit fields are a C construct do not exist in assembly so you can not use the FOObits.WHATEVER variables because they don't exist.  In fact you can't use '.' operator at all because it is not a member operator but a designator to mark the beginning of a pre-processor statement in the same way that # is the pre-processor designator for C.  All you have access to is the RPINR22, RPOR7, RPOR5, and RPOR3 registers as a whole or as a high and low byte.  You can access individual bits through the use of BSET, BCLR, BTG, and the bit test instructions, but even there you are still referencing the whole register and only setting changing or examining one bit at a time.
     
    PLEASE re-read my previous post and take a better look at the solution that MBedder offered as I believe that is probably a simpler option for you.
    #7
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 12:43:40 (permalink)
    3 (1)
    I missed your last post, I will try that now.
    The code provided by mbedder doesn't work for some reason.
     
    You seem to speak as if it were the most normal thing. I never worked with remappable peripherals before, I cant just guess the right syntax. Dont just assume everybody has a programming background and can make those assumptions with the flick of a finger. Most books don't cover this subject either.
     
    I now printed mbedder code to serve as a reference to find out the missing bits that I could not locate on the datasheet or reference manual for the 33F series. I now know that, for example, assigning 01111 or 15 to the SDI2R register selects the coffs pin, but I cant find any official microchip documentation regarding this. I also realized that the example I provided was for pins that my device didn't had, but I was surprised that they weren't covered on the reference manual that covers the dspic33 series.
     
    Is there any document I should have explaining the pin mapping? I feel like I am missing something and I just find it ridiculous that microchip provides a number of examples on how to set the SPI on a dspic33 and have chosen a device with no re-mappable pins to do so. 
     
     
    post edited by cts_casemod - 2014/12/05 12:49:36
    #8
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 13:57:09 (permalink)
    0
    One further question:
     
    Instead of doing a bitshift operation cant I write whatever I need and select the H or L portion of that register?
     
    Say for example: 
     
    mov #0b00110, W0
    mov W0, RPINR21L
     
    This would not change the top 8 bits would it? 
     
    Regards
    #9
    MBedder
    Circuit breaker
    • Total Posts : 6750
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 14:50:23 (permalink)
    4 (1)
    This would not change the top 8 bits would it?
    Wow, thus you should forget about doing anything as complex as PPS, and start learning the very basics of dsPIC architecture instead.
    #10
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 15:22:52 (permalink)
    0
    Well the code you provided, defines each register as L and H. I was a bit puzzled, because of the 16bit architecture, rather than 8, but was just assuming the compiler would interpret that and do a bit shift instruction. 
     
    Reading your reply perhaps not, which is not an issue.
     
    If I got the idea right I could make it as:
     
    ;Unlock I/O
     bclr SPI1STAT, #15; Disable the SPI module
     mov #0x742,w1
     mov #0x46,w2
     mov #0x57,w3
     mov.b w2,[w1]
     mov.b w3,[w1]
     bclr 0x742,#6
    ;

    ;Define Slave Select Input, ON RP6
     
    ;RPINR21 only has 5 lower bytes on the particular pic I am using, so no need to worry with the top 8 bits.
     mov #6, W0
     mov W0, RPINR21;

    ;Define SCK and SDI Inputs
    ;mov #0b---SCK1R---SDI1R
    ;Connect SCK to RP7 & SDI to RP8
     mov #0b0000011100001000, W0
     mov W0, RPINR20;


    ;Lock I/O
    mov #0x742,w1
    mov #0x46,w2
    mov #0x57,w3
    mov.b w2,[w1]
    mov.b w3,[w1]
    bset 0x742,#6
    bset SPI1STAT #15; Enable the SPI module
    ;

     
    Would this work?
    I did not define the SDO as I only plan to receive data via SPI, so once again *I'm* assuming the pin can be left unconnected.
    post edited by cts_casemod - 2014/12/05 15:59:17
    #11
    MBedder
    Circuit breaker
    • Total Posts : 6750
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 17:17:04 (permalink)
    4 (1)
    Would this work?
    No. RTFM.
    #12
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 17:23:01 (permalink)
    0
    Ok, then I have no idea what I am doing wrong.
     
    Back to question 1, can someone be kind enough to post the disassembly of the code on the first post?
    #13
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/05 17:51:56 (permalink)
    3 (1)
    I reviewed the code and I am still clueless about what is wrong, could you please clarify mbedder?

    On the first page C code I posted there was this example:

    RPIN22bits.SDI2R = 0b01111, which output was pin 15 or COFS for that particular pic. I don't have the coffs pin nor the RPIN22 register on the pic I am using, therefore I changed the registers for the SDI1 peripheral which is RPINR21 and I wrote the value 0000000000000110 = 6 to the SDI2R bits confirming I wanted to link this function to RP6. Which of these was done wrong?

    Regards
     
    EDIT:
    Just finished configuring the SPI and the code above works OK, so the pins are correctly mapped.
    Mbedder, apparently I've read the manual correctly not sure what you were referring to on last post.
     
    Thank you all for the advice.
    post edited by cts_casemod - 2014/12/06 15:38:17
    #14
    balmerjd
    Super Member
    • Total Posts : 554
    • Reward points : 0
    • Joined: 2011/03/31 09:18:20
    • Location: Urbana, Ohio
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/08 07:36:52 (permalink)
    4.5 (2)
    cts_casemod
    One further question:
    Instead of doing a bitshift operation cant I write whatever I need and select the H or L portion of that register?

    Yes you can do this, provided the bits in that half of the register have no other function, or you tailor the value you write to the register to account for those other bits.  This will NOT work for most other registers like those of a timer, UART, SPI, or ADC module.
     
    cts_casemod
    Say for example: 
    ov #0b00110, W0
    mov W0, RPINR21L
    This would not change the top 8 bits would it? 

    Uh... Yes that will change the top 8 bits because that is a 16 write.  Try doing that exact same code to RPINR21H and see what happens wink
    Both the PIC24 and the dsPIC33 series are capable of doing both 16 AND 8 bit operations.  To do the BYTE wide operations though you need to add a .B to the end of the address. So what you would want to do is thus:
    MOV     #0b00110,W0   ;<~~~ this is a 16-bit operation
     
    MOV.B   W0,RPINR21L    ;<~~~THIS is an 8-bit operation

     
    cts_casemod
    RPIN22bits.SDI2R = 0b01111, which output was pin 15 or COFS for that particular pic. I don't have the coffs pin nor the RPIN22 register on the pic I am using, therefore I changed the registers for the SDI1 peripheral which is RPINR21 and I wrote the value 0000000000000110 = 6 to the SDI2R bits confirming I wanted to link this function to RP6. Which of these was done wrong?
    EDIT:
    Just finished configuring the SPI and the code above works OK, so the pins are correctly mapped.
    Mbedder, apparently I've read the manual correctly

    No you haven't.  You are still doing a 16-bit write to that register meaning that you are not just setting SDI2R but also SCK2R.  Fortunately you are setting it to 0 though so you aren't inadvertently enabling another input somewhere.
     
    cts_casemod
    Well the code you provided, defines each register as L and H. I was a bit puzzled, because of the 16bit architecture, rather than 8, but was just assuming the compiler would interpret that and do a bit shift instruction. 

    ...... This is assembler.... The compiler assumes NOTHING for you. EVEREND OF STORY PERIOD DOT.  The compiler only does what you explicitly tell it to do.  This is not C. You do not have the support of premade functions.  You do not have the support of variable types.  You do not have the support of "built in functions".  You have bytes and words that can be signed or unsigned or even both wink because YOU have to tell the compiler whether they are singed or not by what instructions you use.  You have the hard ware modules and the instructions ops to move and manipulate data and THAT IS IT!


    cts_casemod
    I missed your last post, I will try that now.
    The code provided by mbedder doesn't work for some reason.
     
    You seem to speak as if it were the most normal thing. I never worked with remappable peripherals before, I cant just guess the right syntax. Dont just assume everybody has a programming background and can make those assumptions with the flick of a finger. Most books don't cover this subject either.

    General books may not cover this subject, but remappable peripheral are extremely common in low pin count high performance devices.  8-bit devices don't always have such things, but many 16-bit devices do.  A PPS system can take on many forms and not all look and operate exactly the same.  Move to Intel, Motorola, Harris, or any of the other micro manufacturers and you will see similar systems on their more advanced parts, but the structures will all be different with different registers, different configurations, and different rules of operation.  And I am not assuming that you can pick up the nuances of PPS just by looking at it, but since, as you say, you have a programming background I am assuming that you can read code and understand what it does.  From that you should be able to tell what a statement like RPINR22bits.SDI2R = 0b01111;  actually physically does.  Maybe not the exact mechanics of it, but you aught to be able to know what the end result of that statement is.  If not, then you really have no business getting into assembler until you do.  And the fact that you would ASSUME the compiler would do bit shifts or anything of the sort for you further tells me you do not have a grasp on assembly. C and ASM are not equal.  You can use ASM to create C but you cannot use C to create ASM.  In ASM you are directly dealing with the processor, its registers, its memory, its data bus, and the actual machine code that is running.   In the end all the ASM compiler is, is a glorified direct translator.  It takes the the statements you type in and using a look up table turns it in to binary op-codes.  It is a direct one to one translation.  C is not even close to a one to one translation.
     
     
    cts_casemod
    Is there any document I should have explaining the pin mapping? I feel like I am missing something and I just find it ridiculous that microchip provides a number of examples on how to set the SPI on a dspic33 and have chosen a device with no re-mappable pins to do so. 

    Yes.  There is plenty of documentation on all of this.
    Start here: 16-bit MCU and DSC Programmer's Reference Manual
    You only need the first 6 sections.  Section 7 (the last 350-400 pages) is all reference... Which you should make note of and keep handy so that you can easily look it up.  I actually have it saved to my desktop so I can quickly open it when I need to look something up.
    Then move on to here: Section 02. CPU - dsPIC33F FRM
    Then move on to this: Section 30. I/O Ports with Peripheral Pin Select (PPS) - dsPIC33F/PIC24H FRM
    Now keep in mind that this is all general information and is meant to apply to more than just your one specific processor.  So take all of the above information and cross-reference with the pin-out of your processor and the specific sections on I/O ports in this document: dsPIC33FJ12MC201/202 Data Sheet and you have everything you need.
    post edited by balmerjd - 2014/12/08 07:40:35
    #15
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/08 08:09:16 (permalink)
    0
    Thank you very much for the detailed write-up, balmerjd!
    #16
    balmerjd
    Super Member
    • Total Posts : 554
    • Reward points : 0
    • Joined: 2011/03/31 09:18:20
    • Location: Urbana, Ohio
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/08 10:22:16 (permalink)
    3 (1)
    Oh! One last note.  It's been a while since I looked over the PPS system's configuration settings but just did in trying to solve another problem.  I noticed that for the input side of the PPS system that setting the value to 0 actually sets the input to be connected to RP0. (my memory failed me here)  So from your earlier example if you do RPINR21 = 0b0000000000000110; you are actually not only setting SDI2R to be connected to RP6, but SCK2R to be connected to RP0.  To make sure that SCK2R is "unconnected" you would need to make all of its bits 1.  So to do it in a 16-bit operation you would use 0x0011111100000110.  Other wise you would just do an 8-bit write of 0b00000110 since the RPINR bits default to 1 at power on.
    #17
    cts_casemod
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2014/07/06 15:26:22
    • Location: 0
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/08 10:47:05 (permalink)
    3 (1)
    I think there is a confusion here.
     
     
     
    RPINR21 register on my chip only defines what pin the SS input is attached to. Am I missing something?
     
     

    Attached Image(s)

    #18
    balmerjd
    Super Member
    • Total Posts : 554
    • Reward points : 0
    • Joined: 2011/03/31 09:18:20
    • Location: Urbana, Ohio
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/08 12:04:08 (permalink)
    3 (1)
    I fat fingered a 21 instead of a 22...  That should have been RPINR22.
    #19
    balmerjd
    Super Member
    • Total Posts : 554
    • Reward points : 0
    • Joined: 2011/03/31 09:18:20
    • Location: Urbana, Ohio
    • Status: offline
    Re: DSPIC33F - Remappable pins 2014/12/08 12:49:06 (permalink)
    0
    I don't often do this, but you might find this helpful.  I have attached an include I wrote for handling setup on dsPIC33F hardware. (I changed the extension to .txt from .inc so I could attach it here.  You'll need to change it back.)  There is a good portion of it that you have to configure yourself, but it helps take a lot of the guess work out of setting individual bits in registers.  The only thing you need to make sure of is that you have FCY defined as the instruction frequency of your processor somewhere before you include this file in your code.  There are a couple of the defines that use that constant to calculate register options.  Also, this file is meant to be modified locally for each project that you use it in.  That is to say that you should have a master un-modified copy of this somewhere that you copy into each project you start and then modify that local copy with the options that you want for your project.  Not the best way to handle such things but it's what works for me.
     
    I'll give you a quick example of one of the defines that is there.  Say you want to setup Timer 1.  In the file, down in a block labeled Timers is this line:
        .equiv    T1CON_C,                    ((0 << TCS) + (0 << TSYNC) + (0b00 << TCKPS0) + (0 << TGATE) + (0 << TSIDL))


    Now lets say you want to set up the timer as being gated with a 64:1 prescaler.  You would change the line to this:
        .equiv    T1CON_C,                    ((0 << TCS) + (0 << TSYNC) + (0b11 << TCKPS0) + (1 << TGATE) + (0 << TSIDL))

     
    And then in your initialization code all you would have to do is:
    MOV    #T1CON_C,W0
    MOV    W0,T1CON
     
    And you're done.
     
    Now this isn't quite as handy if you are doing multiple hardware configurations that are constantly changing, but if you are doing a single setup something like this does tend to help.
     
    Also, if you read through it there are also PPS_OUT and PPS_IN macros that would let you do the same things you're looking at above.
    For example setting:
    RPINR21 = 0b0000000000000110;
    is the same as putting:
    PPS_IN I_SS1 I_RP6
    using the macros in the include I attached.
     
    Just make sure you read over the file before you use it so that you understand what is going on.
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5