帮忙看看程序吧 好久都调不通
大哥们 帮帮忙吧
#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();
}
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |