Help with a good book for pic microcontollers.

Discussion in 'Embedded Systems and Microcontrollers' started by johnnyinwa, Jul 14, 2013.

  1. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    Hey guys,
    I am looking for a good beginning book on c programming for pic microcontrollers. I am using the mplab x ide with the c18 free c compiler from microchip. I also have a programmer from futurlec that programs most 8 bit pic microcontollers. Anyway the software and the programmer work just fine but I need a book that teaches c using the c18 compiler. I purchased a book from amazon.com titled "Programming 8-bit Pic Microcontrollers in C" but it is written for the ccs c compiler. A book like the one I purchased but written for the c18 microchip compiler would be ideal. A free book off the web would be good too.
    Anyway I was hoping you guys could help me out. The chip I am using is a pic18f458 microcontroller. Thank you for your time and attention in this matter.

    Johnnyinwa.:confused:
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,367
    C is C. The syntax is the same regardless of which compiler you are using.
     
  3. WBahn

    Moderator

    Mar 31, 2012
    17,777
    4,805
    The main thing you probably need to learn, or at least have a reference for, are the function libraries. I would recommend going to the Microchip website and seeing what they have available. It almost certainly will be free.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    C may be C, but every compiler has it's own family of non-standard library functions, so I would stick with a book for my intended compiler.

    I just don't know of any books devoted to the C18 compiler offhand. Lucio Di Jasio has written an awesome book for the PIC32 but I don't see anything similar for the PIC18 (though he did one for PIC24).

    I didn't look for a book till I got to the 32's as I was neither starting in programming or micro controllers.
     
    Last edited: Jul 15, 2013
  5. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    Hey guys,
    I found the library write up for the xc8 microchip compiler on-line. What is really weird is that a lot of the compiler specific commands are not listed in the standard files. An example would be the commands needed to write to a port. The ccs c compiler uses 'output_A(255)' and the xc8 compiler uses 'portA=255'. Anyway I spent a lot of time trying to find the compiler specific keywords for the microchip xc8 c compiler and I can't find a list anywhere. My book 'Programming 8-bit pic microcontrollers in C' has a nice write up in the back for all the compiler keywords and library keywords for the ccs c compiler. My question is where can I find such a list for the xc8 microchip c compiler? I figure it has to be on-line somewhere -- any help you can give me would be greatly appreciated!

    Johnnyinwa.
     
  6. Ogu Reginald

    New Member

    Oct 13, 2011
    6
    0
    I am interested in the c book for pic microcontroller. I am using mikroc compiler.
     
  7. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    C18 libraries here
    XC8 libraries are described in the XC8 user's manual Appendix A.

    XC8 does not have specific IO functions that I know of. You use the various SFR names i.e.
    LATC=0x12;

    As the others have stated, each compiler handles hardware specifics and non C data types (e.g bits) differently.

    Standard C processing (math, data structures etc.) works pretty much the same across platforms with a few exceptions here and there.

    uCHIP has stated (in READMEs) that it might be better to keep a current project on whatever platform its on and use XC8 for new stuff, especially C18 projects. I have a large PICC-18 project that will not build on XC8 and I am told that it never will due to the RTOS structure. YMMV

    Have fun.
     
    absf likes this.
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You will find a manual in the folder "..\program install dir>\Microchip\xc8\v1.12\docs" Here you will find all you need. The XC8 compiler is quite true to the ansi C standard. So most ansi C book may help you a lot. Another important thing to do. Is to get known with with the specific header filer for your PIC. In your case it will be the pic18f458.h file in the "\include" folder.
    You are also free to (ab)use this forum for help to get started
    Some Ansi C books I have used. Not saying that these will work for you though.
    http://www.amazon.com/C-Programming-Language-2nd-Edition/dp/0131103628
    http://www.amazon.com/Beginning-Nov...words=beginning+c+from+novice+to+professional
     
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Most of what is happening here is standard C function are contained in layer upon layer of macro functions that make the top level code (the stuff you write) easier to read, follow, and understand.

    Would you rather see:
    Code ( (Unknown Language)):
    1.    PortA = 255;
    or this?
    Code ( (Unknown Language)):
    1.    char *port_A = 0xF80;
    2.     ....
    3.     *port_A = 0; @ 0xF80 = 255;
    There can always be too much of a good thing. In the "good old days" you were required to add a header specific to the PIC you were using. In these modern times (since about 2010) there has been a change to using a generic header file for the compiler, and using the processor symbol letting that file conditionally compile and pick the proper header for you.

    That's a lot of words to mean you may never get to see the header specific to your PIC device, and guess what? It has all those specific keywords noted.

    If you wander down to the folder C:\Program Files (x86)\Microchip\xc8\v1.20\include and look for pic18f458.h you will find lots of goodies in there.

    I'll often include the processor header into my project so I can refer to it fast when I feel the need.
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,367
    Good point. The op has to understand what is standard C and what is not.
    The stuff that is hidden in the header files and libraries is standard C. How you call them is not standard C.

    For example, in my MSP430 blog I use a statement such as:

    Code ( (Unknown Language)):
    1.  
    2.    LED1 = ON;
    3.  
    This is not standard C.

    The declarations:

    Code ( (Unknown Language)):
    1.  
    2. #define LED1 P1OUT_bit.P0
    3. #define ON 1
    4.  
    The first statement is valid only after the structure P1OUT_bit and element P0 are defined in the header.

    The second statement is a valid C statement.

    Conclusion: it doesn't matter which C compiler you use. It is the header files and libraries that make the difference.

    You can choose not to use the headers and libraries and create your own.
     
  11. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    Heh guys,
    After much time spent surfing the web I found a web page that does a good job explaining c for pic microcontrollers using xc8. The name of the site is "mybookez". Type in "programming pic microcontrollers in c with xc8" on the search line and a whole bunch of files are displayed. Using the site is completely free. All levels of learning for the student are addressed.
     
  12. panic mode

    Senior Member

    Oct 10, 2011
    1,321
    304
Loading...