|
//AD数据采集,CAN发送数据
#include"p30f6010A.h"
#include"cpuinit.h"
#include"main.h"
#include"math.h"
//#include"IO.h"
//unsigned long int TX0_id,TX1_id,TX2_id;
#define FCY = 16000000;//10MHz外部晶振
_FOSC(CSW_FSCM_OFF&HS2_PLL8);
_FWDT(WDT_ON & WDTPSA_512 & WDTPSB_1);//开启看门狗,1024ms复位
_FBORPOR(PBOR_OFF&MCLR_EN);//掉电复位禁止,MCLR复位时能
int main (void)
{
IO_init();
ClrWdt();//清看门狗
T1_init();
ClrWdt();//清看门狗
ADC_init();
ClrWdt();//清看门狗
I2C_init();
ClrWdt();//清看门狗
//USATRT_init();
ClrWdt();//清看门狗
//CAN发送ID
TX0_id = 0x18104040;//模拟量输入发送id
TX1_id = 0x18104041;
// TX2_id = 0x1FFFFFFF;//
//CAN接收ID
RX1_F0id = 0x18200303;
RX1_F1id = 0x1FFFFFFF;
RX1_Mid = 0x1FFFFFFF;
//------
ClrWdt();//清看门狗
CAN_init_C1();
ClrWdt();//清看门狗
TRISDbits.TRISD1 = 1;//RUN_1点亮
Delay(50);
ClrWdt();//清看门狗
while(1)
{
Lamp_flashing = 1;
ClrWdt();
if(CANexchange[0] == 0);//交换数据
{
CAN1_data_change0[0] = CAN_receive_finish[0][0];
CAN1_data_change0[1] = CAN_receive_finish[0][1];
CAN1_data_change0[2] = CAN_receive_finish[0][2];
CAN1_data_change0[3] = CAN_receive_finish[0][3];
CAN1_data_change0[4] = CAN_receive_finish[0][4];
CAN1_data_change0[5] = CAN_receive_finish[0][5];
CAN1_data_change0[6] = CAN_receive_finish[0][6];
CAN1_data_change0[7] = CAN_receive_finish[0][7];
CANexchange[0] == 1;
}
if(CANexchange[1] == 0)
{
CAN1_data_change1[0] = CAN_receive_finish[1][0];
CAN1_data_change1[1] = CAN_receive_finish[1][1];
CAN1_data_change1[2] = CAN_receive_finish[1][2];
CAN1_data_change1[3] = CAN_receive_finish[1][3];
CAN1_data_change1[4] = CAN_receive_finish[1][4];
CAN1_data_change1[5] = CAN_receive_finish[1][5];
CAN1_data_change1[6] = CAN_receive_finish[1][6];
CAN1_data_change1[7] = CAN_receive_finish[1][7];
CANexchange[1] == 1;
}
if(CANexchange[2] == 0)
{
CAN1_data_change2[0] = CAN_receive_finish[2][0];
CAN1_data_change2[1] = CAN_receive_finish[2][1];
CAN1_data_change2[2] = CAN_receive_finish[2][2];
CAN1_data_change2[3] = CAN_receive_finish[2][3];
CAN1_data_change2[4] = CAN_receive_finish[2][4];
CAN1_data_change2[5] = CAN_receive_finish[2][5];
CAN1_data_change2[6] = CAN_receive_finish[2][6];
CAN1_data_change2[7] = CAN_receive_finish[2][7];
CANexchange[2] == 1;
}
//TX0_id发送
if((CAN1send_EN == 0)&&(CAN1_sendCLC >25))
{
if(AD_change1 == 0)
{
CANsendID1 = TX0_id;
CANsend_data1[0] = CAN1_data[0][0];
CANsend_data1[1] = CAN1_data[0][1];
CANsend_data1[2] = CAN1_data[0][2];
CANsend_data1[3] = CAN1_data[0][3];
CANsend_data1[4] = CAN1_data[0][4];
CANsend_data1[5] = CAN1_data[0][5];
CANsend_data1[6] = CAN1_data[0][6];
CANsend_data1[7] = CAN1_data[0][7];
}
CAN_Life();
if(AD_change1 == 1)
{
Life_Data ++;
CANsendID1 = TX1_id;
CANsend_data1[0] = CAN2_data[0][0];
CANsend_data1[1] = CAN2_data[0][1];
CANsend_data1[2] = CAN2_data[0][2];
CANsend_data1[3] = CAN2_data[0][3];
CANsend_data1[4] = 0;
CANsend_data1[5] = 0;
CANsend_data1[6] = 4;
CANsend_data1[7] = Life_Version;
}
CAN1send_EN = 1;//发送
AD_change1++;
if(AD_change1 >1)
AD_change1 = 0;
CAN1_sendCLC = 0;
}
Send_C1TX0();
//TX1_id发送
// Life_Data =0;
// CAN_Life();
//
// if((CAN1send_EN1 == 0)&&(CAN2_sendCLC >400))
// {
// if(AD_change2 == 0)
// {
// //Delay(50);
// // AD_change[0]=1;
// AD_change_2();
//
// Life_Data ++;
// CAN1_data[1][0] = AD_buff2[0];
// CAN1_data[1][1] = AD_buff2[1];
// CAN1_data[1][2] = AD_buff2[2];
// CAN1_data[1][3] = AD_buff2[3];
// CAN1_data[1][4] = AD_buff2[4];
// CAN1_data[1][5] = AD_buff2[5];
// CAN1_data[1][6] = Life_Data;
// CAN1_data[1][7] = Life_Version;
//
// CANsendID2 = TX1_id;
// CANsend_data2[0] = CAN1_data[1][0];
// CANsend_data2[1] = CAN1_data[1][1];
// CANsend_data2[2] = CAN1_data[1][2];
// CANsend_data2[3] = CAN1_data[1][3];
// CANsend_data2[4] = CAN1_data[1][4];
// CANsend_data2[5] = CAN1_data[1][5];
// CANsend_data2[6] = CAN1_data[1][6];
// CANsend_data2[7] = CAN1_data[1][7];
//
// // CANsend_data2[7] = Life_Data;
// //CANsend_data2
// }
// CAN1send_EN1 = 0;
// AD_change2++;
// if(AD_change2 > 1)
// AD_change2 = 0;
// CAN2_sendCLC = 0;
// }
//Life_Data ++;
//Send_C1TX0_1();
//--------------------------------------------
//发送完成延时
Delay(5);
// CAN 模块收、发错误处理
//--------------------------------------------------------------------------
if ((C1INTFbits.TXBO==1)||(C1INTFbits.TXBP==1)||(C1INTFbits.RXEP))
{
IEC0bits.T1IE = 0;
CAN_init_C1();//接收错误被动复位
IEC0bits.T1IE = 1;
}
}
}
//详情见附件
|
评分
-
查看全部评分
|