我使用MSP430G2553 LaunchPad
將P2.3作為輸出,無論程序怎麼改變,P2.3都需要保持high。
但P2.3會在中斷程序發生時,瞬間變成low,不知道是不是設置有誤?
程序如下:
#include"msp430g2553.h"
#define PERIOD 200
#define naturalF 118800
int flag_IE=1;
int count=2;
void delayus(int us)
{
int i;
for(i=0;i<us;i++)
{
__delay_cycles(1);
}
}
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
DCOCTL|=DCO1+DCO0;
BCSCTL1|=RSEL3;
CACTL1 =CAON+ CAREF_0+CAIE + CAIES;
CACTL2 = P2CA1 + P2CA0 + CAF;
P1DIR |= BIT0+BIT1+BIT4+BIT5+BIT6+BIT7;
P1SEL2= 0;
P1SEL = 0;
P1REN=0;
P2DIR |= BIT5+BIT1+BIT2+BIT3+BIT4+BIT7;
P2SEL = 0;
P2SEL2= 0;
P2REN=0;
P1OUT&=~BIT4+BIT5+BIT6+BIT7;
P2OUT&=~BIT2+BIT4;
P2OUT|=BIT5+BIT1+BIT3;
__enable_interrupt();
}
#pragma vector=COMPARATORA_VECTOR
__interrupt void comp(void)
{
//P1IE=0;
CACTL1 &=~ CAIE;
P2OUT|=BIT5+BIT3;
if(flag_IE==1)
{
P1OUT&=~BIT5+BIT6;
P2OUT&=~BIT1+BIT2;
P1OUT|=BIT4+BIT7;
P2OUT|=BIT5+BIT4+BIT3;
delayus(26); //9.947us
//P2OUT|=BIT3+BIT7;
P2OUT&=~BIT1;
P2OUT|=BIT5+BIT2+BIT3;
P1OUT&=~BIT3+BIT4+BIT5+BIT6+BIT7;
delayus(22);
// P2OUT|=BIT3+BIT7;
P1OUT&=~BIT4+BIT7;
P1OUT|=BIT5+BIT6;
P2OUT&=~BIT1+BIT2;
P2OUT|=BIT5+BIT3;
delayus(26);
//P2OUT|=BIT3+BIT7;
P1OUT&=~BIT3+BIT4+BIT5+BIT6+BIT7;
P2OUT|=BIT5+BIT1+BIT3;
P2OUT&=~BIT2+BIT4;
flag_IE=0;
CACTL1 &=~ CAIES;
}
else
{
P1OUT&=~BIT4+BIT7;
P1OUT|=BIT5+BIT6;
P2OUT&=~BIT1+BIT2;
P2OUT|=BIT5+BIT3+BIT4;
delayus(26);
P2OUT&=~BIT1;
P2OUT|=BIT5+BIT2+BIT3+BIT4;
P1OUT&=~BIT3+BIT4+BIT5+BIT6+BIT7;
delayus(22);
P1OUT&=~BIT5+BIT6;
P2OUT&=~BIT1+BIT2;
P1OUT|=BIT4+BIT7;
P2OUT|=BIT5+BIT3+BIT4;
delayus(26);
P1OUT&=~BIT3+BIT4+BIT5+BIT6+BIT7;
P2OUT|=BIT5+BIT3+BIT1+BIT4;
P2OUT&=~BIT2+BIT4;
flag_IE=1;
CACTL1 |= CAIES;
// P1IES|=BIT0;
}
CACTL1|= CAIE;
CACTL1 &=~ CAIFG;
}
黃色為輸入訊號(介於P1.0 & P1.1)
藍色為P2.3的輸出訊號
放大之後如下:
我該怎麼調整呢?
灰小子:
程序里没看出p2.3有什么问题。你的外部电路是怎么样的?
xyz549040622:
P2.3的输出没问题,你中断中的逻辑的问题,仔细整理逻辑吧。
Susan Yang:
请把 Launchpad上J3 的 RXD TXD 跳帽拔掉再测量,它们使用的是P1.1 和 P1.2
gaoyang9992006:
一步一步的调试,看看是走到哪一行代码出行了这个低脉冲。