#include "driverlib.h"
void main (void)
{
//Stop watchdog timer
WDT_A_hold(WDT_A_BASE);
//Set LED1 to output direction
GPIO_setAsOutputPin(GPIO_PORT_P5,GPIO_PIN0);
GPIO_setOutputHighOnPin(GPIO_PORT_P5,GPIO_PIN0);
//Enable S1 internal resistance as pull-Up resistance
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2,GPIO_PIN3);
//S1 interrupt enabled
GPIO_enableInterrupt(GPIO_PORT_P2,GPIO_PIN3);
//S1 Hi/Lo edge
GPIO_selectInterruptEdge(
GPIO_PORT_P2,GPIO_PIN3,
GPIO_HIGH_TO_LOW_TRANSITION
);
//S1 IFG cleared
GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN3);
PMM_unlockLPM5();
//Enter LPM3 w/interrupt
__bis_SR_register(LPM3_bits + GIE);
//For debugger
__no_operation();
}
//******************************************************************************
//
//This is the PORT2_VECTOR interrupt vector service routine
//
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT2_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(PORT2_VECTOR)))
#endif
void P2_ISR (void)
{
//LED1 = toggle
GPIO_toggleOutputOnPin(GPIO_PORT_P5,GPIO_PIN0
);
//S1 IFG cleared
GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN3
);
}
在评估板上调试上述程序时、
单击"Resume"
LED (绿色)亮起、因为它设置为 GPIO_setOutputHighOnPin (GPIO_PORT_P5、GPIO_PIN0);。
之后、当我输入 P2.3时、它进行切换、但
调试后、当我拔下 USB 并重新连接时、LED (绿色)不亮。 如果您输入 P2.3、则会激活扭矩。
当您连接 USB 和电源时、
我认为已设置 GPIO_setOutputHighOnPin (GPIO_PORT_P5、GPIO_PIN0);并且 LED 亮起。
为什么它不点亮?
顺便说一下、设置 GPIO_setOutputLowOnPin (GPIO_PORT_P5、GPIO_PIN0);将执行相反的操作。 (通过 USB 连接时 LED 亮起)