Page 1 of 1

PIC 16F Chip Configuration

Posted: Thu Nov 11, 2021 10:36 pm
by ddllc
In Flowcode 9, some of the processor configuraton can be set in the Project Options/Configure menu (Oscillator, Watchdog, etc.) I see this creates two entries in the C code, e.g.

//Chip Configuration Settings
__PROG_CONFIG(0x1, 0x7DC);
__PROG_CONFIG(0x2, 0x1633);

I want to configure the ODCONC register of my 16F1786, which controls outputs in the C register to be open drain, specifically registers 0,1,2,3 and 7.

I would like advice on how to add a "C Code" insert into my Flow Code to accomplish this. The data sheet indicates this register is in Bank 5, 28Eh.

Thank you!

Re: PIC 16F Chip Configuration

Posted: Fri Nov 12, 2021 8:40 am
by medelec35
Hi, ddllc
Welcome to the Flowcode forums.
Perhaps the safest way to set bits of a register within a C code block:

Code: Select all

ODCONC |= 0b100000;
To clear bits:

Code: Select all

ODCONC = ODCONC & (~0b100000);
Doing it that way you won't interfere with the other bits that may already be set or cleared.
You don't have to use binary, I just find it conveient.
For example:

Code: Select all

ODCONC |= 0x5; //hex

Code: Select all

ODCONC |= 5; //decimal
etc
// is just to make a comment if not familure with C code.

Re: PIC 16F Chip Configuration

Posted: Fri Nov 12, 2021 6:20 pm
by ddllc
Seems easy. Thank you! I'll give it a go.

Re: PIC 16F Chip Configuration

Posted: Sat Nov 13, 2021 2:53 pm
by medelec35
nps I was going going to state you can could also set or clear indiviaul bits with:

Code: Select all

set_bit(ODCONC,ODC5);
st_bit(ODCONC,ODC5);
clear_bit(ODCONC,ODC5);
cr_bit(ODCONC,ODC5);
or

Code: Select all

set_bit(ODCONC,5);
st_bit(ODCONC,5);
clear_bit(ODCONC,5);
cr_bit(ODCONC,5);
However, as Microchip has not defined the ODCONC register for 16F1786 then you can't use that method.
It's something to remember for other target devices.