/*********************************************
** 功能描述: CAN口测试,11位标准标识符**
*********************************************/
#include "p30f6014.h"
int failmemory[40];
_FWDT(WDT_OFF);
//_FOSC(CSW_FSCM_OFF & XT);
_FOSC(CSW_FSCM_OFF & XT_PLL4);
unsigned int buffer1;
unsigned int buffer2;
unsigned int buffer3;
unsigned int buffer4;
unsigned long int i = 0;
void initial1()
{
C1CTRLbits.REQOP = 0x4; //请求进入配置模式
C1CTRLbits.CANCKS = 0;
while (C1CTRLbits.OPMODE!=0x4){} //确认进入配置模式
C1TX0CON = 0x0003; //发送0邮箱配置,高优先级
C1TX0SID = 0x0020; //发送0标准标识符(ID),11位
C1TX0DLC = 0x01c0; //发送0数据长度,8字节
C1RX0CON = 0x0000; //接收0邮箱配置
C1RX0DLC = 0x0008; //接收0数据长度,8字节
C1RXF0SID = 0x0010; //接收滤波器0标准标识符(ID),11位
C1RXM0SID = 0xffff; //接收屏蔽0标准标识符
/*******波特率配置*******************************/
C1CFG1bits.SJW = 0x3;
C1CFG1bits.BRP = 0xE;
C1CFG2bits.SEG2PH = 0x7;
C1CFG2bits.SEG1PH = 0x7;
C1CFG2bits.PRSEG = 0x7;
C1CTRLbits.REQOP = 0x0; //请求进入正常模式
while (C1CTRLbits.OPMODE!=0x0){} //确认进入正常模式
return;
}
int main()
{
for (i=0;i<300000;i++){}
INTCON1=0x0000;
INTCON2=0x0000; //关闭所有中断
initial1();
while(1)
{
C1TX0B1 = 0xAAAA; //发送缓冲寄存器8字节
C1TX0B2 = 0x5555;
C1TX0B3 = 0x5555;
C1TX0B4 = 0xAAAA;
C1TX0CONbits.TXREQ = 1; //启动发送
while (C1TX0CONbits.TXREQ==1){} //等待发送完成
for (i=0;i<2;i++){}
if (C1RX0CONbits.RXFUL == 1)
{
buffer1 = C1RX0B1;
buffer2 = C1RX0B2;
buffer3 = C1RX0B3;
buffer4 = C1RX0B4;
C1RX0CONbits.RXFUL = 0;
for (i=0;i<300000;i++){}
}
}
}