|
求大神帮忙,小弟实在是不知道哪儿错了,关于G2553+霍尔传感器测速的
[复制链接]
源程序贴出来了,大神帮忙看看哪里有问题。。。
/*****************************************************************************
*****************************************************************************/
#include
#include"LCD1602.h"
#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0)) //延时x微秒
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0)) //延时X毫秒
int Num,a;
char flag_time = 0;
uint Speed=0;
uchar ge,shi,bai,qian;
uchar table[]={"0123456789"};
uchar table1[] = {"speed:"};
void TIMER0_Init(void)
{
CCR0=32768-1;
TACTL = TASSEL_1 + MC_1; //选择ACLK,增计数模式
CCTL0 = CCIE;//上升沿捕获,
}
/********************************时钟初始化*********************/
void CLK_Init(void)
{
if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
{
while(1);
}
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ; //校准DCO时钟为8MHZ
BCSCTL3 |= LFXT1S_0; //ACLK=32768KHZ
BCSCTL2 |= DIVS_3; // MCLK=SMCLK = DCO8M/8=1M
}
void xianshi(unsigned int shuju,int t) //显示一个数字
{
uint huancun[6]={0};
uchar biaozhi=0,i;
if (shuju < 10) biaozhi = 1;
else if(shuju < 100) biaozhi = 2;
else if(shuju < 1000) biaozhi = 3;
else if(shuju < 10000) biaozhi = 4;
else if(shuju <=65535) biaozhi = 5;
switch(biaozhi)
{case 5:huancun[0] = shuju/10000;
case 4:huancun[5] = shuju%10000/1000;
case 3:huancun[4] = shuju%1000/100;
case 2:huancun[3] = shuju%100/10;
case 1:huancun[1] = shuju%10;
break;
default:break;
}
for(i=6;i>1;i--)
{
if(i==3)
LCD_Disp_char(12,t,'.');
else
LCD_Disp_char(15-i,t,0x30+huancun[i-1]);
}
LCD_Disp_char(14,t,'c');
LCD_Disp_char(15,t,'m');
}
/********************************主函数*********************/
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; //关看门狗
CLK_Init();
IO_Init();
LCD_Init();
TIMER0_Init(); //定时器TIMER初始化函数
LCD_Disp_string(0,1,table1);
_EINT(); //中断使能
while(1);
/* {
LPM0;
_NOP();
}*/
}
#pragma vector=TIMER0_A0_VECTOR //定时中断向量声明
__interrupt void Timer_A0(void) //Timer A0 1s定时中断服务程序
{
Speed=Num*30; //计算风扇每分钟转速(RPM),转速=1s内上升沿个数
//*60(1分钟60秒)/2(风扇转一圈输出2周期脉冲)
Num=0; //脉冲上升沿计数清0
xianshi(Speed,1); //风扇转速送液晶显示
//TACTL|=TACLR;
}
#pragma vector=PORT1_VECTOR //P1口中断源
__interrupt void P1_ISR(void) //声明一个中断服务程序,名为P1_ISR
{
if(P1IFG & BIT2) //判断P1中断标志位第2位
{
Num+=1; //中断处理程序:来一个上升沿,计数值加1
}
P1IFG=0; //清除P1所有中断标志位-
}
|
|