Demo entry 6738409

gaotie

   

Submitted by s on May 04, 2018 at 08:00
Language: C++. Code size: 4.7 kB.

if(SCI_Num>=10000)
{
	SCI_Num = 1;
}
else
{
	SCI_Num = SCI_Num + 1;
}
//发送时序:17 260 3000 5200 6000 7800 9000 17
if(SCI_Num==(sending03))
{
	rec_pointer = 0;
	send03 = 1;//执行频率:10000分频
}
else if(SCI_Num%(sending05)==0)
{
	rec_pointer = 0;
	send05 = 1;//执行频率:10000中执行3次
}
else if(SCI_Num%(sending06)==0)
{
	rec_pointer = 0;
	send06 = 1;//执行频率:10000中执行3次
} 

if(send03==1)
{
	if(ScibRegs.SCIFFTX.bit.TXFFST == 0)
	{
		num_to_read= 3;      //读取频率设定和参考电压设定,返回的数有9个8bit数
		CRC_temp[0]= 0x01;
		CRC_temp[1]= 0x03;
		CRC_temp[2]= 0;
		CRC_temp[3]= 105;
		CRC_temp[4]= 0;
		CRC_temp[5]= num_to_read;
		CRC_result_temp=CRC16_cal ( CRC_temp,6);
		CRC_temp[6]= CRC_result_temp&0x00FF;
		CRC_temp[7]= (CRC_result_temp)>>8&0x00FF;
		
		for(send_pointer=0;send_pointer<8;send_pointer++)
		{
			//while (ScibRegs.SCICTL2.bit.TXRDY == 0);//不使用FIFO时判断发送许可
			
			ScibRegs.SCITXBUF  = CRC_temp[send_pointer]; 
		}
		send03=0;
		
	}
}
else 
	if(send05==1)
	{
		if(num05<7&&ScibRegs.SCIFFTX.bit.TXFFST == 0)//有7个状态位需要发送,HMI位地址和DSP_DATA[20~26]一一对应
		{
			
			CRC_temp[0]= 0x01;
			CRC_temp[1]= 0x05;
			CRC_temp[2]= 0;
			CRC_temp[3]= 00+num05;
			CRC_temp[4]= (DSP_RUN_DATA_BUFFER[00+num05]>>8)&0x00FF;
			CRC_temp[5]= DSP_RUN_DATA_BUFFER[00+num05]&0x00FF;
			CRC_result_temp=CRC16_cal ( CRC_temp,6);
			CRC_temp[6]= CRC_result_temp&0x00FF;
			CRC_temp[7]= (CRC_result_temp)>>8&0x00FF;
			for(send_pointer=0;send_pointer<8;send_pointer++)
			{
				//while (ScibRegs.SCICTL2.bit.TXRDY == 0);//不使用FIFO时判断发送许可
				ScibRegs.SCITXBUF  = CRC_temp[send_pointer]; 
			}
			send05=0;
			num05 = num05+1;
		}
		if(num05==7)
		{
			num05=0;
		}
	}
	else
		if(send06==1)
		{
			if(num06<3&&ScibRegs.SCIFFTX.bit.TXFFST == 0)//有3个变量需要显示,HMI字地址和DSP_DATA[110-112]一一对应
			{
				
				CRC_temp[0]= 0x01;
				CRC_temp[1]= 0x06;
				CRC_temp[2]= 0;
				CRC_temp[3]= 110+num06;
				CRC_temp[4]= (DSP_RUN_DATA_BUFFER[110+num06]>>8)&0x00FF;
				CRC_temp[5]= DSP_RUN_DATA_BUFFER[110+num06]&0x00FF;
				CRC_result_temp=CRC16_cal ( CRC_temp,6);
				CRC_temp[6]= CRC_result_temp&0x00FF;
				CRC_temp[7]= (CRC_result_temp)>>8&0x00FF;
				for(send_pointer=0;send_pointer<8;send_pointer++)
				{
					//while (ScibRegs.SCICTL2.bit.TXRDY == 0);//不使用FIFO时判断发送许可
					
					ScibRegs.SCITXBUF  = CRC_temp[send_pointer]; 
				}
				num06 = num06+1;
				send06=0;
			}
			if(num06==3)
			{
				num06=0;
				//send06=0;
			}
			
		}
//以上是发送逻辑

//以下是接收逻辑

if((ScibRegs.SCIFFRX.bit.RXFFST != 0))
{
	if(SCI_Num>sending03&&SCI_Num<sending05)//此时应该接收0103的数
	{
		maxlength = num_to_read*2+5;
		if(rec_pointer<maxlength)
		{
			receive_buffer_addr[rec_pointer]=ScibRegs.SCIRXBUF.all;
			rec_pointer = rec_pointer+1;
		}
		if(rec_pointer==maxlength)//接收完成,赋值到相应寄存器中
		{
			
			if(receive_buffer_addr[1] == 0x03)
			{
				for(rec_pointer=3;rec_pointer<=maxlength-4;rec_pointer=rec_pointer+2)
				{
					DSP_RUN_DATA_BUFFER[105+(rec_pointer-3)/2] = (Uint16)(receive_buffer_addr[rec_pointer]<<8)+receive_buffer_addr[rec_pointer+1];
				}
			}
			rec_pointer = 0;
		}
		
	}
	else//正在接收0105或者0106的数据
	{
		maxlength = 8;
		if(rec_pointer<maxlength)
		{
			receive_buffer_addr[rec_pointer]=ScibRegs.SCIRXBUF.all;
			rec_pointer = rec_pointer+1;
		}
		if(rec_pointer==maxlength)//接收完成,赋值到相应寄存器中
		{
			rec_pointer = 0;
			if(receive_buffer_addr[1] == 0x06)
			{
				DSP_RUN_DATA_BUFFER[1] = 666;
			}
			else
			{
				DSP_RUN_DATA_BUFFER[1] = 555;
			}
			
		}
			
				
			
			
		
	}	
}

//接收完毕开始赋值
Freq_ref = *(&DSP_RUN_DATA_BUFFER[105]);
Udc_ref = *(&DSP_RUN_DATA_BUFFER[106]);
DT = *(&DSP_RUN_DATA_BUFFER[107])&0x0F;//防止传输数据错误,最大死区为16us

if(DT==0)
{
	DT = 1;
}
Deadtime_set = DT*75;

if((Freq_ref>=10)&&(Freq_ref<=60)&&(Freq_ref!=Freq))
{
	pwm1.PeriodMax = 150*250/Freq_ref;
	pwm1.Periodhalf = pwm1.PeriodMax*0.5;
	pwm1.init(&pwm1);
}

//给要发送的数赋值

/////////////////////0105////////////////////////发送FF00是on,发送0000是off
*(&DSP_RUN_DATA_BUFFER[00])=(Uint16)(Power_flag*0xFF00);
*(&DSP_RUN_DATA_BUFFER[01])=(Uint16)(IO_IN_value2_flag*0xFF00);
*(&DSP_RUN_DATA_BUFFER[02])=(Uint16)((IO_IN_value3_flag|Udc1_over|Udc2_over)*0xFF00);
*(&DSP_RUN_DATA_BUFFER[03])=(Uint16)(0);
*(&DSP_RUN_DATA_BUFFER[04])=(Uint16)(IO_IN_value3_flag*0xFF00);
*(&DSP_RUN_DATA_BUFFER[05])=(Uint16)(Udc1_over*0xFF00);
*(&DSP_RUN_DATA_BUFFER[06])=(Uint16)(Udc2_over*0xFF00);


/////////////////////0106////////////////////////
*(&DSP_RUN_DATA_BUFFER[110])=(Uint16)(Udc1);
*(&DSP_RUN_DATA_BUFFER[111])=(Uint16)(Freq);
*(&DSP_RUN_DATA_BUFFER[112])=(Uint16)(Udc2);

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).