CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

bit manipulation

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Marc
Guest







bit manipulation
PostPosted: Fri Jun 29, 2007 8:50 am     Reply with quote

I have 3 registry bits:
ADCONbits.CHS2=1
ADCONbits.CHS1=0
ADCONbits.CHS0=0

How can I define something which contains them so that I can write
CHS=100
and those bits take the values I want

Thank You
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Fri Jun 29, 2007 9:23 am     Reply with quote

You didn't say what processor you were using, so I wrote this is for the PIC18F65J10.

you should be able to convert it though.

Code:

struct {
   unsigned int1 ADON;
   unsigned int1 GOnDONE;
   unsigned int8 CHS : 4;
   unsigned int1 bit6;
   unsigned int1 ADCAL;
} ADCON0;
#locate ADCON0 = getenv( "SFR:ADCON0" )



void main( void )
{
   ADCON0.CHS = 0b0100;
}
Marc
Guest







PostPosted: Fri Jun 29, 2007 2:12 pm     Reply with quote

Thank you but if I have:
unsigned char ADCON2;
#locate ADCON2=0x0FC0
struct {
unsigned ADCS0:1;
unsigned ADCS1:1;
unsigned ADCS2:1;
unsigned ACQT0:1;
unsigned ACQT1:1;
unsigned ACQT2:1;
unsigned :1;
unsigned ADFM:1;
} ADCON2bits;
#locate ADCON2bits=0x0FC0

without touching this structure, how can I use ADCS=110 ?
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sat Jun 30, 2007 5:25 am     Reply with quote

You can set bit by bit.

ADCON2.ADCS0 = 0;
ADCON2.ADCS1 = 1;
ADCON2.ADCS2 = 1;

or

ADCON2 &= 0b11111000;
ADCON2 |= 0b00000110;
Marc
Guest







PostPosted: Sat Jun 30, 2007 9:28 am     Reply with quote

Perhaps I can explain.
I need something that modify only three bits and have a name ADCS, I don't know but I think a structure or union that contains those bits
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 30, 2007 10:13 am     Reply with quote

Apparently you don't want to use the "dot" syntax to access the bitfield.
Instead, you want to access it with the symbolic name of "ADCS".

You can do this with a #define statement. Use Kevcon's structure
and define a symbolic name for that bitfield. Then access it by that
name in your main program. Example:
Code:

#define ADCS (ADCON0.CHS) 

//==============================
void main()
{

ADCS = 0b1010;

while(1);
}
Marc
Guest







PostPosted: Sun Jul 01, 2007 2:49 am     Reply with quote

So with command

#define ADCS (ADCON0.CHS)

the compiler knows that ADCON0.CHS means ADCON0.CHS0 plus ADCON0.CHS1, ADCON0.CHS2, ADCON0.CHS3 (ADCON0.CHSx) ?
Or it works only in this situation? Because I'm speaking about grouping 3 bits in a structure which contains 8 bits each of them with a name
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group