what is #pragma pic

Discussion in 'Embedded Systems and Microcontrollers' started by bug13, Nov 12, 2012.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Hi guys,

    I am new to PIC and I am coming from AVR, setting the registers in PIC is about the same as AVR for me, but there is one thing that I am totally lost.

    there are a few example code, they use something like:
    Code ( (Unknown Language)):
    1. #pragma config
    2. #pragma rom
    3. #pragma data
    4. #pragma .....
    I am guessing they are same as setting those individual bits in registers, but I don't know for sure and can't find much info about these on Google. Can someone point me to the right direction please?

    A tutorial or something is perfect.

    Thanks
     
  2. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    bug13 likes this.
  3. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    for who have the same question, details info can be found \Microchip\xc8\v1.10\docs\manual.pdf, and
    \Microchip\xc8\v1.10\docs\pic_chipinfo.html
     
  4. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    so #pragam config ... ... is same as setting the CONFIG register, what's the advantage of over setting CONFIG register in the C code anyway? any good reason except using #gragam config is a little easier?
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You should not bother with other #pragma settings than the #config settings in 99.9% of your programming. I like to use the header file for my current PIC as base. I cut out all the configuration setings from the header file. Then I paste it in to my code code. And just comment out the settings not needed or used
     
    bug13 likes this.
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,605
    #pragma is a well defined way to send some message to a C compiler saying "hey, I need you to do something specific to my hardware, something outside the bounds of normal C code, so let's just be pragmatic about this."

    There are many things you may need to tell your compiler, such as configuration settings, the address to start placing code, that the following routine in an interrupt handler, and so on. Things beyond normal C bounds.
     
    bug13 likes this.
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You may need to specify the RAM bank sometimes. It depends on the compiler, but C18 needs a pragma for that.
     
    bug13 likes this.
Loading...