那位大哥 能帮小弟看看这个程序怎么发不出数去啊 我都要疯了 好几天就看这几句话 也调不通 我在这里谢谢了 帮我看看 这个can程序吧。 #include <hidef.h> /* common defines and macros */ #include <mc9s12dg256.h> /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12dg256b" unsigned char data0; unsigned char id0=0x12; unsigned char id1=0x00; unsigned char len=0x08; unsigned char data1[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07}; void DELAYNS(unsigned int k) { unsigned int j=10000; while(j--) for(;k>0;k--); } void CAN_Init(void) { CAN0CTL0 = 0x01; while(!(0x01&CAN0CTL1)); CAN0CTL1_CANE = 1; CAN0CTL1_LISTEN = 0; CAN0BTR0 = 0x01; CAN0BTR1 = 0x10; CAN0IDAC = 0X10; CAN0CTL0_INITRQ = 0; while((0x01&CAN0CTL1)!=0); } void CAN_Send(void){ unsigned char txbuf; CAN0TBSEL = CAN0TFLG; txbuf = CAN0TBSEL; CAN0TXIDR0 = id0; CAN0TXIDR1 = id1;
CAN0TXDSR0 = data1[0]; CAN0TXDSR1 = data1[1]; CAN0TXDSR2 = data1[2]; CAN0TXDSR3 = data1[3]; CAN0TXDSR4 = data1[4]; CAN0TXDSR5 = data1[5]; CAN0TXDSR6 = data1[6]; CAN0TXDSR7 = data1[7];
CAN0TXDLR = len; CAN0TXTBPR = 0; CAN0TFLG = txbuf; } void main(void) { unsigned int i; DELAYNS(0x4000); CAN_Init(); DELAYNS(0x4000); for(i=0;i<100;i++){
DELAYNS(0x1000); DELAYNS(0x1000); DELAYNS(0x1000); CAN_Send(); }
}
|