|
为什么我的标准帧改扩展帧,对中断9进行了更改,主要为移位操作,利用CAN分析仪与电脑连接后,只能发送更改数字变量的数据,一旦发送文本显示的就会死机呢,就没有通讯了。希望能得到解答。
中断程序如下:
void CAN_Isr() interrupt 9//canÖжϳÌÐò
{
unsigned char i = 0;
unsigned long TempWord = 0;
unsigned long TempDWord = 0;
EA = 0; //½øÈëCANÖжϷþÎñ³ÌÐòºó£¬¹Ø±Õ×ÜÖжÏ
if((CAN_IR&0xC0) == 0xC0) //Ô¶³ÌÖ¡½ÓÊÕÖжϱê¼ÇÖà 1 ÇÒ½ÓÊÕÍê³É±ê¼ÇÖà 1
{
CAN_IR &= 0x3F; //Ô¶³ÌÖ¡½ÓÊÕÖжϱê¼ÇÇåÁãÇÒ½ÓÊÕÍê³É±ê¼ÇÇåÁã
ADR_H = 0xFF; //ÅäÖà DGUS±äÁ¿´æ´¢Æ÷µØÖ·
ADR_M = 0x00;
ADR_L = 0x68;//0x69;
ADR_INC = 1; //ÅäÖõØÖ·ÔöÁ¿
RAMMODE = 0xAF; //¶Á²Ù×÷
while(!APP_ACK); //µÈ´ýÈ·ÈÏ£¬APP_ACKÓ²¼þ¶Ô8051Õ¼ÓñäÁ¿´æ´¢Æ÷ÇëÇóµÄÓ¦´ð£¬1=OK£¬0=BUSY£¬ÐèÒª¼ÌÐøµÈ´ý¡£
//FF0068Êý¾Ý
APP_EN = 1;
while(APP_EN); //½ÓÊÕÊý¾Ýµ½»º³åÇø
rx_buf[12] = DATA3;
rx_buf[13] = DATA2;
rx_buf[14] = DATA1;
rx_buf[15] = DATA0;
//FF0069Êý¾Ý
APP_EN = 1;
while(APP_EN); //½ÓÊÕÊý¾Ýµ½»º³åÇø
rx_buf[0] = DATA3;
rx_buf[1] = DATA2;
rx_buf[2] = DATA1;
rx_buf[3] = DATA0;
RAMMODE = 0; //½áÊø¶ÔDGUS±äÁ¿´æ´¢Æ÷µÄ·ÃÎÊ
rx_done = 1; //½ÓÊÕÍê³É (Ô¶³ÌÖ¡)
}
else if((CAN_IR&0xC0) == 0x40) //½ÓÊÕÍê³É±ê¼ÇÖà 1
{
CAN_IR &= 0xBF; //½ÓÊÕÍê³É±ê¼ÇλÇåÁã
ADR_H = 0xFF;
ADR_M = 0x00;
ADR_L = 0x68;//0x69
ADR_INC = 1; //ÅäÖõØÖ·ÔöÁ¿
RAMMODE = 0xAF; //¶Á²Ù×÷
while(!APP_ACK); //µÈ´ýÈ·ÈÏ£¬APP_ACKÓ²¼þ¶Ô8051Õ¼ÓñäÁ¿´æ´¢Æ÷ÇëÇóµÄÓ¦´ð£¬1=OK£¬0=BUSY£¬ÐèÒª¼ÌÐøµÈ´ý¡£
//FF0068Êý¾Ý
APP_EN = 1;
while(APP_EN); //½ÓÊÕÊý¾Ýµ½»º³åÇø
rx_buf[12] = DATA3;
rx_buf[13] = DATA2;
rx_buf[14] = DATA1;
rx_buf[15] = DATA0;
APP_EN = 1;
//FF0069Êý¾Ý
while(APP_EN); //½ÓÊÕÊý¾Ýµ½»º³åÇø
rx_buf[0] = DATA3; //ID3
rx_buf[1] = DATA2; //ID2
rx_buf[2] = DATA1; //ID1
rx_buf[3] = DATA0; //ID0
//FF006AÊý¾Ý
APP_EN = 1;
while(APP_EN);
rx_buf[4] = DATA3;
rx_buf[5] = DATA2;
rx_buf[6] = DATA1;
rx_buf[7] = DATA0;
//FF006BÊý¾Ý
APP_EN = 1;
while(APP_EN);
rx_buf[8] = DATA3;
rx_buf[9] = DATA2;
rx_buf[10] = DATA1;
rx_buf[11] = DATA0;
RAMMODE = 0; //½áÊø¶ÔDGUS±äÁ¿´æ´¢Æ÷µÄ·ÃÎÊ
rx_done = 2; //½ÓÊÕÍê³É (Êý¾ÝÖ¡)
}
if((CAN_IR&0x20) == 0x20)
{
CAN_IR &= 0xDF; //Çå¿Õ·¢ËÍÖ¡±ê¼Çλ
}
if((CAN_IR&0x10) == 0x10)
{
CAN_IR &= 0xEF; //Çå¿Õ½ÓÊÕÒç³ö±ê¼Çλ
}
if((CAN_IR&0x08) == 0x08)
{
CAN_IR &= 0xF7; //Çå¿Õ´íÎó±ê¼Çλ
CAN_ET &= 0xE0; //Çå¿Õ´íÎó±ê¼Ç
}
if((CAN_IR&0x04) == 0x04)
{
CAN_IR &= 0xFB; //Çå¿ÕÖÙ²Ãʧ°Ü±ê¼Çλ
CAN_CR |= 0x04; //ÖØÐÂÆô¶¯·¢ËÍ
}
EA = 1;
if((rx_buf[12]&0x40) == 0x40)
{
Rx_Message.RTR = 1; //Ô¶³ÌÖ¡
}
else
{
Rx_Message.RTR = 0; //Êý¾ÝÖ¡
}
if((rx_buf[12]&0x80) == 0x80)
{
Rx_Message.IDE = 1; //À©Õ¹Ö¡
}
else
{
Rx_Message.IDE = 0; //±ê×¼Ö¡
}
Rx_Message.len = (rx_buf[12]&0x0f);
if(Rx_Message.IDE == 0) //±ê×¼Ö¡
{
// TempWord=(rx_buf[0]+rx_buf[1]+rx_buf[2]+rx_buf[3]);
// Rx_Message.Id =(TempWord>>18);
TempWord = ((unsigned int)rx_buf[0])<<3;
Rx_Message.Id = TempWord|((rx_buf[1]&0xe0)>>5);
}
else
{
TempDWord = ((unsigned long)rx_buf[0])<<21;
TempDWord |= (((unsigned long)rx_buf[1])<<13);
TempDWord |= (((unsigned long)rx_buf[2])<<5);
Rx_Message.Id = TempDWord|((rx_buf[3]&0xf8)>>3);
}
for(i=1;i<9;i++)
{
Rx_Message.Data = rx_buf[i+3];
}
Can_RX_Data_Parse();
//DWIN_CANRxData_Process();
}
发送程序如下:
void Can_RX_Data_Parse()//½ÓÊÕ³ÌÐò
{
//unsigned char i=0;
u16 value_3[4]={0};
u16 value[5]={0};
unsigned char temp_word[8]={0};
unsigned char temp_word_1[8]={0};
if(Rx_Message.Id==0x180BA001)
{
temp_word[0]=Rx_Message.Data[1];
temp_word[1]=Rx_Message.Data[2];
temp_word[2]=Rx_Message.Data[3];
temp_word[3]=Rx_Message.Data[4];
temp_word[4]=Rx_Message.Data[5];
temp_word[5]=Rx_Message.Data[6];
temp_word[6]=Rx_Message.Data[7];
temp_word[7]=Rx_Message.Data[8];
value_3[0]=((u16)temp_word[1]<<8)+temp_word[0]; //AÏàµçѹ
value_3[1]=((u16)temp_word[3]<<8)+temp_word[2]; //BÏàµçѹ
value_3[2]=((u16)temp_word[5]<<8)+temp_word[4]; //CÏàµçѹ
value_3[3]=((u16)temp_word[7]<<8)+temp_word[6]; //»·¾³Î¶È
sys_write_vp(0x5020,(u8*)&value_3[0],1);
sys_write_vp(0x5030,(u8*)&value_3[1],1);
sys_write_vp(0x5040,(u8*)&value_3[2],1);
sys_write_vp(0x5050,(u8*)&value_3[3],1);
}
if(Rx_Message.Id==0x1801A001)
{
temp_word_1[0]=Rx_Message.Data[1];
temp_word_1[1]=Rx_Message.Data[2];
temp_word_1[2]=Rx_Message.Data[3];
temp_word_1[3]=Rx_Message.Data[4];
temp_word_1[4]=Rx_Message.Data[5];
temp_word_1[5]=Rx_Message.Data[6];
temp_word_1[6]=Rx_Message.Data[7];
temp_word_1[7]=Rx_Message.Data[8];
value[2]=temp_word_1[0];
value[0]=((u16)temp_word_1[2]<<8)+temp_word_1[1]; //½âÂëµçѹ1
value[1]=((u16)temp_word_1[4]<<8)+temp_word_1[3]; //½âÂëµçÁ÷ 1
value[3]=((u16)temp_word_1[6]<<8)+temp_word_1[5]; //¹ÊÕÏÐÅÏ¢
value[4]=temp_word_1[7];//PFC¹ÊÕÏ
//³äµçÄ£¿é״̬
if(value[2]==0x00)
{
sys_write_vp(0x3000,(u8*)&FIRST_TXT_1,sizeof(FIRST_TXT_1)/2+1);//Êä³öÕý³£¹Ø»ú״̬
sys_delay_ms(5);
}
if(value[2]==0x01)
{
sys_write_vp(0x3000,(u8*)&FIRST_TXT_2,sizeof(FIRST_TXT_2)/2+1);//Êä³ö¿ª»ú״̬
sys_delay_ms(5);
}
if(value[2]==0x11)
{
sys_write_vp(0x3000,(u8*)&FIRST_TXT_3,sizeof(FIRST_TXT_3)/2+1);//Êä³ö¹ÊÕϹػú״̬
sys_delay_ms(5);
}/*
//¹ÊÕϸ澯
if(value[3]==0x0000)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_28,sizeof(FIRST_TXT_28)/2+1);//Êä³öÕý³£
sys_write_vp(0x3100,(u8*)&FIRST_TXT_28,sizeof(FIRST_TXT_28)/2+1);//Êä³öÕý³£
sys_delay_ms(5);
}
if(value[3]==0x0001)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_4,sizeof(FIRST_TXT_4)/2+1);//Êä³öÄ£¿éÊäÈëǷѹ
sys_write_vp(0x3100,(u8*)&FIRST_TXT_29,sizeof(FIRST_TXT_29)/2+1);//ÎÞ
sys_delay_ms(5);
}
if(value[3]==0x0002)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_5,sizeof(FIRST_TXT_5)/2+1);//Êä³öÄ£¿éÊäÈëȱÏà
sys_delay_ms(5);
}
if(value[3]==0x0004)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_6,sizeof(FIRST_TXT_6)/2+1);//Êä³öÄ£¿éÊäÈë¹ýѹ
sys_delay_ms(5);
}
if(value[3]==0x0008)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_7,sizeof(FIRST_TXT_7)/2+1);//Êä³öÄ£¿éÊä³ö¹ýѹ
sys_delay_ms(5);
}
if(value[3]==0x0010)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_8,sizeof(FIRST_TXT_8)/2+1);//Êä³öÄ£¿éÊä³ö¹ýÁ÷
sys_delay_ms(5);
}
if(value[3]==0x0020)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_9,sizeof(FIRST_TXT_9)/2+1);//Êä³öÄ£¿éζȹý¸ß
sys_delay_ms(5);
}
if(value[3]==0x0040)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_10,sizeof(FIRST_TXT_10)/2+1);//Êä³öÄ£¿é·çÉȹÊÕÏ
sys_delay_ms(5);
}
if(value[3]==0x0080)
{
sys_write_vp(0x3050,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_delay_ms(5);
}
if(value[3]==0x0180)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3050,(u8*)&FIRST_TXT_12,sizeof(FIRST_TXT_12)/2+1);//ĸÏßÒì³£
sys_delay_ms(5);
}
if(value[3]==0x0280)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3050,(u8*)&FIRST_TXT_13,sizeof(FIRST_TXT_13)/2+1);//SCIͨÐÅÒì³£
sys_delay_ms(5);
}
if(value[3]==0x0480)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3050,(u8*)&FIRST_TXT_14,sizeof(FIRST_TXT_14)/2+1);//й·Å¹ÊÕÏ
sys_delay_ms(5);
}
if(value[3]==0x0880)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3050,(u8*)&FIRST_TXT_15,sizeof(FIRST_TXT_15)/2+1);//PFCÒì³£¹Ø»ú
sys_delay_ms(5);
}
if(value[3]==0x1080)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3500,(u8*)&FIRST_TXT_16,sizeof(FIRST_TXT_16)/2+1);//Ƿѹ¾¯¸æ
sys_delay_ms(5);
}
if(value[3]==0x2080)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3050,(u8*)&FIRST_TXT_17,sizeof(FIRST_TXT_17)/2+1);//¹ýѹ¸æ¾¯
sys_delay_ms(5);
}
if(value[3]==0x4000)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3050,(u8*)&FIRST_TXT_18,sizeof(FIRST_TXT_18)/2+1);//¸ßÎÂÏÞ¹¦ÂÊ
sys_delay_ms(5);
}
if(value[3]==0x8000)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_19,sizeof(FIRST_TXT_19)/2+1);//Êä³ö¶Ì·¹ÊÕÏ
sys_write_vp(0x3050,(u8*)&FIRST_TXT_29,sizeof(FIRST_TXT_29)/2+1);//ÎÞ
sys_delay_ms(5);
}
//PFC¹ÊÕÏ
if(value[4]==0x00)
{
sys_write_vp(0x3150,(u8*)&FIRST_TXT_28,sizeof(FIRST_TXT_28)/2+1);//Êä³öÕý³£
sys_delay_ms(5);
}
if(value[4]==0x01)
{
sys_write_vp(0x3150,(u8*)&FIRST_TXT_20,sizeof(FIRST_TXT_20)/2+1);//Êä³öÊäÈë¹ýÁ÷¹ÊÕÏ
sys_delay_ms(5);
}
if(value[4]==0x02)
{
sys_write_vp(0x3150,(u8*)&FIRST_TXT_21,sizeof(FIRST_TXT_21)/2+1);//Êä³öÊеçƵÂʹÊÕÏ
sys_delay_ms(5);
}
if(value[4]==0x04)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3150,(u8*)&FIRST_TXT_22,sizeof(FIRST_TXT_22)/2+1);//Êе粻ƽºâ¹ÊÕÏ
sys_delay_ms(5);
}
if(value[4]==0x08)
{
sys_write_vp(0x3150,(u8*)&FIRST_TXT_23,sizeof(FIRST_TXT_23)/2+1);//Êä³öDCTz¹ÊÕÏ
sys_delay_ms(5);
}
if(value[4]==0x10)
{
sys_write_vp(0x3150,(u8*)&FIRST_TXT_24,sizeof(FIRST_TXT_24)/2+1);//Êä³öµØÖ·³åÍ»
sys_delay_ms(5);
}
if(value[4]==0x20)
{
sys_write_vp(0x3150,(u8*)&FIRST_TXT_25,sizeof(FIRST_TXT_25)/2+1);//Êä³öĸÏßƫѹ
sys_delay_ms(5);
}
if(value[4]==0x40)
{
sys_write_vp(0x3150,(u8*)&FIRST_TXT_26,sizeof(FIRST_TXT_26)/2+1);//Êä³öÏàλÒì³£¹ÊÕÏ
sys_delay_ms(5);
}
if(value[4]==0x80)
{
sys_write_vp(0x3100,(u8*)&FIRST_TXT_11,sizeof(FIRST_TXT_11)/2+1);//Êä³öÄ£¿éÓ²¼þ¹ÊÕÏ
sys_write_vp(0x3150,(u8*)&FIRST_TXT_27,sizeof(FIRST_TXT_27)/2+1);//ĸÏß¹ýѹ¹ÊÕÏ
sys_delay_ms(5);
} */
sys_write_vp(0x5100,(u8*)&value[0],1); //µçÁ÷Öµ
sys_write_vp(0x5110,(u8*)&value[1],1); //dwin ÏÔʾÊý¾Ý µçѹֵ
}
memset(can_receive_data,0,8);
}
|
|