#includeREG52.H#includeintrins.h#includeSJA1000.h#includeSJA1000.cvoidInit_T0(void);bitSja_1000_Init(void);voidDelay(unsignedintx);voidread_p1(void);voidInitCPU(void);voidCan_DATA_Rcv(void);voidCan_DATA_Send(void);voidCan_error(void);voidCan_DATA_OVER(void);bitsend_flag;unsignedchardatasend_data[10],rcv_data[10];unsignedcharTIME_data;unsignedcharDATA_CHANGE;unsignedcharbdataCan_INT_DATA;sbitrcv_flag=Can_INT_DATA^0;sbiterr_flag=Can_INT_DATA^2;sbitOver_Flag=Can_INT_DATA^3;sbitCAN_RESET=P2^0;sbitLED0=P1^0;sbitLED1=P1^1;sbitLED2=P1^2;sbitLED3=P1^3;sbitLED4=P1^4;sbitLED5=P1^5sbitLED6=P1^6;sbitLED7=P1^7;sbitP2_0=P2^0;sbitP2_1=P2^1;sbitP2_2=P2^2;sbitP2_3=P2^3;voidDelay(unsignedintx){unsignedintj;while(x--){for(j=0;j125;j++){;}}}voidex0_int(void)interrupt0using1{SJA1000_Address=INTERRUPT;Can_INT_DATA=*SJA1000_Address;}voidT0_int(void)interrupt1using2{TR0=0;TIME_data--;if(TIME_data==0){TIME_data=30;TH0=0x80;TL0=0x60;send_flag=1;DATA_CHANGE++;}TR0=1;}voidInit_T0(void){TMOD=0x01;TH0=0x80;TL0=0x60;TR0=1;TIME_data=30;DATA_CHANGE=0x00;ET0=1;}voidread_p1(void){if(P2_0==0){send_data[4]=0x02;}else{send_data[4]=0x03;}if(P2_1==0){send_data[5]=0x02;}else{send_data[5]=0x03;}if(P2_2==0){send_data[6]=0x02;}else{send_data[6]=0x03;}if(P2_3==0){send_data[7]=0x02;}else{send_data[7]=0x03;}}bitSja_1000_Init(void){if(enter_RST()){return1;}if(create_communication()){return1;}if(set_rate(0x06)){return1;}if(set_ACR_AMR(0xac,0x00)){return1;}if(set_CLK(0xaa,0x48)){return1;}if(quit_RST()){return1;}SJA1000_Address=CONTROL;*SJA1000_Address|=0x1e;Return0;}voidInitCPU(void){EA=1;IT0=1;EX0=1;PX0=1;Init_TO();}voidCan_error(){bitsja_status1;do{Delay(6);sja_status1=Sja_1000_Init();}while(sja_status1);}voidCan_DATA_OVER(void){SJA_command_control(CDO_order);SJA_command_control(RRB_order);}voidCan_DATA_Rcv(){SJA_rcv_data(rcv_data);SJA_command_control(0x04);}voidCan_DATA_Send(){Send_data[0]=0xAA;Send_data[1]=0x08;Send_data[2]=0x05;Send_data[3]=DATA_CHANGE;SJA_send_data(send_data);SJA_command_control(0x01);}voidmain(void){bitsja_status;Delay(1);CAN_RESET=0;do{Delay(6);sja_status=Sja_1000_Init();}while(sja_status);InitCPU();LED0=0;Can_INT_DATA=0x00;while(1){read_p1();if(_testbit_(rcv_flag)){Can_DATA_Rcv();}if(_testbit_(send_flag)){Can_DATA_Send();LED1=~LED1;}if(_testbit_(OVER_Flag)){Can_DATA_OVER();}if(_testbit_(err_flag)){LED0=1;Can_error();LED0=0;}}}