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

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

Set 2 bits values

Postby Jan Lichtenbelt » Wed Nov 11, 2015 1:48 pm

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: 14217
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4356 times
Been thanked: 4095 times
Contact:

Re: Set 2 bits values

Postby Benj » Wed Nov 11, 2015 4:44 pm

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.
These users thanked the author Benj for the post:
Jan Lichtenbelt (Thu Nov 12, 2015 9:34 am)
Rating: 5.26%
 

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

Re: Set 2 bits values

Postby Jan Lichtenbelt » Wed Nov 11, 2015 7:21 pm

I get a C-code error "Left operand must be l-value". What can be wrong?

test_comparator.fcfx
(15.27 KiB) Downloaded 327 times


Kind regards

Jan Lichtenbelt
These users thanked the author Jan Lichtenbelt for the post:
skquah (Fri Jul 29, 2016 5:24 am)
Rating: 5.26%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8376
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3412 times
Contact:

Re: Set 2 bits values

Postby medelec35 » Wed Nov 11, 2015 9:54 pm

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
These users thanked the author medelec35 for the post (total 2):
Jan Lichtenbelt (Thu Nov 12, 2015 9:34 am) • skquah (Fri Jul 29, 2016 5:23 am)
Rating: 10.53%
 
Martin

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