P1.3一直在输入2.8V的脉冲,周期10MS
#include <msp430x14x.h>
#define uint unsigned int #define uchar unsigned char
uchar BACKFLAG=0; uint i,n,n1,n2=0;
void Delay_ms(unsigned long nValue) { unsigned long nCount; int i; unsigned long j; nCount=2667; for(i=nValue;i>0;i--) { for(j=nCount;j>0;j--); } return; } //*************************************** void Init_TimerA(void) { TACCTL2 = CM_1 + SCS + CCIS_0 + CAP + CCIE; // Rising edge + CCI0A (P1.3) + Capture Mode + Interrupt TACTL = TASSEL_2+ID_3+MC_2+TACLR; // SMCLK + Continuous Mode+8分频 +清除TAR+允许定时器溢出中断 } #pragma vector=TIMERA1_VECTOR __interrupt void Timer_A()//以下为参考处理程序,不使用的中断源应当删除 { switch (TAIV)//P1.3--DJ12,P1.2--DJ34, { case 2: { //捕获/比较1中断 n1++; P3OUT=~BIT3; break; } case 4: { //捕获/比较2中断 n2++; P3OUT=~BIT3; break; } default:break; } }
//********************************************** main() { unsigned int i; WDTCTL = WDTPW + WDTHOLD ; BCSCTL1 &= ~XT2OFF; //打开XT2振荡器 do { IFG1&=~OFIFG; //清除振荡错误标志 for(i=0xFF;i>0;i--); } while((IFG1&OFIFG)!=0); //如果标志为1,则继续循环等待 BCSCTL2 |= SELM1+SELS; //MCLK为8MHz,SMCLK为8MHz, SELM1=SELM_2 P1DIR=0X03; P1SEL|=(BIT3+BIT2); // 选择P1^3和P1^2作为外部计数脉冲的输入端 P2DIR=0XFF; P2OUT=0X80; P3DIR|=(BIT0+BIT1+BIT2+BIT3+BIT4); P3OUT=~BIT0; P4DIR=0X1F;//P4^1、P4^2、P4^3、P4^4作为PWM的输出端 P4OUT=0X00; P5DIR=0X00; P6DIR=0X00; P6SEL=0XF0; Init_TimerA(); _EINT(); while(1) { P2OUT=0XE0; Delay_ms(5); P4OUT=0X08; } }
|