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

📄 can.lst

📁 xc164的双can的使用例程
💻 LST
📖 第 1 页 / 共 5 页
字号:
C166 COMPILER V6.02, CAN                                                                   08/28/2006 10:05:47 PAGE 1   


C166 COMPILER V6.02, COMPILATION OF MODULE CAN
OBJECT MODULE PLACED IN CAN.OBJ
COMPILER INVOKED BY: C:\Keil\C166\BIN\C166.EXE CAN.C MODV2 BROWSE MODV2 DEBUG

 stmt lvl     source

    1         //****************************************************************************
    2         // @Module        TwinCAN Module (CAN)
    3         // @Filename      CAN.C
    4         // @Project       TWINCAN.dav
    5         //----------------------------------------------------------------------------
    6         // @Controller    Infineon XC164CS-16F
    7         //
    8         // @Compiler      Keil
    9         //
   10         // @Codegenerator 2.7
   11         //
   12         // @Description   This file contains functions that use the CAN module.
   13         //
   14         //----------------------------------------------------------------------------
   15         // @Date          12/17/2004 7:07:09 PM
   16         //
   17         //****************************************************************************
   18         
   19         // USER CODE BEGIN (CAN_General,1)
   20         
   21         // USER CODE END
   22         
   23         
   24         
   25         //****************************************************************************
   26         // @Project Includes
   27         //****************************************************************************
   28         
   29         #include "MAIN.H"
   30         
   31         // USER CODE BEGIN (CAN_General,2)
   32         
   33         // USER CODE END
   34         
   35         
   36         //****************************************************************************
   37         // @Macros
   38         //****************************************************************************
   39         
   40         // USER CODE BEGIN (CAN_General,3)
   41         
   42         // USER CODE END
   43         
   44         
   45         //****************************************************************************
   46         // @Defines
   47         //****************************************************************************
   48         
   49         // Structure for a single TwinCAN object
   50         // A total of 31 such object structures exists
   51         
   52         struct stCanObj 
   53         {
   54           ubyte  ubData[8];  // Message Data 0..7
   55           ulong  ulCANAR;    // Arbitration Register
C166 COMPILER V6.02, CAN                                                                   08/28/2006 10:05:47 PAGE 2   

   56           ulong  ulCANAMR;   // Acceptance Mask Register
   57           uword  uwMSGCTR;   // Message Control Register
   58           uword  uwCounter;  // Frame Counter
   59           uword  uwMSGCFG;   // Message Configuration Register
   60           uword  uwINP;      // Interrupt Node Pointer
   61           uword  uwCANFCR;   // FIFO / Gateway Control Register 
   62           uword  uwCANPTR;   // FIFO Pointer
   63           ulong  ulReserved; // Reserved
   64         };
   65         
   66         #define CAN_HWOBJ ((struct stCanObj volatile far *) 0x200300)
   67         
   68         // USER CODE BEGIN (CAN_General,4)
   69         
   70         // USER CODE END
   71         
   72         
   73         //****************************************************************************
   74         // @Typedefs
   75         //****************************************************************************
   76         
   77         // USER CODE BEGIN (CAN_General,5)
   78         
   79         // USER CODE END
   80         
   81         
   82         //****************************************************************************
   83         // @Imported Global Variables
   84         //****************************************************************************
   85         
   86         // USER CODE BEGIN (CAN_General,6)
   87         
   88         // USER CODE END
   89         
   90         
   91         //****************************************************************************
   92         // @Global Variables
   93         //****************************************************************************
   94         
   95         
   96         // USER CODE BEGIN (CAN_General,7)
   97         
   98         // USER CODE END
   99         
  100         
  101         //****************************************************************************
  102         // @External Prototypes
  103         //****************************************************************************
  104         
  105         // USER CODE BEGIN (CAN_General,8)
  106         
  107         // USER CODE END
  108         
  109         
  110         //****************************************************************************
  111         // @Prototypes Of Local Functions
  112         //****************************************************************************
  113         
  114         // USER CODE BEGIN (CAN_General,9)
  115         
  116         // USER CODE END
  117         
C166 COMPILER V6.02, CAN                                                                   08/28/2006 10:05:47 PAGE 3   

  118         
  119         //****************************************************************************
  120         // @Function      void CAN_vInit(void) 
  121         //
  122         //----------------------------------------------------------------------------
  123         // @Description   This is the initialization function of the CAN function 
  124         //                library. It is assumed that the SFRs used by this library 
  125         //                are in its reset state. 
  126         //
  127         //----------------------------------------------------------------------------
  128         // @Returnvalue   None
  129         //
  130         //----------------------------------------------------------------------------
  131         // @Parameters    None
  132         //
  133         //----------------------------------------------------------------------------
  134         // @Date          12/17/2004
  135         //
  136         //****************************************************************************
  137         
  138         // USER CODE BEGIN (Init,1)
  139         
  140         // USER CODE END
  141         
  142         void CAN_vInit(void)
  143         {
  144  1      
  145  1        // USER CODE BEGIN (Init,2)
  146  1      
  147  1        // USER CODE END
  148  1      
  149  1        ///  -----------------------------------------------------------------------
  150  1        ///  Configuration of CAN Node A:
  151  1        ///  -----------------------------------------------------------------------
  152  1      
  153  1        ///  General Configuration of the Node A:
  154  1        ///  - set INIT and CCE
  155  1      
  156  1        CAN_ACR        =  0x0041;      // load global control register
  157  1        CAN_AGINP      =  0x0000;      // load global interrupt node pointer 
  158  1                                       // register
  159  1      
  160  1        ///  Configuration of the Node A Error Counter:
  161  1        ///  - the error warning threshold value (warning level) is 96
  162  1      
  163  1        CAN_AECNTH     =  0x0060;      // load error counter register high
  164  1      
  165  1        ///  Configuration of the used CAN Port Pins:
  166  1        ///  - P4.5 is used for CAN Interface Input (RXDCA)
  167  1        ///  - P4.6 is used for CAN Interface Output (TXDCA)
  168  1      
  169  1        ALTSEL0P4     |=  0x0040;      // select alternate output function
  170  1        DP4  = (DP4  & ~(uword)0x0040) | 0x0040;    //set direction register
  171  1      
  172  1        ///  Configuration of the Node A Baud Rate:
  173  1        ///  - required baud rate = 10.000 kbaud
  174  1        ///  - real baud rate     = 10.000 kbaud
  175  1        ///  - sample point       = 60.00 %
  176  1        ///  - there are 5 time quanta before sample point
  177  1        ///  - there are 4 time quanta after sample point
  178  1        ///  - the (re)synchronization jump width is 2 time quanta
  179  1        ///  - enable the module clock divider (by 8)
C166 COMPILER V6.02, CAN                                                                   08/28/2006 10:05:47 PAGE 4   

  180  1      
  181  1        CAN_ABTRL      =  0xB471;      // load bit timing register low
  182  1      
  183  1        CAN_ABTRH      =  0x0000;      // load bit timing register high
  184  1      
  185  1        CAN_AFCRL      =  0x0000;      // load frame counter timing register low
  186  1      
  187  1        CAN_AFCRH      =  0x0000;      // load frame counter timing register high
  188  1      
  189  1        ///  -----------------------------------------------------------------------
  190  1        ///  Configuration of CAN Node B:
  191  1        ///  -----------------------------------------------------------------------
  192  1      
  193  1        ///  General Configuration of the Node B:
  194  1        ///  - set INIT and CCE
  195  1      
  196  1        CAN_BCR        =  0x0041;      // load global control register
  197  1        CAN_BGINP      =  0x0000;      // load global interrupt node pointer 
  198  1                                       // register
  199  1      
  200  1        ///  Configuration of the Node B Error Counter:
  201  1        ///  - the error warning threshold value (warning level) is 96
  202  1      
  203  1        CAN_BECNTH     =  0x0060;      // load error counter register high
  204  1      
  205  1        ///  Configuration of the used CAN Port Pins:
  206  1        ///  - P9.0 is used for CAN Interface Input (RXDCB)
  207  1        ///  - P9.1 is used for CAN Interface Output (TXDCB)
  208  1      
  209  1        ALTSEL0P9     |=  0x0002;      // select alternate output function
  210  1        ALTSEL1P9     |=  0x0002;      // select alternate output function
  211  1        DP9  = (DP9  & ~(uword)0x0002) | 0x0002;    //set direction register

⌨️ 快捷键说明

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