资源描述:
《用按键控制led灯的亮灭》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、用按键控制LED灯的亮灭,当按键按下时,LED灯亮,当按键松开时,LED灯灭。#includenmsp430f6638.nnunsignedcharflag;voidmain(void){WDTCTL=WDTPW+WDTHOLD;//StopWDTP4DIR&=~(BIT2);P4DIR
2、=BIT4+BIT5+BIT6;//P4.4,P4.5,P4.6setasoutputP4OUT〜(BIT4+BIT5+BIT6);//setledoffP2IEI=BIT6;//enableP2.6interruptP2IFG&=~(BIT6);//cleaninterruptf
3、lag_enable_interrupt();//enableinterruptwhile(l){if((P4IN&0x04)==0){P2IFG
4、=BIT6;}else{P2IFG&=-BIT6;}}}//PORT2interruptserviceroutine#pragmavector=PORT2_VECTOR_interruptvoidport一2(void)用按键控制LED灯的亮灭,当按键按下时,LED灯亮,#include,,msp430f6638.n"voidmain(void){WDTCTL=WDTPW+WDTHOLD;松开时,LED灯灭。(查询){P
5、4OUTA=(BIT4+BIT5+BIT6);//setledonP2IFG&=~BIT6;//cleaninterruptflag}//StopWDT//settingdirection//settingIOforinput//P4.4,P45,P4.6setasoutput一‘一当按BP4DIR〜(BIT2);//Ifkeyispressed//ledon}//ledoff}}}P4DIR
6、=BIT4+BIT5+BIT6;while(1){if((P4IN&0x04)==0){P4OUT卜BIT4+BIT5+BIT6;else{P4OUT&二〜(BIT4+BIT
7、5+BIT6);//关看门狗//将ACLK时钟源配置为VLO;//将ACLK通过P1.0输出SMCLK和MCLK停止,ACLK活动}将ACLK配置为VLOCLK(约为10K),并将ACLK通过.0口输出#includevoidmain(void){WDTCTL二WDTPW+WDTHOLD;UCSCTL4
8、=SELA—1;PlDIR卜BITO;P1SEL
9、=BITO;_bis—SR—register(LPM3—bits);//进入LPM3,设AC[K=XT1=32768Hz,并通过P1.0输出#include
10、//Stopwatchdogtimer//ACLKsetouttopin//SelectXT1//UnlockXT1pinsforoperation//XTlOn//Internalloadcap//LoopuntilXT1faultflagisclearedvoidmain(voia){WDTCTL=WDTPW+WDTHOLD;P1DIR二BITO;P1SEL=BITO;P5SEL=BIT4+BIT5;while(BAKCTL&LOCKIO)BAKCTL&=〜(LOCKIO);UCSCTL6&=-(XT1OFF);UCSCTL6
11、=XCAP_3;do//Clear
12、faultflags//Testoscillatorfaultflag//reducedrivestrength//ACLK=LFTX1(bydefault)//EnterLPM3TgCLK,MCLK=DC0(默认)=32xACLK=1048576Hz,输出。{UCSCTL7&二〜(XT2OFFG+XT1LFOFFG+DCOFFG);SFRIFG1&=〜OFIFG;}while(SFRIFG1&OFIFG);UCSCTL6〜(XT1DRIVE一3);UCSCTL4
13、=SELA一0;_bis—SR—register(LPM3jDits);设ACLK二XT1'32;7
14、68Hz,令SMCLK=ACLK和SMGLK分别通过H.0和P374includevoidmain(voia)WDTCTL=WDTPW+WDTHOLD;P1DIR二BITO;P1SEL=BITO;P3DIR=BIT4;P3SEL=BIT4;while(BAKCTL&LOCKIO)BAKCTL&:〜(LOCKIO);P7SEL
15、=BIT2+BIT3;UCSCTL6&二〜XT2OFF;UCSCTL6&二〜(XT1OFF);UCSCTL6
16、=XCAPJ;do//StopWDT//ACLKsetouttopins//SMCLKsetoutt