#include "MSp430G2553.h"
#include"LCD.h"
unsigned int old=0,new=0,T,zhuangsu;
unsigned char overflow;
void main( void )
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR|=BIT6;
P1SEL|=BIT2;//P1.2->捕获输入
P1OUT&=~BIT6;//关闭LED
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALBC1_1MHZ;
Port_init();
//delay_ms(100);
LCD_init();
LCD_clear();
CCTL1=CM_1+SCS+CCIS_0+CAP+CCIE;//上升沿+同步+CCI0A(p1.2)+捕获功能+捕获中断
TACTL=TASSEL_2+MC_2+TAIE+TACLR;
_EINT();
while(1){_BIS_SR(GIE);
xianshi();
}
}
void xianshi(void)
{
T=2*T/1000000;
zhuangsu=60/T;
LCD_write_str(0,0,"zhuangsu:");
LCD_write_char(0,1,num_char_table[zhuangsu/10000]);
LCD_write_char(1,1,num_char_table[zhuangsu%10000/1000]);
//LCD_write_char(3,1,'.');
LCD_write_char(2,1,num_char_table[zhuangsu%1000/100]);
LCD_write_char(3,1,num_char_table[zhuangsu%100/10]);
LCD_write_char(4,1,num_char_table[zhuangsu%10]);
//LCD_write_char(4,1,num_char_table[0]);
LCD_write_str(5,1,"zhuang/min");
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A (void)
{
switch(TAIV)
{
case 2:
if(CCTL1&CM_1)
{
new=TAR;
T=new-old;
overflow=0;
}
old=new;
P1OUT^=BIT6;
break;
case 10:
overflow++;
break;
default:
break;
}
} |