PIC 16F Chip Configuration

For general Flowcode discussion that does not belong in the other sections.
Post Reply
ddllc
Posts: 3
http://meble-kuchenne.info.pl
Joined: Wed Apr 07, 2021 12:22 am
Location: Southern California
Has thanked: 1 time
Contact:

PIC 16F Chip Configuration

Post 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!

medelec35
Matrix Staff
Posts: 1449
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 509 times
Been thanked: 471 times

Re: PIC 16F Chip Configuration

Post 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.
Martin

ddllc
Posts: 3
Joined: Wed Apr 07, 2021 12:22 am
Location: Southern California
Has thanked: 1 time
Contact:

Re: PIC 16F Chip Configuration

Post by ddllc »

Seems easy. Thank you! I'll give it a go.

medelec35
Matrix Staff
Posts: 1449
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 509 times
Been thanked: 471 times

Re: PIC 16F Chip Configuration

Post 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.
Martin

Post Reply