code thực tập vi xử lý

18 595 0
code thực tập vi xử lý

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

 Đk đc bước số bước nhập từ phím ma trận #include "msp430f249.h" #include "intrinsics.h" void Dkmotor (unsigned char key) { unsigned char CODE [] ={0x01,0x02,0x04,0x08}; unsigned char i, j=0; for (i=key; i>0; i ) //quay so buoc bang gia tri cua key { if(j==4) //neu het chy ky thi j=0; //nap lai giá tri 0x01 P1OUT=CODE[j]; delay_cycles (500000) ;//delay 0.5s j++; } P1OUT=0x00; //dung motor } void main ( void ) { WDTCTL = WDTPW + WDTHOLD; unsigned char key; P1DIR=0xFF; //motor buoc P5DIR=0x0F; //phim hex While (1) { // kiem tra cac phim o cot P5OUT =0xfe; If (! (P5IN & BIT4)) //phim {key =1; Dkmotor(key);} else if (!(P5IN & BIT5)) //phim {key=4; Dkmotor(key);} else if (!(P5IN & BIT6)) //phim {key=7; Dkmotor(key);} else If (!(P5IN & BIT7)) //phim 10 {key=10; Dkmotor(key);} // kiem tra cac phim o cot P5OUT = 0xfd; If (!(P5IN & BIT4)) //phim {key =2; Dkmotor(key);} else if (!(P5IN & BIT5)) //phim {key=5; Dkmotor(key);} else if(!(P5IN & BIT6)) //phim {key=8; Dkmotor(key);} else if(!(P5IN & BIT7)) //phim {key=0; Dkmotor(key);} // kiem tra cac phim o cot P5OUT =0xfb; if(!(P5IN & BIT4)) //phim {key =3; Dkmotor(key);} else if(!(P5IN & BIT5)) //phim {key=6; Dkmotor(key);} else if(!(P5IN & BIT6)) //phim {key=9; Dkmotor(key);} else if(!(P5IN & BIT7)) //phim 11 {key=11; Dkmotor(key);}}}  điều khiển quay thuận nghịch động bước phím đơn #include "msp430f249.h" #define SW1 BIT2 #define SW2 BIT3 unsigned char code[]={0x01,0x02,0x04,0x08}; unsigned char code1[]={0x08,0x04,0x02,0x01}; int j=0,i=0; void main( void ) { WDTCTL = WDTPW + WDTHOLD; P2DIR =0x00; //P3.2_SW1,P3.3_SW2: input P1DIR=0xff; //P4.4_relay: output while(1) { while(!(P2IN&SW1))//SW1 dc an { P2OUT=0x0a;} // phím sw1 đx nhấn P2 gia trị while(!(P2IN&SW2))//SW2 dc an { P2OUT=0x0c; // phím sw2 đx nhấn P2 gia trị } if(P2OUT==0x0a) { if(j==4) j=0; P1OUT=code[j]; delay_cycles(500000); } else if(P2OUT==0x0c) { if(j==4) j=0; P1OUT=code1[j]; delay_cycles(500000); }}}  Điều khiển động bước phim đơn số bước số lần ấn phím, SW1 quay thuận, SW2 quay nghịch #include "msp430f249.h" #include "intrinsics.h" #define SW1 BIT2 #define SW2 BIT3 unsigned char CODE[]={0x01,0x02,0x04,0x08}; unsigned char CODE1[]={0x08,0x04,0x02,0x01}; int i=0,j=0; void main( void ) { WDTCTL = WDTPW + WDTHOLD; unsigned char key; P1DIR=0x0f; //motor buoc P2DIR=0x00; //phim don while(1) { while(!(P2IN&SW1))//SW1 dc an { key+=1; for(i=key;i>0;i ) //quay so buoc bang gia tri cua key { if(j==4) //neu het chy ky thi j=0; //nap lai giá tri 0x01 P1OUT=CODE[j]; delay_cycles(500000);//delay 0.5s } } P1OUT=0x00; key=0; while(!(P2IN&SW2))//SW1 dc an { key+=1; for(i=key;i>0;i ) //quay so buoc bang gia tri cua key { if(j==4) //neu het chy ky thi j=0; //nap lai giá tri 0x01 P1OUT=CODE1[j]; delay_cycles(500000);//delay 0.5s } } P1OUT=0x00; key=0; }}  Chương trình motor quay thuận bước, sau dừng 2s quay nghịch bước lặp lại trình với số lần lặp nhập từ bàn phím #include "msp430f249.h" #include "intrinsics.h" int i=0,key=0; unsigned char code[]= {0x01,0x02,0x04,0x08}; unsigned char code1[]= {0x08,0x04,0x02,0x01}; void dk( unsigned char key) { for(int k=0;k0;t ) { num1-=1; goto hienthi;} dem=0; } hienthi: for(i=0;i[...]... #include "intrinsics.h" unsigned char code [] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void main (void) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; P4DIR=0xff; P6DIR=0x0f; for(int t=0;t98) t=98; for(int i=0;i0;t=t-2) { if(t

Ngày đăng: 22/10/2016, 21:23

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan