1. bilal sheikh

    Thread Starter New Member

    Jan 21, 2015
    22
    0
    any one here who have used PIC C (ccs pic c compiler pcwdh) for pic programming ?
    i want to access SFR registers like PR2 and TMR2 but dont know how to access these. kindly help :)
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,789
    Normally you would have an "include" file with an extension of ".h" containing the definitions of all of the file registers. These definitions would look like"

    #define TMR2 0x87

    for example. There should be an include file for each PIC variant supported by the compiler. If you can locate such a file and include it with your source code you can write statements like

    TMR2 = 0x9C ;
     
    bilal sheikh likes this.
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I believe you meant to make that a define statement. As written it is a simple assignment where the lvalue may not be determined.
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,789
    No I meant it the way it was written. What I did not specify was the content of the include file which would have a definition which allowed the string TMR2 to resolve into an lvalue. I just don't have a handy example at the moment.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    The #define example you wrote is pretty close, though typically all working registers are defined as "volatile".

    Just let it lie there least we start another useless thread concerning the necessity of that keyword. ;)
     
  6. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Only true Alchemists download MPLABX and use project templates.
    You actually dont need to do a thing, and get all the files created.
     
  7. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,789
    OK, I went and found an actual header file for a PIC
    Code (Text):
    1.  
    2. ...
    3. #define TMR2_ADDR 0x0011
    4. ...
    5. extern __sfr __at (TMR2_ADDR) TMR2;
    6.  
    It was the second line in the example above that I could not remember the form of. Of course __sfr and __at have compiler specific meanings as you might expect.
    The file is located at:
    http://ee.hawaii.edu/~sasaki/EE361/Fall12/Lab/pic16f628.txt
     
  8. bilal sheikh

    Thread Starter New Member

    Jan 21, 2015
    22
    0
    thank u all for ur valuable suggestions, the problem was resolved. we can generate a file for all PIC varients that contains defination of all SFR's and can access all SFR's. Screenshot (40).png
     
Loading...