1
\$\begingroup\$

I am new to PIC programming, and I am trying to blink an LED using the PIC10F206. It has 4 I/O pins. I understand I must declare them as inputs or outputs, but the IDE I am using (MPLAB) keeps giving me an error when I declare the TRIS register. Attached is a picture.

My Code with error indicator

The datasheet lists the TRIS GPIO register as having the name "TRISGPIO" but the compiler throws this error: "Unable to resolve identifier TRISGPIO".

Am I just getting the name of the TRIS register wrong? Attached is a picture of the TRIS GPIO register from the datasheet. enter image description here

[EDIT]

Looks like it is a header file problem. When I highlight "xc.h", right click, and go to navigate -> go to definition, the xc.h file is pulled up but the code does not recognize my pic.h file which is where the header file for my chip is. See imagae for the xc.h screenshot. enter image description here

I tried pointing to the directory in the compiler options but no luck. Any thoughts? Below is a picture of my compiler options

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. Any conclusions reached should be edited back into the question and/or any answer(s). \$\endgroup\$
    – Dave Tweed
    Commented Nov 6, 2019 at 14:41

4 Answers 4

5
\$\begingroup\$

You are using a baseline PIC, so you can refer to the XC8 compiler User's Guide section 5.3.10:

5.3.10 Baseline PIC MCU Special Instructions The Baseline devices have some registers which are not in the normal SFR space and cannot be accessed using an ordinary file instruction. These are the OPTION and TRIS registers. Both registers are write-only and cannot be used in expression that read their value. They can only be accessed using special instructions which the compiler will use automatically. The definition of the variables that map to these registers make use of the control qualifier. This qualifier informs the compiler that the registers are outside of the normal address space and that a different access method is required. You should not use this qualifiers for any other registers

When you write to either of these SFR variables, the compiler will use the appropriate instruction to load the value. So, for example, to load the TRIS register, the following code: TRIS = 0xFF;

You will find the following definition in the relevant .h file for this chip:

// Register: TRISGPIO
#define TRISGPIO TRISGPIO
extern volatile __control unsigned char TRISGPIO            __at(0x006);

Which indeed contains the aforementioned __control qualifier. However it also defines TRISGPIO! And I tried a simple program and it does work if xc.h (which loads PIC10F206.h) is included, for either TRIS or TRISGPIO (MPLAB-X , XC8 V2.10).

You also have error markers beside your GPIO names, which implies your .h file is not being properly included or is missing something.

Edit: As @brhans mentions, make sure you've properly configured MPLAB-X for that exact chip. Your tree should look something like this:

enter image description here

If it's not properly configured it may be including the wrong file or nothing, I can't say as I've run into that issue myself.

\$\endgroup\$
10
  • 1
    \$\begingroup\$ Appreciate the addition here. (I only use assembly with the PIC10 family.) \$\endgroup\$
    – jonk
    Commented Nov 6, 2019 at 2:25
  • \$\begingroup\$ @Sphero So the error will remain in the IDE but the assembler knows what do when it comes time to burning the program? I haven't tried this on an actual Pic10 yet, just using the simulator..... as for the header file missing something, I only have the three configuration bits declared (watchdog, code protect, and MCLRE) as well as including the xc.h file so not sure what it could be missing. \$\endgroup\$
    – Sal M
    Commented Nov 6, 2019 at 2:47
  • 1
    \$\begingroup\$ You're using a compiler, not an assembler and it seems to be choking on the program. Check your PIC10F206.h file, which should be in the compiler folder. \$\endgroup\$ Commented Nov 6, 2019 at 2:49
  • \$\begingroup\$ @SpehroPefhany Finally found the header file. What should I be looking for though? The TRISGPIO definition looks correct with the whole __control thing \$\endgroup\$
    – Sal M
    Commented Nov 6, 2019 at 3:17
  • 1
    \$\begingroup\$ @SalM I can't tell if all those .. things get you to the right place. But you are doing the right thing in looking into these tabs. Have you also just tried to specify the absolute directory and filename in the include line? That should override things. You can also copy the include file into the same directory add the source itself and use quotes, not angle brackets, and see if that works. \$\endgroup\$
    – jonk
    Commented Nov 6, 2019 at 16:18
1
\$\begingroup\$

Try putting a space between the "TRIS" and the "GPIO" when declaring it.

TRIS is an instruction that expects a register name (address) as its argument. GPIO is a valid register name for small (8-pin PICs).

[Edit}

I've just re-read the question. I'm not competent in C but I can tell you what the instruction is supposed to look like in assembler:

movlw  0x00
TRIS   GPIO

This may help you get where you need to be.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ TRIS takes 'f', which I think can be either 6 or 7 in the small devices. (GPIO will probably translate to "6" if examined, my guess.) The question is if the C compiler actually accepts "TRIS GPIO" (which I doubt.) If not, the C compiler vendor has to provide some means, which may or may not be common across various C compilers. The OP is obviously using C. \$\endgroup\$
    – jonk
    Commented Nov 6, 2019 at 0:42
0
\$\begingroup\$

You can create a set_tris() in ASM just after last #include of your source file, and calling later from your code in main().

int set_tris(void){
    #asm
          movlw     0x00 //value to load
          tris      0x06 //value of GPIO register
    #endasm
            ;
                return 0;
}
\$\endgroup\$
0
\$\begingroup\$

So turns out it was a problem with #include For some reason MPLAB couldn't figure out the following code in the xc.h file

enter image description here

I navigated to the specific header file containing my PIC's declarations, and included it manually into the main source file. Works now.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.