Advertisement
Goreish_Ahmed

code acting weird

Jan 28th, 2022
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <msp430.h>
  2. #pragma vector = PORT1_VECTOR
  3.  
  4. void if_first_button_is_pressed(void){
  5.     P2OUT |= 1<<5;
  6.     __delay_cycles(3000000);
  7.     P2OUT &= ~(1<<5);
  8. }
  9.  
  10. void if_fourth_button_is_pressed(void){
  11.     P2OUT |= 1<<1;
  12.     __delay_cycles(3000000);
  13.     P2OUT &= ~(1<<1);
  14. }
  15.  
  16.  
  17.  
  18. int main(void){
  19.  
  20.  
  21.     WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
  22.     DCOCTL = 0;
  23.     BCSCTL1 = CALBC1_1MHZ;
  24.     DCOCTL = CALDCO_1MHZ;
  25.  
  26.     P1DIR &= ~1<<3; //button 1
  27.     P2DIR |= 1<<5; //motor pin 1
  28.  
  29.     P1DIR &= ~(3); // pull down resistor button
  30.     P1REN |= 3;
  31.     P1OUT &= ~(3);
  32.  
  33.     P2DIR &= ~1; //button 2
  34.     P2DIR |= 1<<1; //motor pin 2
  35.  
  36.     P2DIR &= ~1; // pull down resistor button
  37.     P2REN |= 1;
  38.     P2OUT &= ~1;
  39.  
  40.  
  41.     while(1){
  42.         if((P1IN & 1<<3) == 1){
  43.             if_first_button_is_pressed();
  44.         }else if((P1IN & 1<<3) == 0){
  45.             P2OUT &= ~(1<<5);
  46.  
  47.         }if((P2IN & 1) == 1){
  48.             if_fourth_button_is_pressed();
  49.         }else if((P2IN & 1) == 0){
  50.             P2OUT &= ~(1<<1);
  51.         }
  52.     }
  53.  
  54.    
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement