www.pudn.com > 12can.rar > candeal2.h


////////candeal2.h/////////////////////// 
#include "can.h" 
void remote_rqst_ini(char MsgNum,uint id){ 
	uint temp; 
  	SFRPAGE = CAN0_PAGE; 
	CAN0ADR = IF1CMDMSK; //指向IF1 Command Mask Registers 
	CAN0DAT = 0x00b3;  
	/*   IF1 Command Mask Registers  =0x00b3  
	WR/RD=1,Mask=0,Arb=1,Control=1,ClrIntPnd=0,TxRqst=0,DataA=1,DataB=1,一次发送8字节数据*/ 
	CAN0ADR = IF1ARB1;             
	CAN0DAT = 0x0000;   
	/*IF1 Arbitration Registers1 =0x0000,即ID15-0=0*/ 
	temp=id<<2;//标准id为ID28-ID18,所以要左移2位 
	temp&=0x1fff; 
	temp|=0x8000; 
	CAN0DAT = temp; //地址自增,指向IF1 Arbitration Registers2 
	/*IF1 Arbitration Registers2=100(id)00b 
	MsgVal=1,Xtd=0,为标准模式,扩展ID无效,Dir=0,为接收*/ 
	CAN0DAT = 0x0488; 
	/*IF1 Message Control Registers=0x0488 
	NewDat=0,MsgLst=0,IntPnd=0,UMask=0,TxIE=0,RxIE=1,RmtEn=0,TxRqst=0 
	EoB=1,DLC3-0=1000,即数据长度为8*/ 
	CAN0ADR = IF1CMDRQST;          
	CAN0DAT = MsgNum;    
	/*IF1 Command Request Registers=MsgNum,将以上配置写入MsgNum号消息*/ 
} 
void remote_rqst(char MsgNum){ 
	SFRPAGE = CAN0_PAGE; 
	CAN0ADR = IF1CMDMSK;  
	CAN0DATL =0x87;//将TxRqst置1,发送远程帧请求 
	CAN0ADR = IF1CMDRQST;          
	CAN0DAT = MsgNum;    
} 
void remote_send_ini(char MsgNum,uint id){ 
	uint temp; 
  	SFRPAGE = CAN0_PAGE; 
	CAN0ADR = IF1CMDMSK; //指向IF1 Command Mask Registers 
	CAN0DAT = 0x00b3;  
	/*   IF1 Command Mask Registers  =0x00b3  
	WR/RD=1,Mask=0,Arb=1,Control=1,ClrIntPnd=0,TxRqst=0,DataA=1,DataB=1,一次发送8字节数据*/ 
	CAN0ADR = IF1ARB1;             
	CAN0DAT = 0x0000;   
	/*IF1 Arbitration Registers1 =0x0000,即ID15-0=0*/ 
	temp=id<<2;//标准id为ID28-ID18,所以要左移2位 
	temp&=0x1fff; 
	temp|=0xa000; 
	CAN0DAT = temp; //地址自增,指向IF1 Arbitration Registers2 
	/*IF1 Arbitration Registers2=101(id)00b 
	MsgVal=1,Xtd=0,为标准模式,扩展ID无效,Dir=1,为发送*/ 
	CAN0DAT = 0x0a88; 
	/*IF1 Message Control Registers=0x0488 
	NewDat=0,MsgLst=0,IntPnd=0,UMask=0,TxIE=1,RxIE=0,RmtEn=1,TxRqst=0 
	EoB=1,DLC3-0=1000,即数据长度为8*/ 
	CAN0ADR = IF1CMDRQST;          
	CAN0DAT = MsgNum;    
	/*IF1 Command Request Registers=MsgNum,将以上配置写入MsgNum号消息*/ 
} 
void remote_send_updata(char MsgNum,char *p,char len){ 
	char i; 
	SFRPAGE = CAN0_PAGE; 
	CAN0ADR = IF2CMDMSK;       	 
	CAN0DATL = 0x08;   
	CAN0ADR = IF2CMDRQST;         
	CAN0DATL = MsgNum;  /*将该消息IntPnd清零,注意一定要保证将中断标志位清零,否则将一直发生中断,陷入死机状态*/          
	CAN0ADR = IF1CMDMSK;          
	CAN0DAT = 0x008b;             
	/*   IF1 Command Mask Registers  =0x008b 
	WR/RD=1,Mask=0,Arb=0,Control=0,ClrIntPnd=1(注意WR/RD=1时,ClrIntPnd=1对消息IntPnd清零是无效的),TxRqst=0,DataA=1,DataB=1,一次发送8字节数据*/ 
	CAN0ADR = IF1DATA1;           
	for(i=0;i