基于CAN總線的汽車組合儀表盤的設(shè)計
3.1 程序流程圖如下
3.2 CAN接收程序
為了便于程序的移植和修改,本接收程序定義了一個結(jié)構(gòu),部分代碼如下:
unsigned char InputCAN( unsigned char msg_num )
{unsigned char p;p=0;RUN = 0x01; /*開始接收*/
if(Receive_message[1].DSTAT.DN==1){p |= 1;
Buf_Speed=((int)Receive_message[1].DATA[0]8)|Receive_message[1].DATA[1];//接收車速數(shù)據(jù)Buf_Speed
Receive_message[1].DSTAT.DN=0;Receive_message[1].DSTAT.MUC=0;}
RUN = 0x01; /*開始接收*/
if(Receive_message[2].DSTAT.DN==1){p|=2;
Buf_Rpm=((int)Receive_message[2].DATA[0]8)|Receive_message[2].DATA[1];//接收轉(zhuǎn)速數(shù)據(jù)Buf_Rpm
Receive_message[2].DSTAT.DN=0;Receive_message[2].DSTAT.MUC=0;}
RUN = 0x01; /*開始接收*/
if(Receive_message[3].DSTAT.DN==1){p |= 4;
Buf_Fuel=((int)Receive_message[3].DATA[0]8)|Receive_message[3].DATA[1];//燃油數(shù)據(jù)Buf_Fuel
Receive_message[3].DSTAT.DN=0;Receive_message[3].DSTAT.MUC=0;}
RUN = 0x01; /*開始接收*/
if(Receive_message[4].DSTAT.DN==1){p |= 8;
Buf_Winker=((int)Receive_message[4].DATA[0]8)|Receive_message[4].DATA[1];//水溫數(shù)據(jù)Buf_Water
Receive_message[4].DSTAT.DN=0;Receive_message[4].DSTAT.MUC=0;}
RUN = 0x01; /*開始接收*/
if(Receive_message[5].DSTAT.DN==1){p |= 16;
Buf_Winker=((int)Receive_message[5].DATA[0]8)|Receive_message[5].DATA[1];//接收報警燈和指示信號Buf_Winker
Receive_message[5].DSTAT.DN=0;Receive_message[5].DSTAT.MUC=0;}
RUN = 0x01; /*開始接收*/
if(Receive_message[6].DSTAT.DN==1){p |= 32;
Buf_CanData=((int)Receive_message[6].DATA[0]|Receive_message[6].DATA[1];//接收其他數(shù)據(jù)Buf_CanData
Receive_message[6].DSTAT.DN=0;Receive_message[6].DSTAT.MUC=0;}
RUN = 0x01;/*開始接收*/
return p;//1:車速信號,2:轉(zhuǎn)速數(shù)據(jù);4:燃油數(shù)據(jù) 8:水溫數(shù)據(jù) 16:報警燈指示數(shù)據(jù) 32:其他數(shù)據(jù) 其他:接收數(shù)據(jù)無效
}
4.結(jié)束語
由于本儀表系統(tǒng)中采用了CAN 總線, 大大減少了儀表板與車載其它電子設(shè)備間通信用電纜的數(shù)量和接插件的數(shù)量和種類,提高了系統(tǒng)的魯棒性,同時系統(tǒng)通過充分利用車載網(wǎng)絡的優(yōu)勢,實現(xiàn)數(shù)據(jù)共享,降低了系統(tǒng)成本,提供汽車儀表的控制精度,本CAN通信軟件已經(jīng)通過驗證,可以滿足汽車儀表的通信要求,鑒于CAN 的應用優(yōu)勢和發(fā)展前景,并考慮到它在國外尚未定型,在國內(nèi)也有很多應用空白,我國汽車業(yè)可以在引進、消化、吸收的基礎(chǔ)上,配合CAN的推廣工作抓緊制定符合國情的CAN技術(shù)標準,形成自主產(chǎn)權(quán)的汽車控制網(wǎng)絡系統(tǒng)。
評論