# Error "option" on C compiler

#### Dodgydave

Joined Jun 22, 2012
10,305
Hi guys , i'm new to this C programming malarky.

i get
{ 46.1 undefined identifier "OPTION" } when compiling a sample programme using the Hi-tec C compiler for a pic16f84,, I assume it doesn't know what the world OPTION means,,,any ideas why it's doing this??

this is the sample programme.
PS i dont know how to use code blocks?

C:
#include    <htc.h>

/*
*    Example code for using timer0 on a 16F84
*    Just sets up a 1 second interrupt and increments a variable
*/

/*
*    Calculate preload value for one second timer
*/

#define    PERIOD    1000000        // period in uS - one second here
#define    XTAL    4000000        // crystal frequency - 4MHz

#define IPERIOD    (4 * 1000000 / XTAL)    // Period of instruction clock in uSeconds

#define    SCALE    256        // Timer 0 prescaler
#define T0_TICKS 256    // Number of counts for interrupt

#define TICK_PERIOD (SCALE * IPERIOD)    // Period (uSec) of one increment of timer 0

unsigned long    seconds;    // second count

/* service routine for timer 0 interrupt */
void interrupt
timer0_isr(void)
{
// effect a change on PORTB whenever our desired period is reached.
// Note this timing will contain a margin of error.
seconds++;
PORTB++;    // effect a change on PORTB
}
T0IF = 0;
}

main()
{
// initialize timer 0;

OPTION = 0b0111;    // prescale by 256
T0CS = 0;            // select internal clock
T0IE = 1;            // enable timer interrupt
GIE = 1;            // enable global interrupts
TRISB = 0;            // output changes on LED

for(;
continue;        // let interrupt do its job
}

Last edited:

#### Papabravo

Joined Feb 24, 2006
18,417
Malarky implies you'd rather not be messing with it I guess. Your choice, so never mind.

OPTION is the name of a register. Where that register is actually located and how many bits it contains for a particular PIC architecture is not necessarily well defined in general. A machine with a Harvard architecture like the PIC family has multiple memory spaces what such a thing might live. A set of definitions would normally be included in a common header file like "htc.h". It is the same error that you would get for any undefined identifier. If the code was originally written for a different compiler, that could be the root of the problem. Different compilers means different assumptions about what is known and what is undefined.

Check the datasheet for the PIC 16F84 (obsolete) to determine what it might be referring to. That may give you some clues as to how to write an expression that will assign a value to the appropriate place.

Check PIC specific programming forums for additional information.

Last edited:

#### AlbertHall

Joined Jun 4, 2014
12,022
Try OPTION_REG

#### Dodgydave

Joined Jun 22, 2012
10,305
Try OPTION_REG

Bingo !

Yes it's worked now, obviously someone wrote it wrong.

#### AlbertHall

Joined Jun 4, 2014
12,022
Yes, I don't know why but in code the OPTION register is always called OPTION_REG.

#### JohnInTX

Joined Jun 26, 2012
4,667
Yes, I don't know why but in code the OPTION register is always called OPTION_REG.
I would guess it's to avoid confusion with the OPTION instruction in baseline and some smaller midrange stuff. The OPTION register is not mapped in the SFRs in those PICs so it used a dedicated instruction.

#### Papabravo

Joined Feb 24, 2006
18,417
I would guess it's to avoid confusion with the OPTION instruction in baseline and some smaller midrange stuff. The OPTION register is not mapped in the SFRs in those PICs so it used a dedicated instruction.
I think you nailed it.

#### Dodgydave

Joined Jun 22, 2012
10,305
Malarky implies you'd rather not be messing with it I guess. Your choice, so never mind.

OPTION is the name of a register. Where that register is actually located and how many bits it contains for a particular PIC architecture is not necessarily well defined in general. A machine with a Harvard architecture like the PIC family has multiple memory spaces what such a thing might live. A set of definitions would normally be included in a common header file like "htc.h". It is the same error that you would get for any undefined identifier. If the code was originally written for a different compiler, that could be the root of the problem. Different compilers means different assumptions about what is known and what is undefined.

Check the datasheet for the PIC 16F84 (obsolete) to determine what it might be referring to. That may give you some clues as to how to write an expression that will assign a value to the appropriate place.

Check PIC specific programming forums for additional information.
The sample is from the Hi-tech compiler files from Mplab, I am trying to learn C on my own from books , I'm so used to using ASM , and I find it hard with C when there is no one to help you.

#### Papabravo

Joined Feb 24, 2006
18,417
The sample is from the Hi-tech compiler files from Mplab, I am trying to learn C on my own from books , I'm so used to using ASM , and I find it hard with C when there is no one to help you.
That seems to imply that there are some variants of the PIC architecture that would allow the syntax used in the example file. If I were to venture a guess, they would be the more recent ones rather than the obsolete ones. You don't seem to be having any more or less difficulty than others that have traveled this road. Turns out there are a few of us here that can and will try to help.