RSS

MSP430 io programming

29 Aug

In my previous post we saw how a led and a switch can be used.There is another way to use the individual bits of the pin.These are defined in the header file of the device.Suppose we’ve to check if a switch is pressed and switch on led then we can use the code similar to the one we wrote earlier where we did bitwise and on the P1IN register to find the value or do the following.

#include "io430.h"
#define           led             P1OUT_bit.P1OUT_0
 #define          switch       P1IN_bit.P1IN_3 
 #define          on               1
 #define          off               0
int main( void )
 {
  // Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
  P1DIR=BIT0+BIT6;               // make pin 0 and 6 output
  P1OUT=0x00;                         // switch off  led
while(1)
  {
  if(switch == 0)
  led=on;
  else
  led=off; 
 }
 }

In the above code we’ve defined macros which refer to the particular pin of a port and whether it is input or output.These are present in the file io430x202.h which gets added by default.If the file is not getting added then it can be added from the folder

C:\Program Files\IAR Systems\Embedded Workbench 5.4 Kickstart\430\inc\

select the required file and add it to the source.

Advertisements
 
1 Comment

Posted by on August 29, 2011 in Flip, MSP430 Tutorials

 

Tags: ,

One response to “MSP430 io programming

  1. raju

    April 21, 2015 at 4:26 pm

    how to do single bit declaration.I think above answer is wrong because ,when i written in my program i am getting error like undeclared .if any body knows this topic can u define lcd pins to micro controller pins.those pins are lcd_rs,lcd_rw,lcd_en just enough.thank you

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: