我使用g2335的P1.2作为定时器TIMEA_0的捕获输入端,但是再看数据手册是的时候发现如图的描述,看有的资料说要选择P1.2的第二功能,但是怎么看TIMEA_0是这个管脚的第几功能啊,并且我还用到这个管脚的外部中断功能,应该是先进入普通的IO中断,当溢出之后进入定时器中断这是我配置的管脚
P1DIR&=~BIT2;
P1IES&=~BIT2;
P1SEL = BIT2 ;
这是用到的中断向量
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
#pragma vector=PORT1_VECTOR
__interrupt void P1_ISR (void)
但是程序就是进不去中断
已经弄了很久了,希望大家帮忙啊
http://file:///C:%5CUsers%5Cadmin%5CAppData%5CRoaming%5CTencent%5CUsers%5C1147833968%5CQQ%5CWinTemp%5CRichOle%5C]UL75M3R%7B0CE3MSVFYMKSB9.jpg
这是我的程序#define uint unsigned int
#define uchar unsigned char
uint Period; //==用于存放周期==
unsigned long int TA_OverflowCnt;
unsigned char frequency; //==用于存放频率==
uint fy[7];
void process(void);
void delay();
void PWM(void);
void main( )
{
WDTCTL = WDTPW+ WDTHOLD; //stop WDT
BCSCTL1=CALBC1_1MHZ;
DCOCTL=CALDCO_1MHZ;
P1DIR=BIT0+BIT1+BIT5+BIT3+BIT4;//控制液晶用的
P1DIR&=~BIT2;
P1IES&=~BIT2;
P1SEL = BIT2 ;
P1SEL2 =BIT2 ;
BCSCTL3 |= LFXT1S_0; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_0 + DIVS_0; // MCLK = DCO, SMCLK = DCO
lcd_init();
// lcd_write_stringxy(1,0,"ADC result");
_EINT();
while(1)
{
PWM();
P1IE|=BIT2; // 开启I/O中断,连续计数模式、无分频、开启定时中断
TACTL=TASSEL_1+MC_2+TAIE+TACLR+ID_0; //TA基准时钟为32768HZ
process();
LCD_Disp_Num(0,3,fy[5]);
LCD_Disp_Num(6,3,fy[4]);
LCD_Disp_Num(12,3,fy[3]);
lcd_write_stringxy(18,3,".");
LCD_Disp_Num(24,3,fy[2]);
LCD_Disp_Num(30,3,fy[1]);
LCD_Disp_Num(36,3,fy[0]);
lcd_write_stringxy(42,3,"KHZ");
}
}
void process(void)
{
frequency=Period/(1/32768);
fy[6]=frequency/1000000;
fy[5]=(frequency-1000000*fy[6])/100000;
fy[4]=(frequency-1000000*fy[6]-100000*fy[5])/10000;
fy[3]=(frequency-1000000*fy[6]-100000*fy[5]-10000*fy[4])/1000;
fy[2]=(frequency-1000000*fy[6]-100000*fy[5]-10000*fy[4]-1000*fy[3])/100;
fy[1]=(frequency-1000000*fy[6]-100000*fy[5]-10000*fy[4]-1000*fy[3]-100*fy[2])/10;
fy[0]=frequency%10;
}
void PWM(void)
{
P2DIR |= BIT2; // 选择P2.2的第二功能,即TA1.1
P2SEL |= BIT2;
TA1CCR0 = 199; // PWM Period
TA1CCTL1 = OUTMOD_7; // CCR1 reset/set
TA1CCR1 = 100; // CCR1 PWM duty cycle
TA1CTL = TASSEL_2 + MC_1; // SMCLK, up mode
}
// I/O中断程序
#pragma vector=PORT1_VECTOR
__interrupt void P1_ISR (void)
{
static unsigned int i=0; // I/O中断计数值
if(P1IFG&BIT2)
i++;
if(i>=100) // 计数100次
{
i=0;
Period=(((unsigned long int)TA_OverflowCnt)<<16)+TAR; // 获得100个周期内的时钟个数
TA_OverflowCnt=0;
TACTL|=TACLR; // 定时清零
}
P1IFG=0;
}
// Timer_A中断程序
#pragma vector=TIMER0_A0_VECTOR //改过了
__interrupt void Timer_A (void)
{
switch(TAIV) // TA中断方式选择
{
case 2:break;
case 4:break;
case 10: TA_OverflowCnt++; // 溢出中断计数加1
break;
}
}
|