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.

programming doubt in msp430f449

Status
Not open for further replies.

AnuHV

Member level 2
Joined
Nov 4, 2011
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,571
HI,
i am planning to receive an analog input in port6.0 from flex sensor.output of flex sensor is 1.9 volt.when i bend the sensor it increases upto 2.5v.

depending upon this value i have to glow the led connected in port1.0


while writing a c code i want to transfer this analog input value to some registers.could some one help me to write the code for it?
 

please someone help me ...
i want to know whether while writing c code for msp430f449 we can access port pins individually?
 

to change the state of the required pin:

//to set P1.0
P1OUT=P1OUT | 1;
//to reset
P1OUT=P1OUT & 0xfe;
 
  • Like
Reactions: AnuHV

    AnuHV

    Points: 2
    Helpful Answer Positive Rating
[/COLOR]
to change the state of the required pin:

//to set P1.0
P1OUT=P1OUT | 1;
//to reset
P1OUT=P1OUT & 0xfe;


if it is to get an input from a single port pin?
 

[/COLOR]


if it is to get an input from a single port pin?
if you want to read port1 , bit 0 ,
then,

if(P1IN&0x01)
yourvariable=1;
else
yourvariable=0;
 
  • Like
Reactions: AnuHV

    AnuHV

    Points: 2
    Helpful Answer Positive Rating
I like to use


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// add this defines
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT)) 
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) 
#define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT)) 
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT)) 
#define WRITEBIT(RADDRESS,RBIT,WADDRESS,WBIT) (CHECKBIT(RADDRESS,RBIT) ? SETBIT(WADDRESS,WBIT) : CLEARBIT(WADDRESS,WBIT))
 
// and then you can use
SETBIT(PORTX,2);  // set bit2 of portx (set to 1)
SETBIT(PORTY,0);  // set bit0 of porty
 
CLEARBIT(PORTX,5); // clear bit5 of portx (set to 0)
 
FLIPBIT(PORTX,2);  // invert bit2 of portX, if it was 1 it becomes 0, and if 0 becomes 1
                    // example for portx 0x10101010 the result is 0x10101110
                    
if (CHECKBIT(PORTX,4)) {} else {} // result is true if bit4 of portx is 1, false if it is 0
if (!CHECKBIT(PORTX,4)) {} else {} // result is true if bit4 of portx is 0, false if it is 1
 
 
WRITEBIT(PORTX,0,PORTY,2);   // copy the bit0 of portx to bit2 of porty



Just replace the PORTX/PORTY with the register you want to read/write (like P1IN)

Alex
 
  • Like
Reactions: AnuHV

    AnuHV

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top