//=======================================================
//TIMER2 10毫秒自动重装
//=======================================================
void TIME2_ISR (void) interrupt 5 //20毫秒自动重装
{
static uchar i,j1,j2,j3,j4,j5,j6,k,k1,m,m1,LTP1,LNY1;
static uint c1,c2,c3,c4;
TF2 = 0; //清标志位
i++;
if(i==50)
{
P5=~(P5);
i = 0;
}
LTP1 = P7; //接近开关不遮挡输出高电平,
LNY1 = P7;
if((LTP1&0xFF) ==0xFF) //P70=1;遮挡上了,接近开关无输出,此时P70=1;
{
j1++;
if(j1》2) //2次以上还是原来状态证明不是干扰脉冲
{
j1 = 0;
k = 1; //检测到P70为0,置位K
}
c3++;
if(c3》9000) //超过1分半钟没变化认为停止了
{
c3 = 0;
SPEEDcount1 = 0;
SPEEDTP = 0;
}
}
if(k) //在置位情况下等待下降沿
{
if((LTP1&0xFF) ==0xFE) //P70=0;检测到无遮挡,接近开关输出24V,开始一个周期此时P70 = 0;
{
j2++;
if(j2》2) //过滤脉冲干扰
{
j2 = 0;
k1 = 1;
}
c1++;
if(c1》9000) //超过1分半钟没变化认为停止了
{
c1 = 0;
SPEEDcount1 = 0;
SPEEDTP = 0;
k1 = 0;
k = 0;
}
if(k1)
{
SPEEDcount1++; //发生了正跳变,开始计时
}
}
if(k1)
{
if((LTP1&0xFF) ==0xFF) //再一次检测到有遮挡表示一次检测周期结束,计时结束,开始计算速度
{
j3++;
if(j3》2)
{
j3 = 0;
k1 = 0;
k = 0;
//SPEEDTP = SPEEDcount1/100; //(秒)
SPEEDTP = (long)600*(Between[4]*100 + Between[3])/SPEEDcount1; //米/分;显示部分已经后移了两位
SPEEDcount1 = 0;
c1 = 0;
c3 = 0;
TPcount++;
TPrange = (long)TPcount*(Between[6]*100 + Between[5])/1000;
}
}
}
}
if((LNY1&0xFF) ==0xFF) //P71=1;
{
j4++;
if(j4》2) //2次以上还是原来状态证明不是干扰脉冲
{
j4 = 0;
m = 1; //检测到P71为0,置位M
}
c4++;
if(c4》9000) //超过1分半钟没变化认为停止了
{
c4 = 0;
SPEEDcount2 = 0;
SPEEDNY = 0;
}
}
if(m) //在置位情况下等待下降沿
{
if((LNY1&0xFF) ==0xFD) //P71=0;
{
j5++;
if(j5》2) //过滤脉冲干扰
{
j5 = 0;
m1 = 1;
}
c2++;
if(c2》9000) //等待了1分半钟没变化,认为停止了
{
c2 = 0;
SPEEDcount2 = 0;
SPEEDNY = 0;
m1 = 0;
m = 0;
}
if(m1)
{
SPEEDcount2++; //发生了正跳变,开始计时
}
}
if(m1)
{
if((LNY1&0xFF) ==0xFF) //发生了负跳变,计时结束,开始计算速度
{
j6++;
if(j6》2)
{
j6 = 0;
m1 = 0;
m = 0;
SPEEDNY = (long)36*(Between[6]*100 + Between[5])/SPEEDcount2; //km/h;显示部分已经后移了两位
SPEEDcount2 = 0;
c2 = 0;
c4 = 0;
}
}
}
}
}
void ADC0_ISR (void) interrupt 15
{
static uchar count0; // Loop counter
AD0INT = 0; //清中断标志位
switch( AMX0SL ) //通道转换
{
case 0x00: //AIN0.0
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 1;
filter();
TPHD1= (sum/(N-2));
if(TPHD1》ADC04V)
{
TPHD1 = TPHD1 - 5; //去掉偏移量
a = (long)TPHD1*2500/4095; //放大1000倍,采集到1毫伏
a = (a*469-37500)/1000; //超声传感器公式150=a*0.4+b 900=a*2.0+b a=468.75 b=37.5
TPHD1 = a;
}
else {TPHD1 = 0;}
}
break;
case 0x01: //AIN0.1
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 2;
filter();
TPHD2= (sum/(N-2));
if(TPHD2》ADC04V)
{
TPHD2 = TPHD2 - 5;
a = (long)TPHD2*2500/4095; //放大1000倍,采集到1毫伏
a = (a*469-37500)/1000; //超声传感器公式150=a*0.4+b 900=a*2.0+b a=468.75 b=37.5
TPHD2 = a;
}
else {TPHD2 = 0;}
}
break;
case 0x04: //AIN0.4
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 3;
filter();
TEMP1= (sum/(N-2));
if(TEMP1》ADC04V)
{
KT1F = 1;
TEMP1 = TEMP1 - 5; //去掉偏移量
a = (long)TEMP1*2500/4095; //放大1000倍,采集到1毫伏
a = (long)(a*331-129000)/100; //线性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分别取313和125
TEMP1 = a; //两点标定法标定后取a = 368 b = 157
}
else {TEMP1 = 0;KT1F = 0;}
}
break;
case 0x05: //AIN0.5
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 4;
filter();
TEMP2= (sum/(N-2));
if(TEMP2》ADC04V)
{
KT2F = 1;
TEMP2 = TEMP2 - 5; //去掉偏移量
a = (long)TEMP2*2500/4095; //放大1000倍,采集到1毫伏
a = (long)(a*331-129000)/100; //线性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分别取313和125
TEMP2 = a;
}
else {TEMP2 = 0;KT2F = 0;}
}
break;
case 0x06: //AIN0.6
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 5;
filter();
TEMP3= (sum/(N-2));
if(TEMP3》ADC04V)
{
KT3F = 1;
TEMP3 = TEMP3 - 5; //去掉偏移量
a = (long)TEMP3*2500/4095; //放大1000倍,采集到1毫伏
a = (long)(a*331-129000)/100; //线性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分别取313和125
TEMP3 = a;
}
else {TEMP3 = 0;KT3F = 0;}
}
break;
case 0x07: //AIN0.7
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 6;
filter();
TEMP4= (sum/(N-2));
if(TEMP4》ADC04V)
{
KT4F = 1;
TEMP4 = TEMP4 - 5; //去掉偏移量
a = (long)TEMP4*2500/4095; //放大1000倍,采集到1毫伏
a = (long)(a*331-129000)/100; //线性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分别取313和125
TEMP4 = a;
}
else {TEMP4 = 0;KT4F = 0;}
}
break;
default:break;
}
}
void ADC1_ISR (void) interrupt 17
{
static uchar count1; // Loop counter
ADC1CN &=~(0x20); //清中断标志位
switch( AMX1SL ) //通道转换
{
case 0x03: //AIN1.3
ADCbuffer1[count1]=ADC1;
count1++;
if (count1 》 N-1)
{
count1 = 0;
ADC1CN &=~(0x80);
ADcount = 7;
filter();
HT= (sum/(N-2));
if(HT》40)
{
HTF = 1;
HT = HT -4;
HT = (long)(HT*HTA-HTB*100)/10;
}
else {HT = 0;HTF = 0;}
}
break;
case 0x02: //AIN1.2
ADCbuffer1[count1]=ADC1;
count1++;
if (count1 》 N-1)
{
count1 = 0;
ADC1CN &=~(0x80);
ADcount = 8;
filter();
HR= (sum/(N-2));
if(HR》40)
{
HRF = 1;
HR = HR-4;
HR = (long)(HR*HRA-HRB*100)/10;
}
else {HR = 0;HRF = 0;}
}
break;
case 0x01: //AIN1.1
ADCbuffer1[count1]=ADC1;
count1++;
if (count1 》 N-1)
{
count1 = 0;
ADC1CN &=~(0x80);
ADcount = 9;
filter();
HP1= (sum/(N-2));
if((HP1》40)&&(HP1《123)) //负向倾角
{
HPF = 0;
HP = HP1-4;
HP = (long)(HPB*100-HP*HPA)/10;
}
if((HP1》127)&&(HP1《=255)) //正向倾角
{
HPF = 1;
HP = HP1-4;
HP = (long)(HP*HPA-HPB*100)/10;
}
if((HP1》=123)&&(HP1《=127))
{
HPF = 2; //只显示0
HP = 0;
}
if(HP1《40)
{
HPF = 3; //未连接
}
}
break;
/* case 0x00: //AIN1.0
ADCbuffer1[count1]=ADC1;
count1++;
//ADC0CN |=0x10; //写ADC1BUSY位启动转换
if (count1 》 N-1){
count1 = 0;
ADC1CN &=~(0x80);
ADcount = 8;
}
break;*/
default:break;
}
}
评论
查看更多