• AVR Freaks

Hot!Pin Manager LAT defines

Author
seyyah
Super Member
  • Total Posts : 633
  • Reward points : 0
  • Joined: 2004/05/14 12:49:28
  • Status: offline
2020/03/27 07:36:21 (permalink)
0

Pin Manager LAT defines

I think there were lat defines in some previous versions in pin_manager.h file something like
#define Button_LAT           (_LATC7)
 
but I could not see it in the latest version.  Some times it is required for expressions like
Button_LAT = (somevalue & 0x0010) >> 4;
 
but I only see
 
#define Button_Toggle()           (_LATC7 ^= 1)
#define Button_SetHigh()           (_LATC7 = 1)
#define Button_SetLow()           (_LATC7 = 0)
 
which are not always efficient to use. So I think that define should be added to mcc produced file. You cannot know when it will be required...
#1

6 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3688
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Pin Manager LAT defines 2020/03/27 08:27:04 (permalink)
    0
    If at all, I'd prefer some Button_SET() or Button_VAL.
    But you're always free to add your own #defines.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    OscarTheGrouch
    Super Member
    • Total Posts : 337
    • Reward points : 0
    • Joined: 2010/11/29 18:07:28
    • Location: 0
    • Status: offline
    Re: Pin Manager LAT defines 2020/03/27 11:41:00 (permalink)
    0
    I think you get those if you use MCC and give the pins custom names in pin manager.
    I prefer to define them in my project source code and just let MCC use default names.
    OtG
    #3
    davekw7x
    Entropy++
    • Total Posts : 1870
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: Pin Manager LAT defines 2020/03/27 16:16:24 (permalink)
    0
    seyyah
    I think...previous versions ..latest version.
    So I think...



    I haven't seen the problems you are facing.
     
    If you had told us what version of the MCC plugin you are using, and even what device you are using, maybe someone could help get to the bottom of things.
     
    I am using MPLABX version 5.35, and I installed the MCC plugin from within the IDE (MCC plugin version 3.95.0).  There are instructions on the Microchip MCC page for installing this (latest) plugin with older versions of MPLABX, but I haven't tried that.
     
    Anyhow...
     
    I find that for every pin shown in the MCC Pin Module window there is a complete set of macros (including definitions for xxx_LAT).  See attachments.
     
    For example, for the PIC18F47K42 project that I am currently working on, pin_manager.h is full of stuff like
    // get/set LED1 aliases
    #define LED1_TRIS                 TRISAbits.TRISA4
    #define LED1_LAT                  LATAbits.LATA4
    #define LED1_PORT                 PORTAbits.RA4
    #define LED1_WPU                  WPUAbits.WPUA4
    #define LED1_OD                   ODCONAbits.ODCA4
    #define LED1_ANS                  ANSELAbits.ANSELA4
    #define LED1_SetHigh()            do { LATAbits.LATA4 = 1; } while(0)
    #define LED1_SetLow()             do { LATAbits.LATA4 = 0; } while(0)
    #define LED1_Toggle()             do { LATAbits.LATA4 = ~LATAbits.LATA4; } while(0)
    #define LED1_GetValue()           PORTAbits.RA4
    #define LED1_SetDigitalInput()    do { TRISAbits.TRISA4 = 1; } while(0)
    #define LED1_SetDigitalOutput()   do { TRISAbits.TRISA4 = 0; } while(0)
    #define LED1_SetPullup()          do { WPUAbits.WPUA4 = 1; } while(0)
    #define LED1_ResetPullup()        do { WPUAbits.WPUA4 = 0; } while(0)
    #define LED1_SetPushPull()        do { ODCONAbits.ODCA4 = 0; } while(0)
    #define LED1_SetOpenDrain()       do { ODCONAbits.ODCA4 = 1; } while(0)
    #define LED1_SetAnalogMode()      do { ANSELAbits.ANSELA4 = 1; } while(0)
    #define LED1_SetDigitalMode()     do { ANSELAbits.ANSELA4 = 0; } while(0)
    ... and similar for other assigned pins ...

    Same for other PIC16 and PIC18 projects that I have recently explored.
     
    Regards,
     
    Dave
     
     
    post edited by davekw7x - 2020/03/27 16:23:01

    Attached Image(s)

    #4
    seyyah
    Super Member
    • Total Posts : 633
    • Reward points : 0
    • Joined: 2004/05/14 12:49:28
    • Status: offline
    Re: Pin Manager LAT defines 2020/03/28 08:09:54 (permalink)
    0
    davekw7x
    seyyah
    I think...previous versions ..latest version.
    So I think...



    I haven't seen the problems you are facing.



     
    Hmm It may depend on the mcu then. My current project is based on dspic33e. By the way Mplabx version is 5.30
    post edited by seyyah - 2020/03/28 08:18:16
    #5
    seyyah
    Super Member
    • Total Posts : 633
    • Reward points : 0
    • Joined: 2004/05/14 12:49:28
    • Status: offline
    Re: Pin Manager LAT defines 2020/03/28 08:16:00 (permalink)
    0
    dhpalmer
    I think you get those if you use MCC and give the pins custom names in pin manager.
    I prefer to define them in my project source code and just let MCC use default names.
    OtG


    Yes, because the idea is to make minimum change when you move from one project to another or from one version of the project to the other version and track pin changes from mcc (or from a single point). It is not a big deal but I would prefer them to be defined automatically.
    #6
    David Lago
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2020/05/05 15:57:00
    • Location: Spain
    • Status: offline
    Re: Pin Manager LAT defines 2020/05/06 01:42:55 (permalink)
    0
    I am seeing the same "problem" as seyyah.
     
    Below two examples of "pin_manager.h" code generated from the MCC, one using XC8 2.05 and other with XC16 1.5.
    In both cases I am working from MPLABX 5.2 (MCC 3.95.0). 
     
    XC8 2.05 (PIC16F15345)
    // get/set Potentiometer aliases
    #define Potentiometer_TRIS TRISAbits.TRISA2
    #define Potentiometer_LAT LATAbits.LATA2
    #define Potentiometer_PORT PORTAbits.RA2
    #define Potentiometer_WPU WPUAbits.WPUA2
    #define Potentiometer_OD ODCONAbits.ODCA2
    #define Potentiometer_ANS ANSELAbits.ANSA2
    #define Potentiometer_SetHigh() do { LATAbits.LATA2 = 1; } while(0)
    #define Potentiometer_SetLow() do { LATAbits.LATA2 = 0; } while(0)
    #define Potentiometer_Toggle() do { LATAbits.LATA2 = ~LATAbits.LATA2; } while(0)
    #define Potentiometer_GetValue() PORTAbits.RA2
    #define Potentiometer_SetDigitalInput() do { TRISAbits.TRISA2 = 1; } while(0)
    #define Potentiometer_SetDigitalOutput() do { TRISAbits.TRISA2 = 0; } while(0)
    #define Potentiometer_SetPullup() do { WPUAbits.WPUA2 = 1; } while(0)
    #define Potentiometer_ResetPullup() do { WPUAbits.WPUA2 = 0; } while(0)
    #define Potentiometer_SetPushPull() do { ODCONAbits.ODCA2 = 0; } while(0)
    #define Potentiometer_SetOpenDrain() do { ODCONAbits.ODCA2 = 1; } while(0)
    #define Potentiometer_SetAnalogMode() do { ANSELAbits.ANSA2 = 1; } while(0)
    #define Potentiometer_SetDigitalMode() do { ANSELAbits.ANSA2 = 0; } while(0)

     
    XC16 1.5 (dsPIC33EV256GM002)
    /**
      @Summary
        Sets the GPIO pin, RB5, high using LATB5.

      @Description
        Sets the GPIO pin, RB5, high using LATB5.

      @Preconditions
        The RB5 must be set to an output.

      @Returns
        None.

      @Param
        None.

      @Example
        <code>
        // Set RB5 high (1)
        Potentiometer_SetHigh();
        </code>

    */
    #define Potentiometer_SetHigh() (_LATB5 = 1)
    /**
      @Summary
        Sets the GPIO pin, RB5, low using LATB5.

      @Description
        Sets the GPIO pin, RB5, low using LATB5.

      @Preconditions
        The RB5 must be set to an output.

      @Returns
        None.

      @Param
        None.

      @Example
        <code>
        // Set RB5 low (0)
        Potentiometer_SetLow();
        </code>

    */
    #define Potentiometer_SetLow() (_LATB5 = 0)
    /**
      @Summary
        Toggles the GPIO pin, RB5, using LATB5.

      @Description
        Toggles the GPIO pin, RB5, using LATB5.

      @Preconditions
        The RB5 must be set to an output.

      @Returns
        None.

      @Param
        None.

      @Example
        <code>
        // Toggle RB5
        Potentiometer_Toggle();
        </code>

    */
    #define Potentiometer_Toggle() (_LATB5 ^= 1)
    /**
      @Summary
        Reads the value of the GPIO pin, RB5.

      @Description
        Reads the value of the GPIO pin, RB5.

      @Preconditions
        None.

      @Returns
        None.

      @Param
        None.

      @Example
        <code>
        uint16_t portValue;

        // Read RB5
        postValue = Potentiometer_GetValue();
        </code>

    */
    #define Potentiometer_GetValue() _RB5
    /**
      @Summary
        Configures the GPIO pin, RB5, as an input.

      @Description
        Configures the GPIO pin, RB5, as an input.

      @Preconditions
        None.

      @Returns
        None.

      @Param
        None.

      @Example
        <code>
        // Sets the RB5 as an input
        Potentiometer_SetDigitalInput();
        </code>

    */
    #define Potentiometer_SetDigitalInput() (_TRISB5 = 1)
    /**
      @Summary
        Configures the GPIO pin, RB5, as an output.

      @Description
        Configures the GPIO pin, RB5, as an output.

      @Preconditions
        None.

      @Returns
        None.

      @Param
        None.

      @Example
        <code>
        // Sets the RB5 as an output
        Potentiometer_SetDigitalOutput();
        </code>

    */
    #define Potentiometer_SetDigitalOutput() (_TRISB5 = 0)

     
    Thank you
    David
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5