根据外部中断信号来计数。就是计数10个外部中断的信号中间的计数脉冲!
计数器中断程序:
void counter0_interrupt(void) interrupt 1 using 2
{
TL0 = 0;
TH0 = 0;
std_pulse_count++;
}
外部中断程序:
void extint0_interrupt(void) interrupt 0
{
idata uchar x,y;
idata union
{
ulong tmp;
uchar a[4];
}union_tmp;
meter_pulse_count0++;
if((start_flag == false)||(calc_flag == true)) //找到脉冲起点
{
Enable_Counter0();
meter_pulse_count0 = 0;
start_flag = true;
calc_flag = false;
ok_flag = true;
}
if((meter_pulse_count0 >= yg_cycles)&&(ok_flag == true)) //到设定的圈数
{
Disable_Extint0();
Disable_Counter0();
do{
x = TH0;
union_tmp.a[2] = TH0;
union_tmp.a[3] = TL0;
y = TH0;
}while(x != y);
union_tmp.a[1] = std_pulse_count%256;
union_tmp.a[0] = std_pulse_count/256;
counter0_cnt = union_tmp.tmp;
end_flag = true;
ok_flag = false;
}
}
|