Báo cáo TT vi xử lý - Bài 6: Điều khiển motor dc - Relay

Báo Cáo TT.Vi Xử Lý Bài 6: Điều Khiển Motor DC-Relay Câu 1: điều khiển đóng ngắt Relay. 2/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 #define relay BIT4 void main( void ) { WDTCTL = WDTPW + WDTHOLD; P3DIR = 0xfb; //P3.2_SW1: input P4DIR = 0xff; //P4.4_relay: output P4OUT=0x00; //tat relay while(1) { while(P3IN & SW1&SW2); //kiem tra SW1 __delay_cycles(20000); //chong doi phim P4OUT = relay; //neu phim duoc an dao P4.4 while(!(P3IN & SW1)); //phim dang dc an thi lap tai cho } } 3/

docx10 trang | Chia sẻ: thuychi11 | Lượt xem: 740 | Lượt tải: 0download
Bạn đang xem nội dung tài liệu Báo cáo TT vi xử lý - Bài 6: Điều khiển motor dc - Relay, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Báo Cáo TT.Vi Xử Lý Bài 6: Điều Khiển Motor DC-Relay Câu 1: điều khiển đóng ngắt Relay. 2/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 #define relay BIT4 void main( void ) { WDTCTL = WDTPW + WDTHOLD; P3DIR = 0xfb; //P3.2_SW1: input P4DIR = 0xff; //P4.4_relay: output P4OUT=0x00; //tat relay while(1) { while(P3IN & SW1&SW2); //kiem tra SW1 __delay_cycles(20000); //chong doi phim P4OUT = relay; //neu phim duoc an dao P4.4 while(!(P3IN & SW1)); //phim dang dc an thi lap tai cho } } 3/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 #define relay BIT4 void main( void ) { WDTCTL = WDTPW + WDTHOLD; P3DIR = 0xfb; //P3.2_SW1: input P4DIR = 0xff; //P4.4_relay: output P4OUT=0x00; //tat relay while(1) { if(!(P3IN&SW1))//SW1 dc an { __delay_cycles(20000); P4OUT=relay; //dong relay } if(!(P3IN&SW2))//SW2 dc an { __delay_cycles(20000); P4OUT &=~relay; //ngat relay } } } 4/ #include "msp430fg4618.h" #define SW1 BIT2 #define relay BIT4 int i=0; void main( void ) { WDTCTL = WDTPW + WDTHOLD; P3DIR = 0xfb; //P3.2_SW1: input P4DIR = 0xff; //P4.4_relay: output while(1) { if(!(P3IN&SW1))//SW1 dc an { i+=1; for(int j=0;j<i;j++) {P4OUT^=relay; __delay_cycles(20000); }} } } 5/ #include "msp430fg4618.h" #define SW1 BIT2 #define relay BIT4 int i=0; void main( void ) { WDTCTL = WDTPW + WDTHOLD; P3DIR = 0xfb; //P3.2_SW1: input P4DIR = 0xff; //P4.4_relay: output while(1) { if(!(P3IN&SW1))//SW1 dc an { for(int j=0;j<10;j++) {P4OUT^=relay; __delay_cycles(20000); }} } } 6/ giống câu 3 7/ 8/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 #define relay BIT4 void main( void ) { WDTCTL = WDTPW + WDTHOLD; P3DIR = 0xfb; //P3.2_SW1: input P4DIR = 0xff; //P4.4_relay: output P4OUT=0x00; //tat relay while(1) { if(!(P3IN&SW1&SW2))//SW1 dc an { __delay_cycles(20000); P4OUT&=~relay; //dong relay } if(!(P3IN&SW1))//SW2 dc an { __delay_cycles(20000); P4OUT =relay; //ngat relay } if(!(P3IN&SW2))//SW2 dc an { __delay_cycles(20000); P4OUT =relay; //ngat relay } } } Câu 2: diều khiển motor quay thuận/nghịch 2/ 3/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 int i=0; void main( void ) { WDTCTL = WDTPW + WDTHOLD; P3DIR =0x00; //P3.2_SW1,P3.3_SW2: input P4DIR |= 0x03; //P4.4_relay: output P4OUT |= 0x03; //P4.4=0 while(1) { if(!(P3IN&SW1))//SW1 dc an { i+=1; for(int j=0;j<i;j++) { P4OUT=0x01; //set P4.0-->quay thuan __delay_cycles(20000); //chong doi phim } P4OUT=0x00; //tat } if(!(P3IN&SW2))//SW2 dc an { { i+=1; for(int j=0;j<i;j++) { P4OUT=0x02; //set P4.0-->quay nghich __delay_cycles(20000); //chong doi phim } P4OUT=0x00; //tat } } } 4/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 int i=0; void main( void ) { { WDTCTL = WDTPW + WDTHOLD; P3DIR =0x00; //P3.2_SW1,P3.3_SW2: input P4DIR |= 0x03; //P4.4_relay: output P4OUT |= 0x03; //P4.4=0 while(1) { if(!(P3IN&SW1))//SW1 dc an { P4OUT=0x02; //set P4.0-->quay nghich __delay_cycles(20000); //chong doi phim } if(!(P3IN&SW2))//SW2 dc an { P4OUT=0x01; //set P4.1-->quay thuan __delay_cycles(20000); } } } 5/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 void main( void ) { { WDTCTL = WDTPW + WDTHOLD; P3DIR =0x00; //P3.2_SW1,P3.3_SW2: input P4DIR |= 0x03; //P4.4_relay: output P4OUT |= 0x03; //P4.4=0 for (int j=0;j<5;j++) { P4OUT=0x01; //set P4.0-->quay thuan __delay_cycles(1000000); //chong doi phim } P4OUT=0x00; } 6/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 void main( void ) { { WDTCTL = WDTPW + WDTHOLD; P3DIR =0x00; //P3.2_SW1,P3.3_SW2: input P4DIR |= 0x03; //P4.4_relay: output P4OUT |= 0x03; //P4.4=0 While (1) { for (int j=0;j<5;j++) { P4OUT=0x01; //set P4.0-->quay thuan __delay_cycles(1000000); //chong doi phim } for (int j=0;j<5;j++) { P4OUT=0x00; //set P4.0-->dung __delay_cycles(1000000); //chong doi phim } } }} 7/ #include "msp430fg4618.h" #define SW1 BIT2 #define SW2 BIT3 void main( void ) { { WDTCTL = WDTPW + WDTHOLD; P3DIR =0x00; //P3.2_SW1,P3.3_SW2: input P4DIR |= 0x03; //P4.4_relay: output P4OUT |= 0x03; //P4.4=0 for (int j=0;j<5;j++) { P4OUT=0x01; //set P4.0-->quay thuan __delay_cycles(1000000); //chong doi phim } for (int j=0;j<5;j++) { P4OUT=0x02; //set P4.0-->dung __delay_cycles(1000000); //chong doi phim } P4OUT=0x00; } } Câu 3: điều khiển tốc độ quay của motor bằng các sử phương pháp PWM 2/ void main( void ) { unsigned int value=5000;//gia tri ban dau WDTCTL = WDTPW + WDTHOLD; P3DIR = 0x00; //P3.2_SW1,P3.3_SW2: input P4DIR = MOTOR|BIT1; //P4.4_relay: output P4OUT &=~ BIT1; //P4.4=0 while(1) { if(!(P3IN&SW1))//neu SW1 dc an { __delay_cycles(2000); value+=1000; //tang toc do if(value==26000) value=5000; while(!(P3IN&SW1));//neu phim con nhan //thi lap tai cho } if(!(P3IN&SW2))//neu SW2 dc an { __delay_cycles(2000); value-=1000; //giam toc do if(value==4000) value=25000; while(!(P3IN&SW2)); } P4OUT|=MOTOR; //MOTOR ON delay(value); P4OUT&=~MOTOR; //MOTOR OFF delay(25000-value); } } 3/ void main( void ) { unsigned int value=5000;//gia tri ban dau WDTCTL = WDTPW + WDTHOLD; P3DIR = 0x00; //P3.2_SW1,P3.3_SW2: input P4DIR = MOTOR|BIT1; //P4.4_relay: output P4OUT &=~ BIT1; //P4.4=0 while(1) { Value=5000; P4OUT|=MOTOR; //MOTOR ON delay(value); P4OUT&=~MOTOR; //MOTOR OFF delay(20000-value); } } 5/ void main( void ) { unsigned int value=5000;//gia tri ban dau WDTCTL = WDTPW + WDTHOLD; P3DIR = 0x00; //P3.2_SW1,P3.3_SW2: input P4DIR = MOTOR|BIT1; //P4.4_relay: output P4OUT &=~ BIT1; //P4.4=0 while(1) { Value=10000; P4OUT|=MOTOR; //MOTOR ON delay(value); P4OUT&=~MOTOR; //MOTOR OFF delay(20000-value); } } 6/ void main( void ) { unsigned int value=5000;//gia tri ban dau WDTCTL = WDTPW + WDTHOLD; P3DIR = 0x00; //P3.2_SW1,P3.3_SW2: input P4DIR = MOTOR|BIT1; //P4.4_relay: output P4OUT &=~ BIT1; //P4.4=0 while(1) { Value=15000; P4OUT|=MOTOR; //MOTOR ON delay(value); P4OUT&=~MOTOR; //MOTOR OFF delay(20000-value); } }