程序在这里:
#include <hidef.h> /* common defines and macros */
#include <mc9s12dp256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dp256b"
#include<init.h>
#define unchar unsigned char
unchar a,b,c,d,e,f,g,h;
//////延迟子程序///////
void delay()
{
long j=60000;
while(j--);
j=60000;
while(j--);
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
////////can0中断程序/////////////////
interrupt void CAN0_ISR(void){
CAN0CTL0_RXFRM=1; //接收帧标志位清零
a=CAN0RXDSR0;
delay();
b=CAN0RXDSR1;
delay();
c=CAN0RXDSR2;
delay();
d=CAN0RXDSR3;
delay();
e=CAN0RXDSR4;
delay();
f=CAN0RXDSR5;
delay();
g=CAN0RXDSR6;
delay();
h=CAN0RXDSR7;
delay();
CAN0RFLG_RXF=1;//接收缓冲区满清除
}
#pragma CODE_SEG DEFAULT
///////can0初始化////////
void can_init(void) {
CAN0CTL0_INITRQ=1; //进入 初始化模式
while(CAN0CTL1_INITAK==0); //等待进入初始化模式
CAN0IDAC=0X20;//16位接收过滤器
CAN0IDMR0=0XFF;//设置屏蔽寄存器,忽略屏蔽
CAN0IDMR1=0XFF;
CAN0IDMR2=0XFF;
CAN0IDMR3=0XFF;
CAN0IDMR4=0XFF;
CAN0IDMR5=0XFF;
CAN0IDMR6=0XFF;
CAN0IDMR7=0XFF;
CAN0BTR0=0X49;//设置时钟,分频系数10
CAN0BTR1=0X0F;//16tq时钟周期,波特率=16000K/(16*10)=100K
CAN0CTL1=CAN0CTL1|0X80;//使能CAN功能,选择晶振时钟作为时钟源
CAN0CTL1=CAN0CTL1&0XEF;//turn off listen mode
CAN0CTL0_INITRQ=0;//初始化完毕
while(CAN0CTL1_INITAK==1);//等待应答信号
while(CAN0CTL0_SYNCH==0);//和总线同步
CAN0RIER_RXFIE=1; //允许CAN0接收中断
}
/* put your own code here */
void main(void) {
//int i,j;
COPCTL=0X00;//关闭看门狗
InitPLL ( );
DisableInterrupts;
can_init( );
EnableInterrupts;
/*while(CAN0RFLG_RXF==0); //接收标志位是否有效
a=CAN0RXDSR0;
delay();
b=CAN0RXDSR1;
delay();
c=CAN0RXDSR2;
delay();
d=CAN0RXDSR3;
delay();
e=CAN0RXDSR4;
delay();
f=CAN0RXDSR5;
delay();
g=CAN0RXDSR6;
delay();
h=CAN0RXDSR7;
delay();
CAN0RFLG_RXF=1; //接收标志位清零
*/
for(;;)
{
}
} |