G题-报告4-程序清单 | ||||
| ||||
G题-报告4-程序清单 #include <msp430.h> #define bit0 (0x0001) #define bit1 (0x0002) #define bit2 (0x0004) #define bit3 (0x0008) void delay(volatile unsigned int n) { do (n--);while (n != 0); } int main(void) { WDTCTL = WDTPW + WDTHOLD; BCSCTL1=CALBC1_16MHZ; DCOCTL=CALDCO_16MHZ; P1DIR = bit0 ; // Set P1.0 to output direction P2DIR = 0x00; volatile unsigned int i=0; unsigned int a=0; unsigned int b=0; while(1) { // if((P1IN & BIT5)==0) P1OUT|=BIT1; //若P1.5为低电平则P1.1输出高电平 if((P2IN & bit0)==0) //场致低时 { delay(1000); // delay_cycles(1); while(!(P2IN & bit0)) { if(P2IN & bit1) //行信号降高时 { delay(128); if(a!=0) { P1OUT|= bit0; delay(a); } if(b!=0) { P1OUT = 0x00; delay(3); } if(b!=0) { P1OUT|= bit0; delay(b); } P1OUT = 0x00; if(i<=25 || i>115) if(i>=285) { P1OUT = 0x00; i=3; delay(300); } else {a=0;b=0;} else if(i<45 || i>95){a=18;b=0;} else if(i<65 || i>75){a=6;b=4;} else{a=5;b=0;} i++; } } } else {P1OUT = 0x00; i=0;} } //while }
|