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