msp430入门学习10

基于msp430f160的闪烁灯,代码如下:

 1 #include <msp430f169.h>
 2 
 3 #define CPU_F ((double)8000000)   //定义一个常数8000_000
 4 //#define CPU_F ((double)32768)   //外部低频晶振32.768KHZ
 5 #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/8000000.0))
 6 #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/8000.0))
 7 
 8 /**
 9  * main.c
10  */
11 int main(void)
12 {
13     WDTCTL = WDTPW | WDTHOLD;    // stop watchdog timer
14     P6DIR |= BIT0;
15     P6OUT |= BIT0;
16 
17     while(1){
18         delay_ms(1000);
19         P6OUT &= ~BIT0;
20         delay_ms(1000);
21         P6OUT |= BIT0;
22     }
23 
24     return 0;
25 }

 

posted @ 2017-11-09 06:23  叕叒双又  阅读(330)  评论(0编辑  收藏  举报