第三章 msp430入门小程序.docVIP

  • 12
  • 0
  • 约3.44万字
  • 约 38页
  • 2017-06-24 发布于湖北
  • 举报
编者寄语: 假期出参加TI竞赛,把所有的程序都写出来了,或许有些你没看懂, 430爱好者一个,作为新手!或许我有些不好的地方,望大家谅解! //简单输出流水灯程序 #include msp430g2553.h unsigned int i=8000; int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD;//看门狗不解释 P1DIR=BIT6+BIT0;//设置p1输出 while(1)//可以多加一些灯 {P1OUT=BIT0;while(i--);//P1.0灯亮 P1OUT=BIT6;while(i--);//P1.6灯亮 } } //独立按键程序 //p1.0为led,p1.3为按键 #include msp430g2553.h int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD;//看门狗不解释 P1DIR=BIT0;//P1.0为led,显示按键起作用 P1OUT=BIT0+BIT3;//P1IN低电平跳转 P1REN=BIT3;//上拉电阻,缺了好像不能用 while(1) { if(P1INBIT3)//按键没按下 P1OUT=BIT0+BIT3;//led亮 else P1OUT=BIT3;//led灭 } } P1口中断 #include msp430x16x.h unsigned char flag=0; //任务标志 void Iint_Port1(void); //函数声明 void main(void) { WDTCTL=WDTPW+WDTHOLD; //关闭看门狗 Iint_Port1(); //初始化p1.0 _EINT(); //开总中断允许 while(1) { LPM3; //进入低功耗模式3,I/O口中断可将其唤醒 if(!flag) {P1OUT=BIT0;} //中断服务程序 else if(flag) {P1OUT=BIT6;} //其他任务 } } #include msp430x16x.h unsigned char flag=0; //任务标志 void Iint_Port1(void); //函数声明 void main(void) { WDTCTL=WDTPW+WDTHOLD; //关闭看门狗 Iint_Port1(); //初始化p1.0 _EINT(); //开总中断允许 while(1) { LPM3; //进入低功耗模式3,I/O口中断可将其唤醒 if(!flag) {P1OUT=BIT0;} //中断服务程序 else if(flag) {P1OUT=BIT6;} //其他任务 } } #pragma?vector=PORT1_VECTOR __interrupt?void?Port_1(void) { P1IFG=0; //多源中断,需靠软件清除P1IFG flag=1; //置任务标志 _BIC_SR_IRQ(LPM3_bits); //将CPU从睡眠模式唤醒 } void Iint_Port1(void) { P1DIR|=BIT0+BIT6; P1OUT=BIT0

文档评论(0)

1亿VIP精品文档

相关文档