Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <msp430.h>
- #pragma vector = PORT1_VECTOR
- void if_first_button_is_pressed(void){
- P1OUT |= 1<<1;
- __delay_cycles(10000000);
- P1OUT &= ~(1<<1);
- }
- void if_second_button_is_pressed(void){
- P1OUT |= 1<<3;
- __delay_cycles(10000000);
- P1OUT &= ~(1<<3);
- }
- void if_third_button_is_pressed(void){
- P1OUT |= 1<<6;
- __delay_cycles(10000000);
- P1OUT &= ~(1<<6);
- }
- void if_fourth_button_is_pressed(void){
- P2OUT |= 1<<1;
- __delay_cycles(10000000);
- P2OUT &= ~(1<<1);
- }
- int main(void){
- WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
- DCOCTL = 0;
- BCSCTL1 = CALBC1_1MHZ;
- DCOCTL = CALDCO_1MHZ;
- P1DIR &= ~1; //button 1
- P1DIR |= 1<<1; //motor pin 1
- P1OUT &= ~(1<<1);
- P1DIR &= ~(1); // pull down resistor button 1
- P1REN |= 1;
- P1OUT &= ~(1);
- P1DIR &= ~(1<<2); // button pin 2
- P1DIR |= 1<<3; // motor pin 2
- P1OUT &= ~(1<<3);
- P1DIR &= ~(1<<2); //pull down resistor button 2
- P1REN |= 1<<2;
- P1OUT &= ~(1<<2);
- P1DIR &= ~(1<<4); // button pin 3
- P1DIR |= 1<<6;
- P1OUT &= ~(1<<6);
- P1DIR &= ~(1<<4); //pull down resistor button 3
- P1REN |= 1<<4;
- P1OUT &= ~(1<<4);
- P2DIR &= ~1; //button 4
- P2DIR |= 1<<1; //motor pin 4
- P2OUT &= ~(1<<1);
- P2DIR &= ~1; // pull down resistor button
- P2REN |= 1;
- P2OUT &= ~1;
- while(1){
- if((P1IN & 1) != 0){
- if_first_button_is_pressed();
- }else if((P1IN & 1) == 0){
- P1OUT &= ~(1<<1);
- }if((P1IN & 1<<2) != 0){
- if_second_button_is_pressed();
- }else if((P1IN & 1<<2) == 0){
- P1OUT &= ~(1<<3);
- }if((P1IN & 1<<4) != 0){
- if_third_button_is_pressed();
- }else if((P1IN & 1<<4) == 0){
- P1OUT &= ~(1<<6);
- }if((P2IN & 1) != 0){
- if_fourth_button_is_pressed();
- }else if((P2IN & 1) == 0){
- P2OUT &= ~(1<<1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement