Getting Started

Discussion in 'Embedded Systems and Microcontrollers' started by MCodeR, Apr 2, 2014.

  1. MCodeR

    Thread Starter New Member

    Apr 2, 2014
    4
    0
    Hi all,

    I have a general question about getting started with a microcontroller. When starting with a new microcontroller and IDE, how do you know which header files to include. I've done it before in an embedded systems class, but in there we were handed a template that already included the header. If i'm starting a brand new project on a brand new platform by myself, how do I know what header to include?

    Thanks,
    Mike
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    Depends on which MCU and which IDE.

    The IDE I use (IAR Embedded Workbench) adds the include files in the template.
     
  3. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    I would start by locating the include file directory for your toolchain. You can go about this sytematically by looking for the toolchain folder in "Program Files" or "Program Files (x86)". You can also search the entire hard drive for "*.h" or "*.inc". It should not take long to narrow things down. In Microchiplandia the name of the processor is also a part of the header file name.
     
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    If using Microchip and downloading the free lab s/w, it includes templates for ABS and REL file examples for each IC number, as well as .INC file for declared locations and labels.
    Max.
     
  5. MCodeR

    Thread Starter New Member

    Apr 2, 2014
    4
    0
    Thanks for the replies so far. So from what it seems like so far, typically the IDE will start you off with a template that has the correct header file(s) included? Is this at least part of the reason for using the "New Project Wizard"? So that the IDE can select the appropriate header and place it in the template it starts you off with?

    If for some reason, the IDE I'm using does not provide a template, is the other alternative to search for the location of all of the header files and select the one which will hopefully have the MCU model in the file name?

    The purpose of my question is to find the reasoning behind selecting a particular header file. Is it specific to the MCU? One header file for a particular MCU will work on multiple IDEs?

    Thanks again for all your help,
    Mike
     
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    What series IC's are you using?
    If you are talking about the MPLAB New Project Wizard, you have to point it to the correct directory.
    I usually make up a Picmicro dir with all my projects and a dir for each of the templates, manuals and INC files, as I implement them.
    This way the originals do not get overridden.
    Max
     
  7. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    There is so much specialization in the microcontroller space that it is almost a one to one correspondence between chips and header files. Each toolchain has header files that are compatible with the compilers and assemblers in that tools chain and have been vetted by the developer of the toolchain. Bugs do happen so one must not be too trusting until experience suggests that problems with a header file are unlikely.

    One particularly thorny example is the syntax for a bit within a register. The C standard does not address this critical feature of embedded controllers, but the compiler writers have gone ahead and implemented something that is rational. The problem comes about if you want to port your stuff to another compiler or IDE with incompatible syntax and semantics.
     
  8. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,387
    497
    I have worked with one Arduino board. I followed the IDE tutorial and tutorial examples that showed how to program various features.

    For example, the IDE tutorial showed how to configure IDE for my specific Arduino board. Which, I assume, setup the programming environment so that I did not have to.
     
  9. MCodeR

    Thread Starter New Member

    Apr 2, 2014
    4
    0
    I don't have a specific MCU I'm trying to work with right now. I'm just asking in a general sense. I'm an EE and took the required COMPE classes in school, but those all had us start with templates. Now that I'm out of school I want to do some sort of home project. I want to pick a platform that I didn't use in school, but have no idea how to start from scratch.

    I don't want to blindly pick a header because that's what the template says to use or because "it just works." I'm trying to get a sense of the "why" of it all, if that makes sense.

    Thanks for all the replies. This is really helping me gain some insight into this. Keep them coming!

    Thanks,
    Mike
     
  10. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
  11. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    The anal retentive method would be to get a datasheet and a candidate header file and do a line by line comparison for accuracy. The result should be each line in the header file corresponds to a documented hardware feature in the datasheet AND each hardware feature in the datasheet corresponds to a line in the header file. In this way you can be sure the header file contains a reference for each feature you might use AND it contains no references to unimplemented features. I've found bugs in header files by doing exactly this.

    Alternatively you can build your own header file and use only those features you're interested in. You have to be sure you know what you are doing for this to work.
     
  12. MCodeR

    Thread Starter New Member

    Apr 2, 2014
    4
    0
    The language I'm most familiar with is C.

    I'm not sure I'm quite ready to build my own header file yet haha.

    Thanks,
    Mike
     
Loading...