void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
if (CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF) {
while (1)
; // If calibration constants erased, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
LCD_init();
IE_init();
_EINT();
while(1){
if(flag==1)
{ _DINT();
flag=0;
count++;
if(count==1)
{
time_0=TA0CCR0;
}
else{
time_1=TA0CCR0;
count=0;
x=1000000/(time_1-time_0);
LCD_write_string(0,0,"The fra is :");
LCD_write_char(1,6,x%10000%1000%100%10+'0');
LCD_write_char(1,5,x%10000%1000%100/10+'0');
LCD_write_char(1,4,x%10000%1000/100+'0');
LCD_write_char(1,3,x%10000/1000+'0');
LCD_write_char(1,2,x/10000+'0');
_delay_cycles(2000);
TA0CTL=MC_2+TACLR;
}
_EINT();}
}
}
#pragma vector=TIMER0_A0_VECTOR //TIMERA0CRRO中断服务程序;
__interrupt void A0CCRO_VECTOR(void)
{ flag=1;
}
void IE_init()
{
P1REN|=BIT1;
P1OUT|=BIT1;
P1SEL|=BIT1;
TA0CCTL0=CM_2+SCS+CCIS_0+CAP+CCIE;
TA0CTL=TASSEL_2+MC_2+TACLR;
}
主要代码都在这里了
|