大家好,我的目的是这样的:
3.3V |------R-------||------------|Gnd
P1.3接个电阻接到上面的RC中间,
P1.3先输出0,给电容放电,再变为输入,检查电容的充电电压(从低到高),达到1.8V,进入P1中断。
不断循环,平时进入LPM0,
问题是进入LPM0就会导致 P1中断进不去,注释掉就好了,但是我想用低功耗,这是什么原因?
#include
void main(void)
{
int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT &= ~BIT0;
P1DIR |= BIT3; // Set P1.3 as output pin
while (1) // Test P1.3
{
P1OUT &= ~BIT3;
P1DIR |= BIT3; // Set P1.3 as output pin
for (i = 10000; i>0; i--); // Delay
P1DIR &= ~BIT3; // Set P1.3 as input pin
P1IES &= ~BIT3;
P1IFG |=BIT3; // To prevent an immediate interrupt, clear the flag for
P1IE |= BIT3;
__bis_SR_register(GIE); // Enable interrupts
__delay_cycles(2000000);
LPM0;
}
}
unsigned int timer_count, key_threshold;
#pragma vector=PORT1_VECTOR
__interrupt void port_1_interrupt(void)
{
P1IFG &= ~BIT3; // clear the interrupt flag
timer_count = TAR - timer_count; /* Record the discharge time */
// LPM0_EXIT; /* Exit from low power 3 or 0 */
P1OUT ^= 0x01;
//return;
} |