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: 796
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
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: 14832
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
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: 796
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
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 378 times
Kind regards

Jan Lichtenbelt

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8870
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Post Reply