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 support@ccsinfo.com

Accessing single bit of a register on dsPIC30F5015

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



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Accessing single bit of a register on dsPIC30F5015
PostPosted: Thu Feb 11, 2016 5:48 am     Reply with quote

Greetings! I'm using the motor control unit of dsPIC30F5015. I need to access it's registers bit by bit. I'm accessing entire registers this way:
Code:

#word PWMCON2= getenv("SFR:PWMCON2")

How can I access every bit of it? I need to make changes only to the specific bits without touching others.
Thanks!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Feb 11, 2016 6:13 am     Reply with quote

all 16 bits of a #word
all 8 bits of a #byte
all 1 bit of a #bit


#bit mybit=word.5 //for example OR
#bit myothebit=0xFD.3

as stated in the CCS manual

or in your example
#bit bitsy3=PWMCON2.3 // bit 3
#bit bitsy11=PWMCON2.11 // bit 11 and so on


Last edited by asmboy on Thu Feb 11, 2016 6:15 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Thu Feb 11, 2016 6:14 am     Reply with quote

First, have a look at this thread:

<http://www.ccsinfo.com/forum/viewtopic.php?t=54824>

Using the union as shown here, will allow you to access multiple bits as if they are a single variable (particularly useful for the SEVOPS bits)

Then realise that you can also use #BIT

So:

#bit PWCON2BIT0=PWMCON2.0
(after PWMCON2 is declared)

and the compiler can also access the bits in SFR's by name.

So:

#bit UDIS=getenv("BIT:UDIS")

UDIS, QSYNC, IUE, SEVOPS0, 1, 2 & 3 are all known
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Thu Feb 11, 2016 10:09 am     Reply with quote

10x
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