📄 xlbh.c
字号:
/* end for UPdata */
//disp();
if(viewfirst==1){gcls();page00();viewfirst=0;}
page0();
} /* for Num_pin==4 */
/* for(t4=0;t4<4;t4++) *(lepq+t4)=epq[t4]; */
if( ++chk_num > 180000) { writetram(); chk_num=0; }
anykey();
//f=(f4/24)+(f>>1);
//if (f>2300||f<2180); f=2222;
//if (f>2978||f<2640); //szb
f=2778;
tttt=~f;
fl=(unsigned char)tttt; fh=(unsigned char)(tttt>>8);
goto l1;
}
/*///////////////////////////////////////////////////////////////////////////*/
/*/////////////////////////// time0 /////////////////////////////////////*/
/*//////////////////////////////////////////////////////////////////////////*/
void time0() interrupt 1 using 1
{ /* begin for time0 */
unsigned int data t[12],temp, f_t1, mm;
unsigned char data nn,nnn;
unsigned char *kpp;
//int idata temp1,temp2,temp3,temp4;
TR0=0; TL0=fl;TH0=fh; TR0=1; //1.67ms
#if BB35
XBYTE[AD1]=0x48; while(P3_2==1) ;
t[0]=*((unsigned int xdata *)(AD1));
XBYTE[AD1]=0x49; while(P3_2==1) ;
t[1]=*((unsigned int xdata *)(AD1));
XBYTE[AD1]=0x4a; while(P3_2==1) ;
t[2]=*((unsigned int xdata *)(AD1));
XBYTE[AD1]=0x4b; while(P3_2==1) ;
t[3]=*((unsigned int xdata *)(AD1));
XBYTE[AD1]=0x4c; while(P3_2==1) ;
t[4]=*((unsigned int xdata *)(AD1));
XBYTE[AD1]=0x4d; while(P3_2==1) ;
t[5]=*((unsigned int xdata *)(AD1));
XBYTE[AD1]=0x4e; while(P3_2==1) ;
t[6]=*((unsigned int xdata *)(AD1));
XBYTE[AD1]=0x4f; while(P3_2==1) ;
t[7]=*((unsigned int xdata *)(AD1));
XBYTE[AD2]=0x48; while(P3_1==1) ;
t[8]=*((unsigned int xdata *)(AD2));
XBYTE[AD2]=0x49; while(P3_1==1) ;
t[9]=*((unsigned int xdata *)(AD2));
XBYTE[AD2]=0x4a; while(P3_1==1) ;
t[10]=*((unsigned int xdata *)(AD2));
// XBYTE[AD2]=0x4b; while(P3_1==1) ;
// t[11]=*((unsigned int xdata *)(AD2));
#endif
i++; time_counter++; time1_counter++; ch_counter++;
#if NBC
f_t1=0;D[i]=t[0];
for(temp=1;temp < Num_ch;temp++)
{
f_t1=f_t1+256;
D[f_t1+i]=t[temp];
}
#endif
//fuxu
ij=i-2;
D[256*12+i] =((int)((long)D[256*2+i]-D[256*3+i]
+D[256*3+ij]-D[256*4+ij]))>>3;
// D[256*12+i] =((int)((long)D[256*9+i]-D[256*10+i]
// +D[256*10+ij]-D[256*11+ij]))>>3;
f3=(unsigned int)RCAP2H;
f2=(f3<<8)+RCAP2L; /* read T form Timer 2 capture */
if(f2!=f1 && P1_1==0 ) f5++;
if(f5>=2)
{ f5=0; f4=f2-f1; f1=f2;
fj_num++ ; fj[fj_num]=f4; }
/* end for f measurement */
/* year month day hour minute second ms */
if(++ms>=ms_num) ms=0;
if( *((unsigned char xdata *)(IDT+0x0260)) == 0x55
&&*((unsigned char xdata *)(IDT+0x0260+9)) == 0x55 )
{
if(t_mark==0)
{ t_mark=1;
for(nn=0;nn<=7;nn++)
{
time[nn]=*((unsigned char xdata *)(IDT+0x0261+nn));
}
ms=( ((unsigned int)time[7]<<8) + time[6] )*ms_1/5+1;
}
if(ms==0){
XBYTE[TIM+10]=0xa6; XBYTE[TIM+11]=0xba;
XBYTE[TIM+9]=time[0]; XBYTE[TIM+8]=time[1];
XBYTE[TIM+7]=time[2]; XBYTE[TIM+4]=time[3];
XBYTE[TIM+2]=time[4]; XBYTE[TIM]=time[5]+1;
XBYTE[TIM+11]=0x0a;
XBYTE[IDT+0x0260]=0; XBYTE[IDT+0x0260+9]=0; t_mark=0;
}
} else
{
if( sec_temp1= *((unsigned char xdata *)TIM),sec_temp1 != sec_temp2)
{ sec_temp2=sec_temp1; ms=0; }
}
/* IN1 and IN2 chang status */
t[0]=*((unsigned char xdata *)IN1);
t[1]=*((unsigned char xdata *)IN1);
t[2]=*((unsigned char xdata *)IN2);
t[3]=*((unsigned char xdata *)IN2);
if(t[0]==t[1] && t[2]==t[3] && in_k==1)
{ temp=t[0]+(t[2]<<8);
if( (temp&0x0fff) != (i5&0x0fff) )
{ kpp=(unsigned char *)(&ms);
mm=1;
for(nn=0;nn<12;nn++)
{ nnn=nn<<3;
if( (temp&mm) != (i5&mm) )
{
if(bz1[0+nnn]==0) {
bz1[1+nnn]=*((unsigned char xdata *)(TIM+4));
bz1[2+nnn]=*((unsigned char xdata *)(TIM+2));
bz1[3+nnn]=*((unsigned char xdata *)TIM);
bz1[4+nnn]=*(kpp+1);
bz1[5+nnn]=*kpp;
kpp=(unsigned char *)(&i5);
bz1[6+nnn]=*(kpp+1);
bz1[7+nnn]=*kpp; }
bz1[0+nnn]++;
if(bz1[0+nnn]>=60) {
/* i5=i5|(temp&mm); */
i5=(i5&(0x3fff^mm))|(temp&mm);
if((BSOE&mm)!=0x0000)
{trip0=1;
f_t1=(unsigned int)bz[1539]*6;
bz[f_t1+0]=*((unsigned char xdata *)(TIM+9));
bz[f_t1+1]=*((unsigned char xdata *)(TIM+8));
bz[f_t1+2]=*((unsigned char xdata *)(TIM+7));
bz[f_t1+3]=bz1[1+nnn];
bz[f_t1+4]=bz1[2+nnn];
bz[f_t1+5]=bz1[3+nnn];
bz[f_t1+6]=bz1[4+nnn];
bz[f_t1+7]=bz1[5+nnn];
bz[f_t1+8]=nn+1;
if((temp&mm)==0)
bz[f_t1+9]=0; else bz[f_t1+9]=1;
bz[f_t1+11]=bz1[6+nnn]; bz[f_t1+12]=bz1[7+nnn];
kpp=(unsigned char *)(&i5);
bz[f_t1+13]=*(kpp+1); bz[f_t1+14]=*kpp;
bz[1539]+=4;
}
bz1[0+nnn]=0;
}
} else { bz1[0+nnn]=0;}
mm=mm<<1;
}
}
}
} /* end for time0 */
/*///////////////////////////////////////////////////////////////////////*/
/*////////////////////////// time1 //////////////////////////////////*/
/*//////////////////////////////////////////////////////////////////////*/
void time1() interrupt 3 using 2
{ /* begin for time1 */
unsigned char *sjpp;
// unsigned char nnn;//,times;
unsigned char idata nn,mm;
unsigned int idata temp1,temp2;
unsigned char idata temp3,temp4;
int data ttt;//,ttt1;
// int ttemp2,ttemp3,ttemp4,ttemp5,ttemp6,ttemp7,ttemp8,p_h,p_m,p_l;
//long U1r, U1x;
/* Watchdog */
if( (i != w_i) && p_counter < 60000) { TA=0xaa; TA=0x55; RWT=1; m++; }
w_i=i; XBYTE[IDT+2]=m; k_counter++; p_counter++;
/////////////////////////////////////// for PSD954
if((time_counter&0x0100)==0) //RUN LED flash
P4=P4&0xfe;
else
P4=P4|0x01;
//////////////////////////////////////////////////
P1_0=0; /* set watchdog */
//iii++;
// if((iii&0x0100)==0)
// {o2=o2|0x1f;XBYTE[OUT1]=o2;XBYTE[OUT2]=o2;}
// else
// {o2=o2&0x00;XBYTE[OUT1]=o2;XBYTE[OUT2]=o2;iii=0;}
#if BB35
TR1=0; TL1=0x6c;TH1=0x00; TR1=1;//39ms
ii=i-12;
for(jjj=2;jjj < 11;jjj++)
{
if(jjj==9) continue;
jj=jjj*256;
ttt=(int)((long)D[j=ii+2,jj+j] - D[j=ii+8,jj+j]+ D[j=ii+4,jj+j] - D[j=ii+10,jj+j]);
tr[jjj] = (int)((long)D[j=ii+1,jj+j] - D[j=ii+7,jj+j] + D[j=ii+5,jj+j] - D[j=ii+11,jj+j])
+ ((int)((long)D[j=ii+3,jj+j] - D[j=ii+9,jj+j])<<1) + ((ttt<<1)-(ttt>>2)-(ttt>>6));
ttt=(int)((long)D[j=ii+1,jj+j] - D[j=ii+7,jj+j]
+ D[j=ii+11,jj+j] - D[j=ii+5,jj+j]);
tx[jjj] = (int)((long)D[j=ii+2,jj+j] - D[j=ii+8,jj+j] + D[j=ii+10,jj+j] - D[j=ii+4,jj+j])
+ ((int)((long)D[j=ii+12,jj+j]-D[j=ii+6,jj+j])<<1) +((ttt<<1)-(ttt>>2)-(ttt>>6));
}
/* begin for protection */
if(prun == 0)
{
s1=(long)tr[5] * tr[5] + (long)tx[5] * tx[5]; /* Ia */
s2=(long)tr[6] * tr[6] + (long)tx[6] * tx[6]; /* Ib */
s3=(long)tr[7] * tr[7] + (long)tx[7] * tx[7]; /* Ic */
if((s1>=s2)&&(s1>=s3)) { st=3; s7=s1; }
else {if((s2>=s1)&&(s2>=s3)){ st=4; s7=s2; }
else { st=2; s7=s3; }
}
if(st==4)
{s1=((long)tr[4]-tr[2])>>3;//Uca
s2=((long)tx[4]-tx[2])>>3;
}
else
{
s1=((long)tr[st]-tr[st+1])>>3;
s2=((long)tx[st]-tx[st+1])>>3;
}
/*************
s3=(((long)s1*94)>>7)-(((long)s2*87)>>7);
s4=(((long)s1*87)>>7)+(((long)s2*94)>>7);
s5=(((long)s1*87)>>7)-(((long)s2*94)>>7);
s2=(((long)s1*94)>>7)+(((long)s2*87)>>7);
**********/
s3=s1-s2; s4=s1+s2;
if(st==3)
{ s6= s3*(long)tr[5] + s4*(long)tx[5];}//s4= s5*(long)tr[5] + s2*(long)tx[5];}
if(st==4)
{ s6= s3*(long)tr[6] + s4*(long)tx[6];}//s4= s5*(long)tr[6] + s2*(long)tx[6];}
if(st==2)
{ s6= s3*(long)tr[7] + s4*(long)tx[7];}//s4= s5*(long)tr[7] + s2*(long)tx[7];}
s3=s1*s1+s2*s2; if(s3<300) s6=-1;else s6=1;
if(st==3) s1=(long)tr[2] * tr[2] + (long)tx[2] * tx[2];//Ua
if(st==4) s1=(long)tr[3] * tr[3] + (long)tx[3] * tx[3];//Ub
if(st==2) s1=(long)tr[4] * tr[4] + (long)tx[4] * tx[4];//Uc
if( ( s6>0 || (pro2&0x08)==0 ) && (pro1&0x01)==0x01 && s7 >= e[0] ) /* 1 */
{P1_3=1; P1_5=0;o1=o1|0x04; XBYTE[OUT1]=o1; trip=1;o2=o2|0x41;
k1=1; w1=w1|0x0001; dz_mark=1;trip0=1;recval[0]=s7; thdz_mark=1;
//if(k11==0){lbbz1=1;k11=1;}
}
else { if( s7<(e[0]-(e[0]>>2)))
{ k1=0; /*k11=0;*/ w1=w1&0xfffe; } }
if( (s6>0 || (pro2&0x10)==0 ) && (pro1&0x02)==0x02 && s7 >= e[1] ) /* 2 */
{if( jjj=time_counter-rt[1],jjj > et[0] )
{ P1_3=1; P1_5=0;o1=o1|0x04; trip=1;XBYTE[OUT1]=o1; thdz_mark=1; o2=o2|0x41;
k2=1; w1=w1|0x0002; dz_mark=1;trip0=1;recval[1]=s7;}
if(js_mark==1 && (pro2&0x01)==0x01 && (jjj=time_counter-rt[1],jjj > et[7]) )
{ P1_3=1; P1_5=0;o1=o1|0x04; trip=1;XBYTE[OUT1]=o1;o2=o2|0x41; thdz_mark=1;
k2=1; w1=w1|0x0010; dz_mark=1;trip0=1;recval[4]=s7;}
// if(k22==0){lbbz1=1;k22=1;}
}
else { if( s7<(e[1]-(e[1]>>2)) )
{ rt[1] = time_counter; k2=0; w1=w1&0xffed; }
}
if( ( s6>0 || (pro2&0x20)==0 ) && (pro1&0x04)==0x04 && s7 >= e[2] && (s1 < e[5] || (pro1&0x40)==0x00 )) /* 3 */
{if( jjj=time_counter-rt[2],jjj > et[1] )
{ P1_3=1; P1_5=0; o1=o1|0x04; XBYTE[OUT1]=o1;trip=1;o2=o2|0x41;
k3=1; w1=w1|0x0004; dz_mark=1; thdz_mark=1;trip0=1;recval[2]=s7;}
if(js_mark==1 && (pro2&0x01)==0x01 && (jjj=time_counter-rt[2],jjj > et[7]) )
{ P1_3=1; P1_5=0; o1=o1|0x04; XBYTE[OUT1]=o1;trip=1; o2=o2|0x41;
k3=1; w1=w1|0x0800; dz_mark=1; thdz_mark=1;trip0=1;recval[11]=s7;}
// if(k33==0){lbbz1=1;k33=1;}
}
else { if( s7<(e[2]-(e[2]>>2)) )
{ rt[2] = time_counter; k3=0; w1=w1&0xf7fb; }
}
/*******
if((pro1&0x08)==0x08 && s7 >= e[12] ) //4
{if( jjj=time_counter-rt[14],jjj > et[9] )
{ trip0=1;
k9=1; if((pro2&0x80)==0x80) {P1_3=1; P1_5=0; o1=o1|0x04;trip=1; thdz_mark=1;
XBYTE[OUT1]=o1;o2=o2|0x41;w1=w1|0x0040;recval[6]=s7;}
else {o2=o2|0x82;w1=w1|0x1000;} }
// if(k99==0){lbbz1=1;k99=1;}
}
else { if( s7<(e[12]-(e[12]>>2)) )
{ rt[14] = time_counter; k9=0; w1=w1&0xefbf; }
}
**************/
s1=(long)tr[8]*tr[8]+(long)tx[8]*tx[8];
if((pro1&0x10)==0x10&&s1>=e[6])
{
if( jjj=time_counter-rt[8],jjj > et[8] )
{ o2=o2|0x82;
k6=1; w1=w1|0x0008; trip0=1;
}
}
else { if( s1<(e[6]-(e[6]>>2)))
{ k6=0; w1=w1&0xfff7; rt[8]=time_counter; }
}
/*********
if((pro1&0x20)==0x20&&s1>=e[13])
{if( jjj=time_counter-rt[4],jjj > et[10] )
{ P1_3=1; P1_5=0; o1=o1|0x04;trip=1; XBYTE[OUT1]=o1;o2=o2|0x41;
k7=1; w1=w1|0x0400; trip0=1; thdz_mark=1;
}
}
else { if( s1<(e[13]-(e[13]>>2)))
{ k7=0; k77=0; w1=w1&0xfbff; rt[4]=time_counter; }
}
***************/
//jilei
#if FOUT/*conghe cha*/
if(dz_mark==1 /*|| (i3&0x01)==0x01 && (((unsigned char)i5)&0x01) == 0*/)
{ qd_mark=1; dz_mark=0; }
i3=(unsigned char)i5;
if(ch_counter>=9000) ch_counter=9000;
//if((((unsigned char)i5)&0x04) == 0x04) ch_counter=0;
if((i5&0x1000)==0x1000) ch_counter=0;//houma
if(ch_counter>=9000 && qd_mark==1 )
{ s1=((long)tr[2]-tr[3]-tr[10])>>1;
s2=((long)tx[2]-tx[3]-tx[10])>>1; /* dUt */
s3=s1*s1+s2*s2;
s4=((long)tr[10] * tr[10] + (long)tx[10] * tx[10])>>2; /* Ut */
if( (pro1&0x80)==0x80 && (i3&0x03) == 0x02 && s7<e[11] &&
((pro1&0x08)==0 || s4<e[12] )&&((pro2&0x80)==0||((s3*e[4]) < s4 )&&s3<e[10])) /*an quan chong he zha*/
{ if(jjj=time_counter-rt[6],jjj > et[2])
{ P1_3=1; P1_5=0;o1=o1|0x01; XBYTE[OUT1]=o1;
o2=o2|0x82; thdz_mark=1;js_mark=1; k=1; w1=w1|0x0020; ch_mark=1; qd_mark=0;trip=1;
ch_counter=0; rt[6]=time_counter;trip0=1;
}
}
else { if(jjj=time_counter-rt[6],jjj > 6000) { qd_mark=0; w1=w1&0xffdf;}}
}
else { rt[6]= time_counter; qd_mark=0; w1=w1&0xffdf; }
if( ch_mark== 0 ) rt[0]=time_counter; /* ch_mark working */
else {
if(jjj=time_counter-rt[0],jjj > 1200)
{ o1=o1&0xfe; XBYTE[OUT1]=o1; ch_mark=0; }
}
//////////////////////
/* heza js */
if((i4&0x01)==0x01 && (((unsigned char)i5)&0x01) == 0x00 )//my
{ js_mark=1; ch_counter=0; }
//i4=(unsigned char)i5;
if( js_mark == 0 ) rt[7]=time_counter; /* js_mark working */
else if(jjj=time_counter-rt[7],jjj > 1200) js_mark=0;
/* end for chonghe */
s1= (long)tr[2]*tr[2]+(long)tx[2]*tx[2];
if( (pro2&0x02)==0x02 && f4 > e[3] && s1>e[5]&&(((unsigned char)i5)&0x01)==0x01 ) // low f1 have delay
{if( (s1 > e[5] || (pro1&0x40)==0x00) && (166666666/fj[j=fj_num-10,j]-166666666/fj[fj_num] < et[4]) )
{
if( (jjj=time_counter-rt[9],jjj > et[3]) )
{ P1_3=1; P1_5=0;o1=o1|0x04; XBYTE[OUT1]=o1;recval[8]=f4;
o2=o2|0x41; w1=w1|0x0100; ch_counter=0;k8=1; thdz_mark=1;trip0=1; trip=1;}
}
}
else { rt[9] = time_counter; k8=0; w1=w1&0xfeff;}
#endif
if( (pro1&0x20)==0x20 && f4 > e[13] && s1>e[5] ) // low f2 have delay
{
if( (s1 > e[5] || (pro1&0x40)==0x00 )
&& (jjj=time_counter-rt[4],jjj > et[10]) )
// if( (pro2&0x40)==0x40 && f4 > e[6] && s3 < e[5] && s3>e[7] )
//&& (jjj=time_counter-rt[14],jjj > et[8])) // off
{ P1_3=1; P1_5=0;o1=o1|0x04; XBYTE[OUT1]=o1;thdz_mark=1;
o2=o2|0x41;k7=1; w1=w1|0x8000; ch_counter=0;recval[15]=f4;trip=trip0=1;}
}
else
{ rt[4]=time_counter; k7=0; w1=w1&0x7fff; }
#if FIN
if ((pro2&0x40)==0x40)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -