⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a_canx1.c

📁 This ZIP file contains the support files for programming the Infineon C167CR CAN interface. Refer to
💻 C
字号:
/******************************************************************************
C167CR CAN Ap. Note project
Main - a_canx1

This is an example program showing how to use the CAN interface on the Keil
MCB167 evaluation board.

Copyright (c) 1997 Keil Software
******************************************************************************/
#include <stdio.h>
#include <intrins.h>
#include "can_ifc.h"
#include "timer.h"
#include "can_msgs.h"

#define TIME_MO 1 /* message object number for time message */


/******************************************************************************
Setup CAN controller

Returns: nothing
-----------------------------------------------------------------------------*/
void
setup_can(void)
{
   begin_can_init();

   /* These mask values tell the CAN controller that all bits in a
      message id. are significant when comparing the id of a received message
      to the id's in the arbitration registers of the message objects.
   */
   CAN_MASK_SHORT = 0xffff;
   CAN_UMASK_LONG = 0xffff;
   CAN_LMASK_LONG = 0xf8ff;

   /* Since this program doesn't use message object 15, it is unnecessary
      to initialize the 'mask of last message' registers (CAN_UMASK_LAST and
      CAN_LMASK_LAST).
   */

   CAN_MSGOBJ[TIME_MO].msg_ctl = MSGVAL_CLR;
   CAN_MSGOBJ[TIME_MO].arbitr = ARBITR(CAN_TIME_MSG);
   CAN_MSGOBJ[TIME_MO].msg_cfg = MSG_CFG(LEN_CAN_TIME_MSG, CANDIR_TRANSMIT, 0);
   /* We're not initializing the data field right now, so we set
      CPUUPD to prevent the message from being transmitted in
      response to a remote frame.  
   */
   CAN_MSGOBJ[TIME_MO].msg_ctl =
      /* clear bits     set bits */
         INTPND_CLR &
         RXIE_CLR &
         TXIE_CLR &
                        MSGVAL_SET &
         NEWDAT_CLR &
                        CPUUPD_SET &
         TXRQ_CLR &
         RMTPND_CLR;

   /* CAN_IE_ must be set for any CAN interrupts to occur.
      CAN_EIE_ must be set for CAN error status change interrupts to occur.
   */
   end_can_init(CAN_IE_ | CAN_EIE_);
}


/******************************************************************************
main

This program does the following:
   Set up the CAN controller, with a message object for the time stamp message
      as a transmit object.
   Setup a timer to generate periodic interrupts.
   Loop forever, periodically updating the time stamp message object.

The CAN controller will transmit the time stamp message when it receives a
remote frame for it, without any intervention from the CPU.

Returns: never
-----------------------------------------------------------------------------*/
void
main(void)
{
   printf("Program A start\n");


   /* Set up */
   setup_can();      /* set up CAN interface */
   init_timer();     /* initialize timing */

   /* Run */
   while (1) {       /* infinite loop */
      unsigned long t;

      t = timer();
      update_can_transmit_message(TIME_MO, &t, LEN_CAN_TIME_MSG);

      /* Put the processor in idle mode to conserve power.
         The next interrupt (from the timer) will wake it up again.
      */
      _idle_();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -