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

📄 int.lst

📁 2个F040之间的CAN通讯
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.10   INT                                                                   07/27/2008 17:14:41 PAGE 1   


C51 COMPILER V7.10, COMPILATION OF MODULE INT
OBJECT MODULE PLACED IN int.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE int.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "c8051f040.h"
   2          #include "can.h"
   3          
   4          extern unsigned char   DO_Address;
   5          extern unsigned char  temp1,temp2;
   6          extern unsigned char  DO_Control_Data_New0,DO_Control_Data_New1;
   7          
   8          
   9          //xdata unsigned char ss[8]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
  10          xdata unsigned char rr[8]={0,0,0,0,0,0,0,0};
  11          
  12          //-----------------------------------------------------------------------------
  13          // SYSCLK_Init
  14          //-----------------------------------------------------------------------------
  15          void SYSCLK_Init (void) 
  16          {
  17   1        SFRPAGE = 0xF;
  18   1        OSCXCN |= 0x67;                                          //Running at 22.1184MHz.     
  19   1        while (!((OSCXCN & 0x80) == 0x80));
  20   1        CLKSEL |= 0x01;
  21   1      }
  22           
  23          //-----------------------------------------------------------------------------
  24          // PORT_Init
  25          //-----------------------------------------------------------------------------
  26          void PORT_Init (void) 
  27          {
  28   1        SFRPAGE = 0xF;
  29   1      XBR1 |= 0x00;
  30   1        XBR1 |= 0x04;              //INT0 Routed To Port Pin
  31   1        XBR2 |= 0x40;              //If crossbar is disabled, all ports are in input mode.  
  32   1        XBR3 |= 0x80;              //CTX pin's output mode is configured as push-pull.
  33   1      //P0MDOUT = 0x00;
  34   1      //P1MDIN =0xFF;
  35   1        P4MDOUT = 0x03;            //CANLED and ENABLE
  36   1        P5MDOUT = 0x00;            //OUTPUT CONTROL PORT
  37   1        P6MDOUT = 0x00;            //OUTPUT CONTROL PORT
  38   1      }
  39          
  40          //-----------------------------------------------------------------------------
  41          // INT_Init
  42          // Interrupts By Priority : INT0 > CAN0
  43          //-----------------------------------------------------------------------------
  44          void INT_Init (void) 
  45          {
  46   1        IE   |= 0x03;              //INT0 Interrupt Enabled        
  47   1                                   //Timer0 Interrupt Enabled
  48   1      //  IE   |= 0x01;              //INT0 Interrupt Enabled
  49   1        EIE2 |= 0x20;              //CAN0 Interrupt Enabled
  50   1      }
  51          
  52          
  53          //-----------------------------------------------------------------------------
  54          // CAN_Init
  55          // CAN0CN  :  Automatic Retransmission is Disable. Error and Status Interrrupt 
C51 COMPILER V7.10   INT                                                                   07/27/2008 17:14:41 PAGE 2   

  56          //            is Disabled. Module Interrrup is eabled.
  57          // BITREG  :  BaudRate is 1M/8(b/s).
  58          // CAN0TST :  Tx1, Tx0, LBack and Silenct are all 0. Use Basic Mode.
  59          //-----------------------------------------------------------------------------
  60          void CAN_Init (void) 
  61          {
  62   1        SFRPAGE = CAN0_PAGE;
  63   1        CAN0CN = 0xC3;
  64   1        CAN0ADR = 0x03;
  65   1        CAN0DATH = 0x5E;
  66   1        CAN0DATL = 0xC7;
  67   1        CAN0TST = 0x10;      //LBack  /*正常工作没有影响*/
  68   1      }
  69          
  70          void CAN_Start(void)
  71          {
  72   1        SFRPAGE = CAN0_PAGE;
  73   1        CAN0CN = 0x02;                //
  74   1      }
  75          
  76          //-----------------------------------------------------------------------------
  77          // CAN_Transmit_Init(unsigned char MsgNum , unsigned char id)
  78          // wr/rd=1,mask=0,arb=1,control=1,,clrintpnd=0,txrqet=0,dataA=1,dataB=1
  79          // MsgVal=1, Xad=0,Dir=1:send
  80          // not use the filter,UMask=0,RmtEn=0,eob=1, dlc =8
  81          //-----------------------------------------------------------------------------
  82          void CAN_Transmit_Init (unsigned char MsgNum , unsigned char id) 
  83          {  
  84   1      /*
  85   1        unsigned char id_tempL,id_tempH;
  86   1        id_tempL = id << 2;          //  id & 0x0F) << 2
  87   1        id_tempH = id >> 6;
  88   1        id_tempH = id_tempH || 0xA0;  // MsgVal=1, Dir =1
  89   1      */
  90   1      
  91   1        SFRPAGE = CAN0_PAGE;
  92   1        CAN0ADR = IF1CMDMSK;
  93   1        CAN0DATL = 0xb3;    //wr/rd=1,mask=0,arb=1,control=1,,clrintpnd=0,txrqet=0,dataa=1,datab=1
  94   1      
  95   1      //  CAN0ADR = IF1MSK1;
  96   1      //  CAN0DATH = 0x00;
  97   1       // CAN0DATL = 0x00;
  98   1      //  CAN0DATH = 0x00;                                    //!!bit 13  :not use
  99   1      //  CAN0DATL = 0x00;           //IF1MSK
 100   1      
 101   1        CAN0ADR = IF1ARB1;
 102   1        CAN0DATH = 0x00;
 103   1        CAN0DATL = 0x00;
 104   1        CAN0DATH = 0xA0;      //
 105   1        CAN0DATL =  (id << 2 ) & 0x3C;    //0x80 | (((DO_Address & 0x0F) << 2)); //IF1ARB
 106   1                       //MsgVal=1, Xad=0,Dir=1:send 
 107   1        CAN0DATH = 0x00;           // not use the filter,UMask=0,RmtEn=0
 108   1        CAN0DATL = 0x88;           //IF1MSGC: eob=1, dlc =8
 109   1      
 110   1        CAN0DATH = 0x00;
 111   1        CAN0DATL = 0x00;                      //data A1
 112   1        CAN0DATH = 0x00;
 113   1        CAN0DATL = 0x00;                      //data A2                                               
 114   1        CAN0DATH = 0x00;
 115   1        CAN0DATL = 0x00;                      //data B1
 116   1        CAN0DATH = 0x00;
 117   1        CAN0DATL = 0x00;          //data B2
C51 COMPILER V7.10   INT                                                                   07/27/2008 17:14:41 PAGE 3   

 118   1      
 119   1        CAN0ADR = IF1CMDRQST;      
 120   1        CAN0DATL = MsgNum;           //
 121   1      }
 122          
 123          //-----------------------------------------------------------------------------
 124          // CAN_Receive_Init(unsigned char MsgNum , unsigned char id)
 125          // wr/rd=1,mask=0,arb=1,control=1,,clrintpnd=0,txrqet=0,dataA=1,dataB=1
 126          // MsgVal=1, Xad=0,Dir=0:receive
 127          // not use the filter,UMask=0,RmtEn=0,eob=1, dlc =8,  RxEn=1
 128          //-----------------------------------------------------------------------------
 129          void CAN_Receive_Init (unsigned char MsgNum , unsigned char id) 
 130          {
 131   1      /*
 132   1        unsigned char id_tempL,id_tempH;
 133   1        id_tempL = id << 2;          //  id & 0x0F) << 2
 134   1        id_tempH = id >> 6;
 135   1        id_tempH = id_tempH || 0x80;  // MsgVal=1, Dir =0
 136   1      */
 137   1      
 138   1        SFRPAGE = CAN0_PAGE;
 139   1        CAN0ADR = IF2CMDMSK;
 140   1        CAN0DATL = 0xbb;    //wr/rd=1,mask=0,arb=1,control=1,,clrintpnd=1,txrqet=0,dataa=1,datab=1
 141   1      
 142   1      //  CAN0ADR = IF2MSK1;
 143   1      //  CAN0DATH = 0x00;
 144   1      //  CAN0DATL = 0x00;
 145   1      //  CAN0DATH = 0x00;                            //0x23;
 146   1      //  CAN0DATL = 0xF4;           //IF2MSK  0xco;
 147   1      
 148   1        CAN0ADR = IF2ARB1;
 149   1        CAN0DATH = 0x00;
 150   1        CAN0DATL = 0x00;
 151   1        CAN0DATH = 0x80;
 152   1        CAN0DATL = (id << 2 ) & 0x3C;            //IF2ARB
 153   1                       //MsgVal=1, Xad=0,Dir=0:get 
 154   1        CAN0DATH = 0x04;           //not use the filter,RxEn=1
 155   1        CAN0DATL = 0x88;           //IF2MSGC,, eob=1, dlc =8
 156   1      
 157   1        CAN0DATH = 0x00;
 158   1        CAN0DATL = 0x00;                      //data A1
 159   1        CAN0DATH = 0x00;
 160   1        CAN0DATL = 0x00;                      //data A2                                               
 161   1        CAN0DATH = 0x00;
 162   1        CAN0DATL = 0x00;                      //data B1
 163   1        CAN0DATH = 0x00;
 164   1        CAN0DATL = 0x00;          //data B2
 165   1      
 166   1        CAN0ADR = IF2CMDRQST;      
 167   1        CAN0DATL = MsgNum;           //
 168   1      }
 169          
 170          //-----------------------------------------------------------------------------
 171          // Timer_Init

⌨️ 快捷键说明

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