Advertisement
codegod313

MPSIS 1 BLINKING

Sep 24th, 2022 (edited)
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #define DELAY 75
  2.  
  3. #include <msp430.h>
  4.  
  5. int main(void)
  6. {
  7.   WDTCTL = WDTPW + WDTHOLD;     // Stop WDT
  8.   //LED CONFIGURATION
  9.   P1DIR |= BIT1; //direction ->OUT
  10.   P1DIR |= BIT2;
  11.   P1DIR |= BIT3;
  12.   P1DIR |= BIT4;
  13.   P1DIR |= BIT5;
  14.  
  15.   P1OUT &= ~BIT1; //state ->OFF
  16.   P1OUT &= ~BIT2;
  17.   P1OUT &= ~BIT3;
  18.   P1OUT &= ~BIT4;
  19.   P1OUT &= ~BIT5;
  20.  
  21.   //BUTTON CONFIGURATION
  22.   P2DIR &= ~BIT2; //direction ->IN
  23.  
  24.   P2REN |=BIT2; //pullup/pulldown enabled
  25.  
  26.   P2OUT &=~BIT2; // enable pulldown
  27.  
  28.   //STATE CONFIGURATION
  29.  
  30.   volatile char state = 0; //state of blinking
  31.   volatile int i = 0;      //cycle parameter
  32.   for(;;){
  33.       if(P2IN &=BIT2){     //if button pressed
  34.           state ^= BIT0;   //change blinking state
  35.       }
  36.       if(state & BIT0){
  37.           for(i = 0; i<2; i++){
  38.               P1OUT ^= BIT1;         //LED inversion
  39.               __delay_cycles(DELAY); //delay
  40.               P1OUT ^= BIT2;
  41.               __delay_cycles(DELAY);
  42.               P1OUT ^= BIT3;
  43.               __delay_cycles(DELAY);
  44.               P1OUT ^= BIT4;
  45.               __delay_cycles(DELAY);
  46.               P1OUT ^= BIT5;
  47.               __delay_cycles(DELAY);
  48.           }
  49.       }
  50.   }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement