Thread: Creation of a GPIO header file

  1. #1
    Registered User
    Join Date
    Jul 2021
    Posts
    20

    Creation of a GPIO header file

    Hi.

    I am giving something some thought.

    I would like to create a header file that will contain all of the information regarding each pin.

    Code:
    //example
    ANSELAbits.ANS1 = 0;      //set to digital
    TRISAbits.TRISA1 = 0;      //set as output
    #define LED1 PORTAbits.RA1  //define pin name
    I want to do the above for each pin (a 100 pin PIC32) so that they are easier to manage in one place.

    I know that i can add #define within the .h file. But im not so sure about the setting of the registers.

    Is there a "best practice" for this type of thing?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,714
    The assignments would have to go into a source file.

    Perhaps as a series of static functions to initialise each feature separately, which in turn are called by a single initHardware() type function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2021
    Posts
    20
    Quote Originally Posted by Salem View Post
    The assignments would have to go into a source file.

    Perhaps as a series of static functions to initialise each feature separately, which in turn are called by a single initHardware() type function.
    Thanks Salem,

    I had to go read up on what a static function was...newby problems... But i get the method you are describing.

    This should achieve what i want it to and make it easier for me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Preventing Creation Of Precompiled Header Files
    By Dren in forum C Programming
    Replies: 3
    Last Post: 11-10-2018, 11:46 PM
  2. Beginner GPIO Question
    By stumpyhuck29 in forum C Programming
    Replies: 3
    Last Post: 02-03-2014, 09:09 PM
  3. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  4. Replies: 4
    Last Post: 12-14-2005, 02:21 PM
  5. Header file creation problem
    By ToxicLove in forum C Programming
    Replies: 2
    Last Post: 05-17-2004, 10:25 PM

Tags for this Thread