Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How access the bitfield of MSP430 in IAR C

Status
Not open for further replies.

chen_Analog

Newbie level 6
Joined
Sep 13, 2005
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,386
bitfield msp430 example

How to access the bitfield of MSP430 using IAR C. for instance, I want to set or reset of any individual bit from c code.
 

iar msp430 bitfield

Do this defines:

#define bit_test(A,B) (A & B)
#define bit_set(A,B) A |= B
#define bit_clear(A,B) A &= ~B

Then you has just insert the processor header:

#include "msp430x14x.h"

Now if you wanna set bit 0 of any REGISTER of variable simple do it:
bit_set(ANY_REGISTER,BIT0);

For RESET
bit_clear(ANY_REGISTER,BIT0);

for test if bit is set
if (bit_test(ANY_REGISTER,BIT0))
{
}

for test if bit is clear
if (!bit_test(ANY_REGISTER,BIT0))
{
}


Do the same for
BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, BIT8, BIT9, BITA, BITB, BITC, BITD, BITE, BITF
These are defined on processor header like it....

#define BIT0 (0x0001)
#define BIT1 (0x0002)
#define BIT2 (0x0004)
#define BIT3 (0x0008)
#define BIT4 (0x0010)
#define BIT5 (0x0020)
#define BIT6 (0x0040)
#define BIT7 (0x0080)
#define BIT8 (0x0100)
#define BIT9 (0x0200)
#define BITA (0x0400)
#define BITB (0x0800)
#define BITC (0x1000)
#define BITD (0x2000)
#define BITE (0x4000)
#define BITF (0x8000)

leomecma
 

iar msp430 bitfield example

I know this method, but I think this is still not bit access but whole register access

The following is the example of bit accessing:
__no_init volatile union
{
unsigned char IE1
struct
{
unsigned char WDTIE : 1;
unsigned char OFIE : 1;
unsigned char : 2;
unsigned char NMIIE : 1;
unsigned char ACCVIE : 1;
unsigned char URXIE0 : 1;
unsigned char UTXIE0 : 1;
} IE1_bit;
} @ 0x0000;

By including above code into the user code it is possible to access either the whole register or any individual bit (or birtfields) from C code as follows"

//whole register access

IE1 = 0x1234;

//Bitfield accesses

IE1.WDTIE = 1;

I try it but can not success. I don't know why?
 

bitfield msp430

IAR don't support this modes.


leomecma
 

chen_Analog,
I believe that you solution is to use macros.

At my proyects with MSP430 I use....

#define RTSon() P3OUT != 0x04 //being bit4 of P3 = 1
#define RTSoff() P3OUT &= ~0x04 //deing bit4 of P3 = 0

then

main()
{
...
...
//now I want RTS=1
RTSon();
....
.....
//now RTS=0
RTSoff();
....
....


}

This example you can to apply to your work
i.e.

Best Regards
FSio
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top