Jump to content
43oh

Interfacing MSP430 launchpad with PIR motion sensor and seven segment display


Recommended Posts

Hello Everyone,
 
I'm having some problems with my code, and I'm really hoping to get some help and guidance to get it working. I'm new to all of this, so please bear with me, if the errors I'm making are stupid ones.
 
The way I want my code to work is this: Everytime motion is detected on the PIR motion sensor, it should blink the LED on the launchpad, and then display the count on the seven segment display. When the count gets to 9, I want it to reset to 0 and then start over. So for example, if the PIR detects motion once, it should display 1, twice, it should display 2 and so on. Right now it blinks the LED on the launchpad, but it doesn't count up or anything. Any help will be really appreciated. Here is my code:
 
#define PIRsensor BIT5
#define LED1_OUT BIT0
int count =0;
 
void main() {
  WDTCTL = WDTPW + WDTHOLD;                     // kill wdt
  P1DIR = LED1_OUT ;                                         // set LED1 to OUT
  P1IES &= ~PIRsensor;                               
  P1IFG &= ~PIRsensor;                            
  P1IE |= PIRsensor;
_BIS_SR(LPM4_bits + GIE);                           
}
 
#pragma vector = PORT1_VECTOR
__interrupt void P1_ISR() {
  if ((P1IFG & PIRsensor) == PIRsensor) {                 // if motion is detected
   P1IFG &= ~PIRsensor;                                          // clear interrupt flag
   P1OUT ^= LED1_OUT;                                          // toggle LED1
   P1IES ^= PIRsensor;                                          
   for(count=0; count<9; count++){
       switch(count)
                  {
                    case 0:  P1OUT|=(0xFF&(~(1<<6)));  break;                         // set to display 0
                    case 1 : P1OUT = BIT1+BIT2; break;                                    // set to display 1
                    case 2 : P1OUT=BIT0|BIT1|BIT6|BIT4|BIT3; break;                // set to display 2
                    case 3 : P1OUT=BIT0|BIT1|BIT6|BIT2|BIT3; break;                // set to display 3
                    case 4 : P1OUT=BIT5|BIT6|BIT2; break;                                // set to display 4
                    case 5 : P1OUT=BIT0|BIT5|BIT6|BIT2|BIT3;break;                 // set to display 5
                    case 6 : P1OUT=BIT0|BIT5|BIT4|BIT3|BIT2|BIT6;break;         // set to display 6
                    case 7 : P1OUT=BIT0|BIT1|BIT2;break;                                // set to display 7
                    case 8 : P1OUT|=0xFF;break;                                               // set to display 8
                    case 9 : P1OUT=BIT6|BIT5|BIT0|BIT1|BIT2|BIT3;break;         // set to display 9
                    default : P1OUT = BIT0|BIT5|BIT6|BIT4|BIT3; break;             //set the letter E to display if an error occurs
                  }
   }
  }
  else {
   P1IFG = 0;                                               
}

Link to post
Share on other sites

You toggle the LED and then count from 0 to 9. as a result you will always display a 9, instead of a number that increments up to 9. How about replacing your for loop with

const unsigned char seg7[10] = {0x3F, 0x06, 0x5B, 0x52, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
if (count => 10) count = 0;
P1OUT = seg7[count];
count = count + 1;
Link to post
Share on other sites

You need to check how are the segment display and PIR inputs are wired.

 

Looks like your have your PIR on P1.5, also using the LP on board led at P1. And at the same time P1.0 to P1.6 are used as output to your 7 segment display. And you are using them as output w/o setting the IO direction P1DIR.

 

May be a simple schematic to show us how it this hooked up?

Link to post
Share on other sites

You need to check how are the segment display and PIR inputs are wired.

 

Looks like your have your PIR on P1.5, also using the LP on board led at P1. And at the same time P1.0 to P1.6 are used as output to your 7 segment display. And you are using them as output w/o setting the IO direction P1DIR.

 

May be a simple schematic to show us how it this hooked up?

Link to post
Share on other sites

@@curiousmind

 

I supposed you would have changed the following line to BIT7, if you had re-wire the PIR output to P1.7.

 

#define PIRsensor BIT5

 

In your original code you only define P1.0 (LP on board red LED) as output. You should now set

 

P1DIR = 0x7f;

 

So that P1.0 to P1.6 are configured as output. This would at least make the 7 segment LED show something.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...