Advertisement
Goreish_Ahmed

soda machine

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