#include <msp430g2553.h>
#include"lcd.h"
uchar table[]="小型风扇检测仪";
uchar table1[]="转速";
uchar table2[]="r/min";
uchar table3[]="线速度";
uchar table4[]="m/s";
uint n,m,overflowcut;
float speed,r=0.055;
void display(uint speed);
void displayini();
void display1(uint speed);
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗定时器
ini();
displayini();
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ; // 设置DCO模式
P1DIR&=~BIT5;//P1.2为输入
P1REN|=BIT5;//上拉电阻
P1IES|=BIT5;//选择第2功能
P1IE|=BIT5;
TACTL|=TASSEL_2+MC_2+TAIE+TACLR;
_EINT();
}
void display(uint speed)
{
uchar bb,cc,dd,ee;
bb=speed%10000/1000;
cc=speed%1000/100;
dd=speed%100/10;
ee=speed%10;
writedata(0x30+bb);
writedata(0x30+cc);
writedata(0x30+dd);
writedata(0x30+ee);
}
void display1(uint speed)
{
uchar bb,cc,dd,ee;
bb=speed%10000/1000;
cc=speed%1000/100;
dd=speed%100/10;
ee=speed%10;
writedata(0x30+bb);
writedata(0x30+cc);
writedata('.');
writedata(0x30+dd);
writedata(0x30+ee);
}
void displayini()
{
uchar i=0;
setwindow(0,0);
for(;table[i]!='\0';i++)
{
writedata(table[i]);
}
i=0;
setwindow(1,0);
for(;table1[i]!='\0';i++)
{
writedata(table1[i]);
}
i=0;
setwindow(1,4);
for(;table2[i]!='\0';i++)
{
writedata(table2[i]);
}
i=0;
setwindow(2,0);
for(;table3[i]!='\0';i++)
{
writedata(table3[i]);
}
i=0;
setwindow(2,5);
for(;table4[i]!='\0';i++)
{
writedata(table4[i]);
}
i=0;
}
#pragma vector=PORT1_VECTOR
__interrupt void port2_4()
{
uint i;
_BIC_SR(SCG0);
for(i=0;i<600;i++);
if((P1IN&BIT5)==BIT5)
{
P1IFG=0;
return;
}
if(P1IFG&BIT5)
{
n=8000000*60/((overflowcut*65535+TAR)*7);
speed=(float)(3.141592654*r*8000000/(7*(overflowcut*65535+TAR)));
m=(int)(speed*100);//转换 把speed化为m
overflowcut=0;
TACTL|=TACLR;
setwindow(1,2);
display(n);
setwindow(2,2);
display1(m);
}
P1IFG=0;
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TA_ISR(void)
{
switch(TAIV)
{
case 2: break;
case 4: break;
case 10: overflowcut++;
if(~TAR)
{
setwindow(1,2);
display(0);
setwindow(2,2);
display1(0);
}
break;
}
}
|