Advertisement
Goreish_Ahmed

frisdrankmachine

Jan 31st, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #include <msp430.h>
  2. #pragma vector = PORT1_VECTOR
  3.  
  4. void if_first_button_is_pressed(void){
  5.     P1OUT |= 1<<1;
  6.     __delay_cycles(10000000);
  7.     P1OUT &= ~(1<<1);
  8. }
  9.  
  10. void if_second_button_is_pressed(void){
  11.     P1OUT |= 1<<3;
  12.     __delay_cycles(10000000);
  13.     P1OUT &= ~(1<<3);
  14. }
  15.  
  16. void if_third_button_is_pressed(void){
  17.     P1OUT |= 1<<6;
  18.     __delay_cycles(10000000);
  19.     P1OUT &= ~(1<<6);
  20. }
  21.  
  22. void if_fourth_button_is_pressed(void){
  23.     P2OUT |= 1<<1;
  24.     __delay_cycles(10000000);
  25.     P2OUT &= ~(1<<1);
  26. }
  27.  
  28.  
  29. int main(void){
  30.  
  31.     WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
  32.     DCOCTL = 0;
  33.     BCSCTL1 = CALBC1_1MHZ;
  34.     DCOCTL = CALDCO_1MHZ;
  35.  
  36.     P1DIR &= ~1; //button 1
  37.     P1DIR |= 1<<1; //motor pin 1
  38.     P1OUT &= ~(1<<1);
  39.  
  40.     P1DIR &= ~(1); // pull down resistor button 1
  41.     P1REN |= 1;
  42.     P1OUT &= ~(1);
  43.  
  44.     P1DIR &= ~(1<<2); // button pin 2
  45.     P1DIR |= 1<<3; // motor pin 2
  46.     P1OUT &= ~(1<<3);
  47.  
  48.     P1DIR &= ~(1<<2); //pull down resistor button 2
  49.     P1REN |= 1<<2;
  50.     P1OUT &= ~(1<<2);
  51.  
  52.     P1DIR &= ~(1<<4); // button pin 3
  53.     P1DIR |= 1<<6;
  54.     P1OUT &= ~(1<<6);
  55.  
  56.     P1DIR &= ~(1<<4); //pull down resistor button 3
  57.     P1REN |= 1<<4;
  58.     P1OUT &= ~(1<<4);
  59.  
  60.     P2DIR &= ~1; //button 4
  61.     P2DIR |= 1<<1; //motor pin 4
  62.     P2OUT &= ~(1<<1);
  63.  
  64.     P2DIR &= ~1; // pull down resistor button
  65.     P2REN |= 1;
  66.     P2OUT &= ~1;
  67.  
  68.     while(1){
  69.         if((P1IN & 1) != 0){
  70.             if_first_button_is_pressed();
  71.         }else if((P1IN & 1) == 0){
  72.             P1OUT &= ~(1<<1);
  73.  
  74.         }if((P1IN & 1<<2) != 0){
  75.             if_second_button_is_pressed();
  76.         }else if((P1IN & 1<<2) == 0){
  77.             P1OUT &= ~(1<<3);
  78.  
  79.         }if((P1IN & 1<<4) != 0){
  80.             if_third_button_is_pressed();
  81.         }else if((P1IN & 1<<4) == 0){
  82.             P1OUT &= ~(1<<6);
  83.  
  84.         }if((P2IN & 1) != 0){
  85.             if_fourth_button_is_pressed();
  86.         }else if((P2IN & 1) == 0){
  87.             P2OUT &= ~(1<<1);
  88.         }
  89.     }
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement