📄 uart1.c
字号:
pu1_command++;
if (u1_count==0)
{ b_g_long=u1_datalen[0]*256;
b_g_long=b_g_long+u1_datalen[1];
if (b_g_long!=0)
u1_receflag=5;
else
u1_receflag=12; //////////////////
}
break;
case 5:
if (u1_acc==0xd7)
u1_receflag=6;
else
u1_receflag=100;
break;
case 6:
if (u1_acc==0x01)
{ u1_receflag=7;
u1_count=2;
pu1_command=temp_object;
}
else
u1_receflag=100;
break;
case 7:
u1_count--;
*pu1_command=u1_acc;
pu1_command++;
if (u1_count==0)
{ u1_receflag=8;
u1_count=2;
pu1_command=u1_datalen;
}
break;
case 8:
u1_count--;
*pu1_command=u1_acc;
pu1_command++;
if (u1_count==0)
{ u1_dlenght=u1_datalen[0]*256;//+r1_datalen[2];
u1_dlenght+=u1_datalen[1];
u0_sendlen=u1_dlenght;
u1_receflag=9;
}
break;
case 9:
u1_dlenght--;
datain(u1_acc);
if (u1_dlenght==0)
{ u1_receflag=10;
}
break;
case 10:
if (u1_acc==0x0d)
{ if (system_status==0x01)
{ object[0]=temp_object[0];
object[1]=temp_object[1];
u1_receflag=0; //send data to GPRS
t0_rtflag=1;
u0_sendflag=16;
T0TC=10782720;
}
else
{ u1_bfailure();
dlcsh();
}
}
else
{ u1_receflag=100;
dlcsh();
}
break;
case 11:
if (u1_acc==0x0d)
{ data_buf[0]=b_address[0];
data_buf[1]=b_address[1];
if (moni_rece_time!=0)
{ mout();
u1_acc=mdl_regist;
mout();
u1_sendlong=u1_acc*256+mdl_regist;
u1_sendlen=u1_sendlong+6;
data_buf[2]=u1_sendlen>>8;
data_buf[3]=u1_sendlen & 0xff;
data_buf[4]=0xd7;
data_buf[5]=0x01;
mout();
data_buf[6]=mdl_regist;
mout();
data_buf[7]=mdl_regist;
data_buf[8]=u1_sendlong>>8;
data_buf[9]=u1_sendlong & 0xff;
moni_rece_time--;
u1_sendlen=10;
u1_sendflag=1;
}
else
{ data_buf[2]=0x00;
data_buf[3]=0x00;
data_buf[4]=0x0d;
u1_sendlen=5;
u1_sendflag=0;
}
u1_receflag=0;
pu1_command=data_buf;
U1THR='!';
}
else
u1_receflag=100;
break;
case 12:
if (u1_acc==0x0d)
{ data_buf[0]=b_address[0];
data_buf[1]=b_address[1];
if (u0_sendstatus==0)
data_buf[2]=0x30;
else
data_buf[2]=0x31;
data_buf[3]=0x0d;
pu1_command=data_buf;
u1_receflag=0;
u1_sendlen=4;
U1THR='!';
u1_sendflag=0;
}
else
u1_receflag=10;
break;
case 13:
if (u1_acc==0x0d)
{ /*data_buf[0]=b_address[0];
data_buf[1]=b_address[1];
data_buf[2]='2';
data_buf[3]='0';
data_buf[4]='0';
data_buf[5]='0';
data_buf[6]=0x0d;
pu1_command=data_buf;
u1_receflag=0;
u1_sendlen=7;
U1THR='!';
u1_sendflag=0; */
read_name();
}
else
u1_receflag=100;
break;
case 100:
if (u1_acc==0x0d)
{ data_buf[0]=b_address[0];
data_buf[1]=b_address[1];
data_buf[2]=0x0d;
u1_receflag=0;
u1_sendlen=3;
pu1_command=data_buf;
if (u1_sendflag==100)
U1THR='?';
u1_sendflag=0;
}
break;
}
}
else // 被动模式下的透明传输
{ switch (u1_receflag)
{ case 0:
if (u1_acc=='$')
u1_receflag=1;
break;
case 1:
if (u1_acc==b_address[0])
u1_receflag=2;
else
u1_receflag=0;
break;
case 2:
if (u1_acc==b_address[1])
u1_receflag=3;
else
u1_receflag=0;
break;
case 3:
if (u1_acc=='W')
{ u1_count=2;
pu1_command=u1_datalen;
u1_receflag=4;
}
else if (u1_acc=='R')
{ u1_receflag=7;
}
else if (u1_acc=='M')
u1_receflag=11;
else
u1_receflag=10;
break;
case 4:
u1_count--;
*pu1_command=u1_acc;
pu1_command++;
if (u1_count==0)
{
u1_dlenght=u1_datalen[0]*256;//+r1_datalen[2];
u1_dlenght+=u1_datalen[1];
u0_sendlen=u1_dlenght;
if (u1_dlenght!=0)
u1_receflag=5;
else
u1_receflag=8;
}
break;
case 5:
u1_dlenght--;
datain(u1_acc);
if (u1_dlenght==0)
u1_receflag=6;
break;
case 6:
if (u1_acc==0x0d)
{ if (system_status==0x01)
{ u1_receflag=0; //send data to GPRS
t0_rtflag=1;
u0_sendflag=16;
T0TC=10782720;
}
else
{ dlcsh();
u1_bfailure();
}
}
else
u1_receflag=10;
break;
case 7:
if (u1_acc==0x0d)
{ data_buf[0]=b_address[0];
data_buf[1]=b_address[1];
if (moni_rece_time!=0)
{ mout();
u1_acc=mdl_regist;
mout();
u1_sendlong=u1_acc*256+mdl_regist;
data_buf[2]=u1_acc;
data_buf[3]=mdl_regist;
mout();
mout();
u1_sendlen=4;
u1_sendflag=1;
moni_rece_time--;
}
else
{ data_buf[2]=0x00;
data_buf[3]=0x00;
data_buf[4]=0x0d;
u1_sendlen=5;
u1_sendflag=0;
}
pu1_command=data_buf;
u1_receflag=0;
U1THR='!';
}
else
u1_receflag=10;
break;
case 8:
if (u1_acc==0x0d)
{ data_buf[0]=b_address[0];
data_buf[1]=b_address[1];
if (u0_sendstatus==0)
data_buf[2]=0x30;
else
data_buf[2]=0x31;
data_buf[3]=0x0d;
pu1_command=data_buf;
u1_receflag=0;
u1_sendlen=4;
U1THR='!';
u1_sendflag=0;
}
else
u1_receflag=10;
break;
case 10:
if (u1_acc==0x0d)
{ data_buf[0]=b_address[0];
data_buf[1]=b_address[1];
data_buf[2]=0x0d;
u1_receflag=0;
u1_sendlen=3;
pu1_command=data_buf;
if (u1_sendflag==100)
U1THR='?';
u1_sendflag=0;
}
break;
case 11:
if (u1_acc==0x0d)
{/* data_buf[0]=b_address[0];
data_buf[1]=b_address[1];
data_buf[2]='2';
data_buf[3]='0';
data_buf[4]='0';
data_buf[5]='0';
data_buf[6]=0x0d;
pu1_command=data_buf;
u1_receflag=0;
u1_sendlen=7;
U1THR='!';
u1_sendflag=0; */
read_name();
}
else
u1_receflag=10;
break;
}
}
}
else //主动模式
{ if (gt_quomodo!=0) //格式传输
{ u1_gdata_count=6;
switch (u1_receflag)
{ case 0: //receive head
if (u1_acc==0xd7)
{ u1_receflag=1;
u1_gdata_=0x01;
}
break;
case 1: //receive command head
if (u1_acc==0x01)
{ u1_receflag=2;
u1_count=2;
pu1_command=temp_object;
}
else
u1_receflag=0;
break;
case 2: //receive user object address
*pu1_command=u1_acc;
pu1_command++;
u1_count--;
if (u1_count==0)
{ u1_receflag=3;
u1_count=2;
pu1_command=u1_datalen;
}
break;
case 3: //receive user data lenght
*pu1_command=u1_acc;
pu1_command++;
u1_count-- ;
if (u1_count==0)
{ u1_receflag=4;
u1_dlenght=u1_datalen[0]*256;//+r1_datalen[2];
u1_dlenght+=u1_datalen[1];
u0_sendlen=u1_dlenght;
}
break;
case 4: //receive user data
u1_dlenght--;
datain(u1_acc);
if (u1_dlenght==0)
{ u1_gdata_=0;
if (system_status==0x01)
{ object[0]=temp_object[0];
object[1]=temp_object[1];
u1_receflag=0; //send data to GPRS
t0_rtflag=1;
u0_sendflag=16;
T0TC=10782720;
}
else
{ u1_command[0]=0xff;
dlcsh();
u1_sendlen=1;
u1send_command();
}
}
break;
}
}
else //透明传输
{ datain(u1_acc);
switch (tou_status)
{ case 0:
if (start_address==1)
{ p_address=zhutai_address;
*p_address++=u1_acc;
addr_len--;
if (addr_len!=0)
{ tou_status=1;
}
else
{ tou_status=2;
}
}
else
start_address--;
break;
case 1:
*p_address++=u1_acc;
addr_len--;
if (addr_len==0)
tou_status=2;
break;
case 2:
break;
}
//T1TC=0x00000000;
//T1TCR=0x01;
u1_data_=0x01;
u1_data_count=6;
}
}
}
}
rst_dog();
VICIntSelect=0x00;
VICVectAddr=0x00;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -