📄 can.lst
字号:
242 1 CAN_OBJ[6].MCR0 = 0x55; // set Message Control Register 0
243 1
244 1 // ------------------------------------------------------------------------
245 1 /// ----------------- Configure Message Object 8 ---------------------------
246 1 // ------------------------------------------------------------------------
247 1 /// message object 8 is not valid
248 1 CAN_OBJ[7].MCR1 = 0x55; // set Message Control Register 1
249 1 CAN_OBJ[7].MCR0 = 0x55; // set Message Control Register 0
250 1
251 1
252 1 // ------------------------------------------------------------------------
253 1 /// ----------------- Configure Message Object 9 ---------------------------
254 1 // ------------------------------------------------------------------------
255 1 /// message object 9 is not valid
256 1 CAN_OBJ[8].MCR1 = 0x55; // set Message Control Register 1
257 1 CAN_OBJ[8].MCR0 = 0x55; // set Message Control Register 0
258 1
259 1
260 1 // ------------------------------------------------------------------------
261 1 /// ----------------- Configure Message Object 10 ---------------------------
262 1 // ------------------------------------------------------------------------
263 1 /// message object 10 is not valid
264 1 CAN_OBJ[9].MCR1 = 0x55; // set Message Control Register 1
265 1 CAN_OBJ[9].MCR0 = 0x55; // set Message Control Register 0
266 1
267 1
268 1 // ------------------------------------------------------------------------
269 1 /// ----------------- Configure Message Object 11 ---------------------------
270 1 // ------------------------------------------------------------------------
271 1 /// message object 11 is not valid
272 1 CAN_OBJ[10].MCR1 = 0x55; // set Message Control Register 1
273 1 CAN_OBJ[10].MCR0 = 0x55; // set Message Control Register 0
274 1
275 1
276 1 // ------------------------------------------------------------------------
277 1 /// ----------------- Configure Message Object 12 ---------------------------
278 1 // ------------------------------------------------------------------------
279 1 /// message object 12 is not valid
280 1 CAN_OBJ[11].MCR1 = 0x55; // set Message Control Register 1
281 1 CAN_OBJ[11].MCR0 = 0x55; // set Message Control Register 0
282 1
283 1
284 1 // ------------------------------------------------------------------------
285 1 /// ----------------- Configure Message Object 13 ---------------------------
286 1 // ------------------------------------------------------------------------
287 1 /// message object 13 is not valid
288 1 CAN_OBJ[12].MCR1 = 0x55; // set Message Control Register 1
289 1 CAN_OBJ[12].MCR0 = 0x55; // set Message Control Register 0
290 1
291 1
292 1 // ------------------------------------------------------------------------
293 1 /// ----------------- Configure Message Object 14 ---------------------------
294 1 // ------------------------------------------------------------------------
295 1 /// message object 14 is not valid
296 1 CAN_OBJ[13].MCR1 = 0x55; // set Message Control Register 1
297 1 CAN_OBJ[13].MCR0 = 0x55; // set Message Control Register 0
298 1
299 1
300 1 // ------------------------------------------------------------------------
301 1 /// ----------------- Configure Message Object 15 ---------------------------
302 1 // ------------------------------------------------------------------------
303 1 /// message object 15 is not valid
C51 COMPILER V7.06 CAN 10/23/2004 16:55:18 PAGE 6
304 1 CAN_OBJ[14].MCR1 = 0x55; // set Message Control Register 1
305 1 CAN_OBJ[14].MCR0 = 0x55; // set Message Control Register 0
306 1
307 1
308 1 /// ------------ CAN Control Register ---------------------
309 1 // reset CCE and INIT
310 1 CR = 0x0a;//set IE of the Control Register.
311 1 //TEST=0;CCE=0;EIE=0;SIE=0;IE=1;INIT=0.
312 1 // CR =0x02; // IE=1;
313 1 }
314
315 ////////////////////////与接收有关的函数/////////////////////////////////////////
316 //****************************************************************************
317 // @Function bit CAN_bNewData(unsigned char ObjNr)
318 //
319 //----------------------------------------------------------------------------
320 // @Description This function checks whether the selected RECEIVE OBJECT has
321 // received a new message. If so the function returns the
322 // value "1".
323 //
324 //----------------------------------------------------------------------------
325 // @Returnvalue 1 the message object has received a new message, else 0
326 //
327 //----------------------------------------------------------------------------
328 // @Parameters Number of the message object (1-15)
329 //
330 //----------------------------------------------------------------------------
331 // @Date 01-2-24 12:51:13
332 //
333 //****************************************************************************
334 /*
335 bit CAN_bNewData(unsigned char ObjNr)
336 {
337 bit bReturn;
338
339 bReturn = 0;
340 if((CAN_OBJ[ObjNr-1].MCR1 & 0x03) == 0x02) // if NEWDAT
341 {
342 bReturn = 1;
343 }
344 return(bReturn);
345 }
346 */
347 /*
348 //****************************************************************************
349 // @Function void CAN_vGetMsgObj(unsigned char ObjNr, unsigned char *BufferPointer)
350 //
351 //----------------------------------------------------------------------------
352 // @Description This function get the data block of the chosen message object.
353 //
354 //----------------------------------------------------------------------------
355 // @Returnvalue none
356 //
357 //----------------------------------------------------------------------------
358 // @Parameters Number of message object to be read (1-15)
359 // @Parameters Pointer to a buffer to be filled by this function.
360 //
361 //----------------------------------------------------------------------------
362 // @Date 01-2-24 12:51:13
363 //
364 //****************************************************************************/
365 /*
C51 COMPILER V7.06 CAN 10/23/2004 16:55:18 PAGE 7
366 void CAN_vGetMsgObj(unsigned char ObjNr,unsigned char * BufferPointer)
367 {
368 unsigned char i;
369 for(i = 0; i < (CAN_OBJ[ObjNr-1].MCFG & 0xf0) >> 4; i++)
370 {
371 * (BufferPointer++)= CAN_OBJ[ObjNr-1].Data[i];//get the data block
372 }
373 if(ObjNr < 15 || (CAN_OBJ[ObjNr-1].MCR0 & 0x0c) != 0x08)
374 {
375 CAN_OBJ[ObjNr-1].MCR1 = 0xfd; // reset NEWDAT
376 }
377
378 }
379 */
380 //****************************************************************************
381 // @Function void CAN_vStoreMsgObj(unsigned char ObjNr,unsigned char *BasePointer)
382 //
383 //----------------------------------------------------------------------------
384 // @Description This function store the data block of the chosen message object
385 // to the buffer specified by BufferPointer and identifier
386 //
387 //----------------------------------------------------------------------------
388 // @Returnvalue none
389 //
390 //----------------------------------------------------------------------------
391 // @Parameters ObjNr---Number of message object to be read (1-15)
392 // BasePointer----base pointer of the data buffer.
393 //----------------------------------------------------------------------------
394 // @Date 01-10-30 9:51:13
395 //
396 //****************************************************************************/
397 void CAN_vStoreMsgObj(unsigned char ObjNr,unsigned char * BasePointer)
398 {
399 1 unsigned char i;
400 1 unsigned int id;
401 1 id=CAN_OBJ[ObjNr-1].UAR0; //id's high 8 bit
402 1 id=(id<<8 | CAN_OBJ[ObjNr-1].UAR1)>>5;//change id to int
403 1 //##############################################
404 1 //BasePointer+=((id-1)<<3); //address the buffer by id
405 1 //##################################################
406 1 BasePointer+=(id<<3); //address the buffer by id
407 1 for(i = 0; i <8; i++)
408 1 {
409 2 * BasePointer= CAN_OBJ[ObjNr-1].Data[i];//get the data block
410 2 BasePointer++;
411 2 }
412 1 if(ObjNr < 15 || (CAN_OBJ[ObjNr-1].MCR0 & 0x0c) != 0x08)
413 1 {
414 2 CAN_OBJ[ObjNr-1].MCR1 = 0xfd; // reset NEWDAT
415 2 }
416 1
417 1 }
418
419 //****************************************************************************
420 // @Function void CAN_vStoreID(unsigned char ObjNr,unsigned char *BasePointer)
421 //
422 //----------------------------------------------------------------------------
423 // @Description This function store identifier of the chosen message object
424 // to the buffer specified by BufferPointer and identifier
425 //
426 //----------------------------------------------------------------------------
427 // @Returnvalue none
C51 COMPILER V7.06 CAN 10/23/2004 16:55:18 PAGE 8
428 //
429 //----------------------------------------------------------------------------
430 // @Parameters ObjNr---Number of message object to be read (1-15)
431 // BasePointer----base pointer of the data buffer.
432 //----------------------------------------------------------------------------
433 // @Date 01-10-30 9:51:13
434 //
435 //****************************************************************************/
436 void CAN_vStoreID(unsigned char ObjNr,unsigned char * BasePointer)
437 {
438 1 unsigned int id;
439 1 id=CAN_OBJ[ObjNr-1].UAR0; //id's high 8 bit
440 1 id=(id<<8 | CAN_OBJ[ObjNr-1].UAR1)>>5;//change id to int
441 1 if(id<=10)
442 1 {
443 2 BasePointer+=(id-1);
444 2 (*BasePointer)=(unsigned char)id;
445 2 }
446 1 }
447
448
449 //////////////////////////////与发送有关函数////////////////////////////////////
450 //****************************************************************************
451 // @Function bit CAN_bRequestMsgObj(unsigned char ObjNr)
452 //
453 //----------------------------------------------------------------------------
454 // @Description If a TRANSMIT OBJECT is to be reconfigured it must first be
455 // accessed. The access to the transmit object is exclusive.
456 // This function checks whether the choosen message object is
457 // still executing a transmit request, or if the object can
458 // be accessed exclusively.
459 // After the message object is reserved, it can be reconfigured
460 // by using the function CAN_vConfigMsgObj or CAN_vLoadData.
461 // Both functions enable access to the object for the CAN
462 // controller.
463 // By calling the function CAN_vTransmit transfering of data
464 // is started.
465 //
466 //----------------------------------------------------------------------------
467 // @Returnvalue 0 message object is busy (a transfer is actice), else 1
468 //
469 //----------------------------------------------------------------------------
470 // @Parameters Number of the message object (1-14)
471 //
472 //----------------------------------------------------------------------------
473 // @Date 01-2-24 12:51:13
474 //
475 //****************************************************************************
476
477 bit CAN_bRequestMsgObj(unsigned char ObjNr)
478 {
479 1 bit bReturn;
480 1
481 1 bReturn = 0;
482 1 if((CAN_OBJ[ObjNr-1].MCR1 & 0x30) == 0x10) // if TXRQ==0
483 1 {
484 2 CAN_OBJ[ObjNr-1].MCR1 = 0xfb; // set CPUUPD
485 2 bReturn = 1;
486 2 }
487 1 return(bReturn);
488 1 }
489
C51 COMPILER V7.06 CAN 10/23/2004 16:55:18 PAGE 9
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -