View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
Accessing single bit of a register on dsPIC30F5015 |
Posted: Thu Feb 11, 2016 5:48 am |
|
|
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
|
|
Posted: Thu Feb 11, 2016 6:13 am |
|
|
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: 19552
|
|
Posted: Thu Feb 11, 2016 6:14 am |
|
|
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
|
|
Posted: Thu Feb 11, 2016 10:09 am |
|
|
10x |
|
|
|