|
楼主 |
发表于 2024-9-2 12:02:22
|
显示全部楼层
void scic_adcTXdata() //adc发送
{
EPwm2Regs.CMPA.all = 0;
ConversionCount_Tx = 0;
// while(ConversionCount_Tx<2000)
while(ConversionCount_Tx<adcTx)
{
for(i=12;i<buffer2size;i++) sendbuffer2[i] =0;
for(i=12; i<buffer2size; i++)
{
sendbuffer2[i] = voltage_adc1[ConversionCount_Tx];
ConversionCount_Tx++;
}
for(i=0;i<buffer2size;i++) scic_xmit(sendbuffer2[i]);
DELAY_US(20000);
}
/* for(loopcount=0;loopcount<10;loopcount++)
{
for(i=12;i<buffer2size;i++) sendbuffer2[i] =0;//1. 0-199
for(i = 12; i<buffer2size; i++)
{
sendbuffer2[i] = voltage_adc1[ConversionCount_Tx];
if(ConversionCount_Tx == (datasize*2-1)+loopcount*200)
{
ConversionCount_Tx = 0+loopcount*200;
}
else ConversionCount_Tx++;
}
for(i=0;i<buffer2size;i++) scic_xmit(sendbuffer2[i]);
}*/
}
//文本返回数组
Uint16 open_Char[14]={0x5A,0xA5,0x0B,0x82,0x50,0x50,0xD5,0xFD,0xD4,0xDA,0xD4,0xCB,0xD0,0xD0};//开机后显示文本:正在运行
Uint16 stop_Char[14]={0x5A,0xA5,0x0B,0x82,0x50,0x50,0xB4,0xED,0xCE,0xF3,0xCD,0xA3,0xBB,0xFA};//紧急停机后:错误停机
Uint16 relieve_Char[14]={0x5A,0xA5,0x0B,0x82,0x50,0x50,0xBD,0xE2,0xB3,0xFD,0xBE,0xAF,0xB1,0xA8};//解除告警后:解除警报
Uint16 para_ready_Char[18]={0x5A,0xA5,0x0F,0x82,0x50,0x50,0xB2,0xCE,0xCA,0xFD,0xC9,0xE8,0xD6,0xC3,0xCD,0xEA,0xB3,0xC9};//参数设定后:参数设置完成
Uint16 overI_Char[14]={0x5A,0xA5,0x0B,0x82,0x50,0x50,0xB9,0xFD,0xC1,0xF7,0xBE,0xAF,0xB8,0xE6};//过流警告
Uint16 overU_Char[14]={0x5A,0xA5,0x0B,0x82,0x50,0x50,0xB9,0xFD,0xD1,0xB9,0xBE,0xAF,0xB8,0xE6};//过压警告
Uint16 clear_Char[18]={0x5A,0xA5,0x0F,0x82,0x50,0x50,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};//清除文本
Uint16 date_rec_buf[15]={0};//接收RTC返回实时时间
Uint16 date_search[7]={0x5A,0xA5,0x04,0x83,0x00,0x10,0x04};//RTC查询指令
//volatile Uint16 date_Tx[25]={0x5A,0xA5,0x16,0x82,0x50,0x50,0x32,0x30,0x30,0x30,0x2D,0x30,0x30,0x2D,0x30,0x30,0x20,0x30,0x30,0x3A,0x30,0x30,0x3A,0x30,0x30};
Uint16 date_Tx[25]={0x5A,0xA5,0x16,0x82,0x50,0x50,0x32,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void scic_datapack()//等候数据接收
{
for(i1=0;i1<9; i1++)
{
recvbuff0[i1]=0;
}
//接收指令
if(flag_open==0)
{for(i = 0; i<9; i++)
{
while(ScicRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for XRDY =1 for empty state//等待从上位机收到一个字节的数据
recvbuff0[i] = ScicRegs.SCIRXBUF.all;
ScicRegs.SCIRXBUF.all=0;//每次接收后将缓冲区清零
}
}
else if(flag_open==1)
{
recvbuff0[0]=0x5A;
for(i = 1; i<9; i++)
{
while(ScicRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for XRDY =1 for empty state//等待从上位机收到一个字节的数据
recvbuff0[i] = ScicRegs.SCIRXBUF.all;
ScicRegs.SCIRXBUF.all=0;//每次接收后将缓冲区清零
}
}
if((recvbuff0[0]==0x5A) &&(recvbuff0[1]==0xA5))//校准帧头
{
if((recvbuff0[4]==0x60)&&(recvbuff0[5]==0x45))
{
if((recvbuff0[7]==0x12)&&(recvbuff0[8]==0x0A))//1.开机 120A
{ open_cmd();
for(i1=0;i1<9; i1++) recvbuff0[i1]=0;
time_read();
date_Tx[4]+=i3;
for(i1=0;i1<25;i1++) scic_xmit(date_Tx[i1]); //发送时间
DELAY_US(100);
date_Tx[4]=0x50;
open_Char[4]+=i4;
clear_Char[4]+=i4;
for(i1=0;i1<18;i1++) scic_xmit(clear_Char[i1]); //清除文本
DELAY_US(100);
for(i1=0;i1<14;i1++) scic_xmit(open_Char[i1]); //开机返回文本
open_Char[4]=0x50;
clear_Char[4]=0x50;
i3+=2;
i4+=2;
flag_open=1;
}
else if((recvbuff0[7]==0x13)&&(recvbuff0[8]==0x0B))//2.紧急关机 130B
{
close_cmd();
for(i1=0;i1<9; i1++) recvbuff0[i1]=0;
time_read();
date_Tx[4]+=i3;
for(i1=0;i1<25;i1++) scic_xmit(date_Tx[i1]); //发送时间
DELAY_US(100);
date_Tx[4]=0x50;
stop_Char[4]+=i4;
clear_Char[4]+=i4;
for(i1=0;i1<18;i1++) scic_xmit(clear_Char[i1]); //清除文本
DELAY_US(100);
for(i1=0;i1<14;i1++) scic_xmit(stop_Char[i1]);//紧急停机返回文本
stop_Char[4]=0x50;
clear_Char[4]=0x50;
DELAY_US(100);
i3+=2;
i4+=2;
flag_open=0;
}
else if((recvbuff0[7]==0x14)&&(recvbuff0[8]==0x0C))//3.解除告警 140C
{ //GpioDataRegs.GPCCLEAR.bit.GPIO64 = 1;//蜂鸣器告警解除
for(i1=0;i1<9; i1++) recvbuff0[i1]=0;
// for(i1=0;i1<18;i1++) scib_xmit(clear_Char[i1]); //清除文本
time_read();
date_Tx[4]+=i3;
for(i1=0;i1<25;i1++) scic_xmit(date_Tx[i1]); //发送时间
DELAY_US(100);
date_Tx[4]=0x50;
relieve_Char[4]+=i4;
clear_Char[4]+=i4;
for(i1=0;i1<18;i1++) scic_xmit(clear_Char[i1]); //清除文本
DELAY_US(100);
for(i1=0;i1<14;i1++) scic_xmit(relieve_Char[i1]);
relieve_Char[4]=0x50;
clear_Char[4]=0x50;
DELAY_US(100);
i3+=2;
i4+=2;
flag_open=0;
}
else if((recvbuff0[7]==0x11)&&(recvbuff0[8]==0x0D))//4.参数设置 110D
{
para_read();
for(i1=0;i1<9; i1++) recvbuff0[i1]=0;
DELAY_US(100);
para_rec_service_sci();
DELAY_US(100);
// for(i1=0;i1<18;i1++) scib_xmit(clear_Char[i1]); //清除文本
time_read();
date_Tx[4]+=i3;
for(i1=0;i1<25;i1++) scic_xmit(date_Tx[i1]); //发送时间
DELAY_US(100);
date_Tx[4]=0x50;
para_ready_Char[4]+=i4;
clear_Char[4]+=i4;
for(i1=0;i1<18;i1++) scic_xmit(clear_Char[i1]); //清除文本
DELAY_US(100);
for(i1=0;i1<18;i1++) scic_xmit(para_ready_Char[i1]);
para_ready_Char[4]=0x50;
clear_Char[4]=0x50;
DELAY_US(100);
i3+=2;
i4+=2;
}
}
}
if(i3>4) i3=0;
if(i4>5) i4=1;
DELAY_US(100000);
// ScicRegs.SCIRXBUF.all=0;
}
void para_read()//参数数据读取
{
// for(readcount=0;readcount<para_set_size*2-1;readcount+=2)
// {
for(i0=0;i0<para_set_size;i0++)
{
unsigned int read_pack[7]={0x5A,0xA5,0x04,0x83,0x60,0x01,0x01}; //发送查询指令,并接收返回的数据存入para_set数组 参数地址6001
read_pack[5]+=readcount;//对第6位参数地址进行修改
for(i1=0;i1<7;i1++) scic_xmit(read_pack[i1]); //读取变量地址为1001开始的参数,参数长度为01
for(i1=0;i1<9; i1++) recvbuff3[i1]=0;
DELAY_US(1000);
for(i1= 0;i1<9; i1++)
{
while(ScicRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for XRDY =1 for empty state//等待从上位机收到一个字节的数据
recvbuff3[i1] = ScicRegs.SCIRXBUF.all;
ScicRegs.SCIRXBUF.all=0;//每次接收后将缓冲区清零
}
if((recvbuff3[0]==0x5A) &&(recvbuff3[1]==0xA5))// 对比帧头后,数据处理
{ re_tmp_16=recvbuff3[7]<<8|recvbuff3[8];//956(十),0x03BC
recv_use=re_tmp_16;
recv_use=recv_use*0.1;
}
if((recvbuff3[3]==0x83)&&(recvbuff3[4]==0x60))//83表示读指令,60为变量地址高两位
{
a=recvbuff3[5];
para_set[a-1]=recv_use;
}
if(readcount==para_set_size-1) readcount=0;
else readcount+=1;
DELAY_US(1000);
}
}
void time_read()
{
for(i1=0;i1<7;i1++) scic_xmit(date_search[i1]); //查询日期
DELAY_US(100);
for(i1=0;i1<15; i1++) date_rec_buf[i1]=0;//
DELAY_US(100);
for(i1= 0;i1<15; i1++)
{
while(ScicRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for XRDY =1 for empty state//等待从上位机收到一个字节的数据
date_rec_buf[i1] = ScicRegs.SCIRXBUF.all;
ScicRegs.SCIRXBUF.all=0;//每次接收后将缓冲区清零
}
DELAY_US(100);
for(i1=8;i1<25;i1++) date_Tx[i1]=0;
DELAY_US(100);
date_Tx[8]=0x30+(date_rec_buf[7]/10%10);
date_Tx[9]=0x30+(date_rec_buf[7]%10); //年
date_Tx[10]=0x2D;
date_Tx[11]=0x30+(date_rec_buf[8]/10%10);
date_Tx[12]=0x30+(date_rec_buf[8]%10); //月
date_Tx[13]=0x2D;
date_Tx[14]=0x30+(date_rec_buf[9]/10%10);
date_Tx[15]=0x30+(date_rec_buf[9]%10); //日
date_Tx[16]=0x20;
date_Tx[17]=0x30+(date_rec_buf[11]/10%10);
date_Tx[18]=0x30+(date_rec_buf[11]%10); //时
date_Tx[19]=0x3A;
date_Tx[20]=0x30+(date_rec_buf[12]/10%10);
date_Tx[21]=0x30+(date_rec_buf[12]%10); //分
date_Tx[22]=0x3A;
date_Tx[23]=0x30+(date_rec_buf[13]/10%10);
date_Tx[24]=0x30+(date_rec_buf[13]%10); //秒
} |
|