void init_msg_object_RX_1 (char MsgNum,uint id)
{
uint temp;
SFRPAGE = CAN0_PAGE;
CAN0ADR = IF2CMDMSK;
CAN0DAT = 0x00ba;
/* IF2 Command Mask Registers =0x00bb
WR/RD=1,Mask=0,Arb=1,Control=1,ClrIntPnd=1,TxRqst=0,DataA=1,DataB=1,一次发送8字节数据*/
CAN0ADR=IF2MSK1;
CAN0DAT=0x0000;
CAN0DAT=0x0000;
CAN0ADR = IF2ARB1;
CAN0DAT = 0x0000;
/*IF2 Arbitration Registers1 =0x0000,即ID15-0=0*/
temp=id<<2;//标准id为ID28-ID18,所以要左移2位
temp&=0x1fff;
temp|=0x8000;
CAN0DAT = temp;
/*IF2 Arbitration Registers2=100(id)00b
MsgVal=1,Xtd=0,为标准模式,扩展ID无效,Dir=0,为接收*/
CAN0DAT = 0x1488;
/*IF2 Message Control Registers=0x0488
NewDat=0,MsgLst=0,IntPnd=0,UMask=1,TxIE=0,RxIE=1,接收中断使能;RmtEn=0,TxRqst=0
EoB=1,DLC3-0=1000,即数据长度为8*/
CAN0ADR = IF2CMDRQST;
CAN0DATL = MsgNum;
/*IF2 Command Request Registers=MsgNum,将以上配置写入MsgNum号消息*/
}
接收初始化 |