Maker Pro
Maker Pro

MPLAB very basic programming. Please help.

Electron_23

May 6, 2014
6
Joined
May 6, 2014
Messages
6
Hello everyone,

This questions is going to be a bit weird, but I really need some help in this aspect. I have been a couple days trying to find good tutorials but I really did not find any. My question is pretty simple and Im sure many of you will be able to give a good answer.
Could someone tell me what is the structure in every program? I mean, there is libraries, the "main" calls the libraries..that kind of stuff. I am also vey lost with regard to finding the proper libraries for my device. I am using a dsPIC33E. Where do I find what libraries I need and what are they called? Is there any manual from Microchip or something? I also do not understand many of the first declarations such as #pragma config , what is it? What do I need? I also don't where to find what oscillator to use, and where to find it or what code to use.

If you don't want to answer every question, some general tips will be really good.

As you saw, Im pretty lost so any help will be more than welcome.

Thank you very in advance.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
In a C program, execution starts at main(). main() generally calls other lower-level functions, which call other lower-level functions, and so on. Some of these functions may be in the standard C library.

Functions like sin(), printf(), malloc(), qsort() etc are part of the standard C library. You can call these functions and the linker (part of the compiler chain) will automatically include code from the relevant library. You should #include the appropriate header file (e.g. math.h, stdio.h, mem.h) in your code so the compiler can see the prototypes (basic definition of the function, including the data types it accepts as parameters and the data type it returns) as it's compiling your code.

You may also be able to add libraries for specific types of functions - for example, encryption/decryption or communication protocols, that aren't part of the standard C library. These may be available to buy, or free. The environment will probably include library functions to help with common embedded software requirements (e.g. initialise the USART for serial communication; enter sleep mode) that aren't part of standard C.

You haven't said which compiler you're using. The next answers relate to the Microchip XC8 C compiler, which is what I'm using. I think you're using a different Microchip compiler, so the filenames will be slightly different.

#pragma config is used by the Microchip XC8 compiler to specify configuration fuse settings for the device. These fuses determine settings like what type of oscillator the device will use (internal, external RC, external low-frequency crystal, external high-frequency crystal, ...), watchdog settings, peripheral connection (when a peripheral may be mapped to different pins), etc. The fuses are documented in the device data sheet, and the names of the text to use with #pragma config are documented in a separate file for each device; these files are linked from a file called pic18_chipinfo.html in the docs subdirectory below the compiler installation directory.

The main compiler reference is a big PDF file called MPLAB_XC8_C_Compiler_User_Guide.pdf and it's also located in the docs subdirectory below the compiler installation directory. It will have a slightly different name on your system. It's pretty well written. Use the Search function of the PDF reader to find out about words you don't understand.
 
Top