|
/*****************对应被捕获信号频率有限制**************************/
#include
#include"5110.h"
#define uchar unsigned char
#define uint unsigned int
unsigned int i,lastCCR0,lastCCR1;
unsigned long j,k;
unsigned int n;
char a[7]={0};
char a1[7]={0};
void Transfer(unsigned long x);
void Transfer1(unsigned long Y);
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
LCD_init();
j=0;
k=0;
lastCCR0=0;
lastCCR1=0;
CCTL2=CCIE;
CCR2=33340;
P3DIR|=BIT5;
P3OUT&=~BIT5;
P1DIR=0X00;
P1SEL=0X06;
P2DIR=0X01; //P2.0口接入一信号
P2OUT|=0x00;
TACTL=TASSEL_2+ID_3+MC_2+TACLR; //连续计数
CCTL0=CM_3+CCIS_0+SCS+CAP+CCIE; //CCI0A,上升下降都捕获P1.1
CCTL1=CM_1+CCIS_0+SCS+CAP+CCIE; //CCI1A,上升沿捕获,同步捕获,捕获模式,中断允许P1.2
_EINT(); //开启中断允许位
LCD_write_english_string(0,0,"T:");
LCD_write_english_string(0,2,"N:");
// LCD_write_english_string(0,4,"N/T:");
for(;;)
{
Transfer(j);
Transfer1(k);
}
}
void Transfer(unsigned long x)
{
a[0]=(long )x/100000+'0';
a[1]=(long)(x%100000)/10000+'0';
a[2]=( long )(x%100000)%10000/1000+'0';
a[3]=(long )(x%100000)%10000%1000/100+'0';
a[4]=(long )(x%100000)%10000%1000%100/10+'0';
a[5]=(long )(x%100000)%10000%1000%100%10+'0';
a[6]='\0';
LCD_write_english_string(18,0,a);
}
void Transfer1(unsigned long y)
{
a1[0]=(long )y/100000+'0';
a1[1]=(long )(y%100000)/10000+'0';
a1[2]=(long )(y%100000)%10000/1000+'0';
a1[3]=(long )(y%100000)%10000%1000/100+'0';
a1[4]=(long )(y%100000)%10000%1000%100/10+'0';
a1[5]=(long )(y%100000)%10000%1000%100%10+'0';
a1[6]='\0';
LCD_write_english_string(18,2,a1);
}
#pragma vector =TIMERA1_VECTOR //周期,上升沿
__interrupt void TIMER_A(void)
{
switch(TAIV)
{
case 2: //CCR1捕获中断
j=65536*n+CCR1-lastCCR1;
lastCCR1=CCR1;
n=0;
break;
case 4:
P2OUT^=0x01; //P2.0
CCR2+=33340;
break;
case 10: //溢出中断
n++;
break;
}
}
#pragma vector=TIMERA0_VECTOR //CCR0捕获中断,高电平时间
__interrupt void TIMER_cc(void)
{
if(SCCI==0)//程序在这里进不去。。。。
{
k=65536*n+CCR0-lastCCR0;
lastCCR0=CCR0;
P3OUT^=BIT5;
}
}
这个程序是利用timerA的捕获与比较模块,测量信号的频率,并在5110上显示出来。这个程序里外部信号是由timerA的CCR2的比较在P2.0引脚上产生的方波,便于程序的测量及检验。
希望大虾多多指教!
[ 本帖最后由 麻滴滴 于 2012-7-24 22:10 编辑 ]
|
|