void main(void) {
/* put your own code here */
InitCRG(); //这是LOOP BACK模式
DDRB=0XFF; //复位
PORTB=0xff; //初始化方向设置为输入,随后pb的状态将被实际状态代替
InitCAN0(); //实际应用时要改到正常模式,并确定硬件连接正确
InitCAN1();
EnableInterrupts ; //CCR中的I位清零
for(;;) {
Transmission_CAN1();
delay();
} /* wait forever */
/* please make sure that you never leave this function */
}
CAN0CTL1=0X80; //CAN 使能,选用晶振时钟,频率为16M ,loop back mode
CAN0BTR1=0X3A; // One sample per bit,time segment2=4,
// time segment1=11;时间量=1+11+4=16
CAN0BTR0=0xC9; //Synchronization Jump With=4Tq,Prescaler=10;
//得到位速率为100K, Bit Rate=(Frequence of CANCLK)/(Prescalar*Number of Time Quanta)
/*To receive standard identifiers in 32 bit filter mode, it is required to
program the last three bits (AM2 - AM0) in the mask registers CANIDMR1 and CANIDMR5 to "don’t
care". To receive standard identifiers in 16 bit filter mode, it is required to program the last three bits (AM2
- AM0) in the mask registers CANIDMR1, CANIDMR3, CANIDMR5 and CANIDMR7 to "don’t car". */
CAN1CTL1=0X80; //CAN 使能,选用晶振时钟,频率为16M ,loop back mode
CAN1BTR1=0X3A; // One sample per bit,time segment2=4,
// time segment1=11;时间量=1+11+4=16
CAN1BTR0=0xC9; //Synchronization Jump With=4Tq,Prescaler=10;
//得到位速率为100K, Bit Rate=(Frequence of CANCLK)/(Prescalar*Number of Time Quanta)
/*To receive standard identifiers in 32 bit filter mode, it is required to
program the last three bits (AM2 - AM0) in the mask registers CANIDMR1 and CANIDMR5 to "don’t
care". To receive standard identifiers in 16 bit filter mode, it is required to program the last three bits (AM2
- AM0) in the mask registers CANIDMR1, CANIDMR3, CANIDMR5 and CANIDMR7 to "don’t car". */