Set 2 bits values

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Set 2 bits values

Post by Jan Lichtenbelt »

I want to set the 2bit parameter CDAFVR<1:0> of the register FVRCON. Is it possible sometime like:
fvrcon.CDAFVR=....

With kind regards

Jan Lichtenbelt

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Set 2 bits values

Post by Benj »

Hi Jan,

In XC8 you can do things like this.

FVRCONbits.CDAFVR = 3;

However in BoostC things are a little different.

I think the register bits are only defined as their bit position so you can do things like this.

set_bit(fvrcon, CDAVR0);
clear_bit(fvrcon, CDAVR1);

Not really what you were after but not too bad.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Set 2 bits values

Post by Jan Lichtenbelt »

I get a C-code error "Left operand must be l-value". What can be wrong?
test_comparator.fcfx
(15.26 KiB) Downloaded 581 times
Kind regards

Jan Lichtenbelt

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Set 2 bits values

Post by medelec35 »

Hi Jan
You have got:

Code: Select all

TRISA=TRISA|0x04;   // Set A2 as input
ANSELA= ANSELA | 0x04; // Set A2 as analog input
For boost C it should be:

Code: Select all

trisa=trisa|0x04;   // Set A2 as input
ansela= ansela | 0x04; // Set A2 as analog input
Registers are in lower case and bit names are in upper case.

Martin
Martin

Post Reply