初级会员

- 积分
- 72
- 金钱
- 72
- 注册时间
- 2014-3-11
- 在线时间
- 14 小时
|
//T1初始化
void tc1_init()
{
TCCR1B=0X42;//8·ÖÆμ
TIMSK1=0X21;
SREG|=0X80;
}
#pragma interrupt_handler TC1_yichu:10 //T1溢出中断
void TC1_yichu()
{
ov_counter++;
}
#pragma interrupt_handler TC1_buzhuo:7 //T1捕捉中断
void TC1_buzhuo()
{
if(icp_n==1)
{
falling_edge=ICR1L;
temp=ICR1H;
falling_edge|=temp<<8;
buhuobiaozhiwei=1;
TIMSK1=0X00;
}
else if(icp_n==0)
{
rising_edge=ICR1L;
temp=ICR1H;
rising_edge|=temp<<8;
}
icp_n++;
}
void main()
{
DDRD &=~(1<<PD0);
PORTD|=BIT(0);
tc1_init();
T2_init();
IO_init();
uart_init(9600);
SREG|=BIT(7);
while(1)
{
if(buhuobiaozhiwei) //完成一次测量
{
if(falling_edge >=rising_edge)
pulse_clocks = (ulong)falling_edge -(ulong)rising_edge;
else
pulse_clocks = (ulong)falling_edge -(ulong)rising_edge+(ulong)ov_counter*65535;
fadongjizhuansu=60000000/pulse_clocks;
buhuobiaozhiwei=0;
ov_counter=0;
icp_n=0;
TIFR1=0X21;
TIMSK1=0X21;
}
}
}
现在测试效果,900多以下就不能正常了,大于这个就可以。因为转速低于900多,就会溢出,也就超过了65535,不知道怎么弄了,求助各位大神。
8M外部晶振。
|
|