代码:#include <msp430g2553.h>
#include "LCDdriver.h"
#include "normal.h"
unsigned int TA_OV=0;
float period=0;
unsigned int per=0;
void CLK_init(void)
{
BCSCTL1 |= CALBC1_1MHZ;
DCOCTL |= CALDCO_1MHZ;//上面两句将内部DCO校准至1MHz
//while(IFG1&OFIFG)
//{
//IFG1 &= ~OFIFG;
//delay_ms(100);
//}
BCSCTL2 |= SELM_0;//MCLK采用1M的内部DCO
BCSCTL2 |= DIVS_2;//SMCLK采用250K的时钟
} //时钟初始化
void main(void) {
WDTCTL =WDTPW+WDTHOLD;
CLK_init();
P1DIR &=~BIT2; //P1.2 TA0.1
P1SEL |=BIT2;
lcdinit();
TACTL =TASSEL_1+MC_2+TAIE+TACLR;
TACCTL1 =CAP +CM_1+CCIS_1+SCS+CCIE; //捕获模块1o
_EINT();
LPM3;
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TIMER_A0 (void){
switch(TAIV){
case 2: period = (TA_OV*65536+TA0R-per);
per=TA0R;
TA_OV=0;
display_hanz(1,1,"频率为:");
LCD_DispDec(2,1,period,6,3);
break;
case 4:break;
case 10: TA_OV++; break; //yi chu
}
} |