新闻中心

EEPW首页>嵌入式系统>设计应用> MSP430G2553笔记【一】

MSP430G2553笔记【一】

作者: 时间:2016-11-26 来源:网络 收藏
昨天下了一下的IAR今天才彻底装好。

早上写了流水灯的例子,算是入门msp430的第一程序。

本文引用地址://m.amcfsurvey.com/article/201611/322048.htm

下午写了按键控制led灯,一直不成功,参照了例程还是不行,例程是用中断的,不理解,还是以后在看啊。后来google了一下,才知道,按键在作为IN的时候,需要使能上接电阻,就因为这纠结了好久,希望其他的朋友不要犯这错误啊~~~

datasheet上的话:Ifthepinspullup/pulldownresistorisenabled,thecorrespondingbitinthePxOUTregisterselectspulluporpulldown
Bit0pulleddown
Bit1ppulledup

附程序

#include

#defineuintunsignedint

#defineucharunsignedchar

voidmain(void)

{

volatileuinti;

WDTCTL=WDTPW+WDTHOLD;//Stopwatchdogtimer

if(CALBC1_1MHZ==0xFF||CALDCO_1MHZ==0xFF)

{

while(1);//Ifcalibrationconstantserased,trapCPU!!

}

//ConfigureBasicClock

BCSCTL1=CALBC1_1MHZ;//Setrange

DCOCTL=CALDCO_1MHZ;//SetDCOstep+modulation

BCSCTL3|=LFXT1S_2;//SetLFXT1

//P1DIR=BIT6;//P1.6output(greenLED)

//P1DIR=0xFF;//P1.6output(greenLED)

P1DIR=0xF7;//11110111

P1REN|=0x08;//pullup

P1OUT|=0x00;//pullup

P1IES|=0x08;//hitoloedge

P1IE|=0x08;//Enableinterrupt

P1IFG&=~0x08;//Clearflag

IFG1&=~OFIFG;//ClearOSCFaultflag

BCSCTL2|=SELM_1+DIVM_0;//SetMCLK

for(;;)

{

if((P1IN&BIT3)==BIT3)

P1OUT^=BIT0;//P1.0on(redLED)

else

P1OUT^=BIT6;//P1.6on(greenLED)

}

}



评论


技术专区

关闭