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

📄 canmain.lst

📁 C8051F020控制的SJA1000can总线芯片的驱动程序
💻 LST
字号:
C51 COMPILER V7.50   CANMAIN                                                               09/12/2006 17:28:29 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE CANMAIN
OBJECT MODULE PLACED IN canmain.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE canmain.c DEBUG OBJECTEXTEND

line level    source

   1          #pragma  REGPARMS
   2          #include <math.h>
   3          #include <stdlib.h>
   4          #include <stdio.h>
   5          #include <string.h>
   6          #include "c8051f020.h"
   7          #include "can20.h"
   8          #define BAUDRATE  115200              // Baud rate of UART in bps
   9          #define SYSCLK    22118400          // SYSCLK frequency in Hz
  10          unsigned char SendBuffer[11];
  11          unsigned char GetBuffer[11];
  12          unsigned char GETOK;
  13          void config (void) {
  14   1      
  15   1      //Local Variable Definitions
  16   1              WDTCN = 0x07;   // Watchdog Timer Control Register
  17   1          WDTCN = 0xDE;   // Disable WDT
  18   1          WDTCN = 0xAD;
  19   1      
  20   1              XBR0 = 0xEF;    // XBAR0: Initial Reset Value
  21   1              XBR1 = 0x07;    // XBAR1: Initial Reset Value
  22   1              XBR2 = 0x44;    // XBAR2: Initial Reset Value
  23   1      // Port configuration (1 = Push Pull Output)
  24   1          P0MDOUT = 0x1D; // Output configuration for P0 
  25   1          P1MDOUT = 0x01; // Output configuration for P1 
  26   1          P2MDOUT = 0x03; // Output configuration for P2 
  27   1          P3MDOUT = 0x00; // Output configuration for P3 
  28   1          P74OUT = 0xff;  // Output configuration for P4-7
  29   1          P1MDIN = 0xFF;  // Input configuration for P1
  30   1      // View port pinout
  31   1      
  32   1                      // The current Crossbar configuration results in the 
  33   1                      // following port pinout assignment:
  34   1                      // Port 0
  35   1                      // P0.0 = UART TX0        (Push-Pull Output)
  36   1                      // P0.1 = UART RX0        (Open-Drain Output/Input)
  37   1                      // P0.2 = SPI Bus SCK     (Push-Pull Output)
  38   1                      // P0.3 = SPI Bus MISO    (Push-Pull Output)
  39   1                      // P0.4 = SPI Bus MOSI    (Push-Pull Output)
  40   1                      // P0.5 = SPI Bus NSS     (Open-Drain Output/Input)
  41   1                      // P0.6 = SMBus SDA       (Open-Drain Output/Input)
  42   1                      // P0.7 = SMBus SCL       (Open-Drain Output/Input)
  43   1      
  44   1                      // Port 1
  45   1                      // P1.0 = UART TX1        (Push-Pull Output)(Digital)
  46   1                      // P1.1 = UART RX1        (Open-Drain Output/Input)(Digital)
  47   1                      // P1.2 = PCA CEX0        (Open-Drain Output/Input)(Digital)
  48   1                      // P1.3 = PCA CEX1        (Open-Drain Output/Input)(Digital)
  49   1                      // P1.4 = PCA CEX2        (Open-Drain Output/Input)(Digital)
  50   1                      // P1.5 = PCA CEX3        (Open-Drain Output/Input)(Digital)
  51   1                      // P1.6 = PCA CEX4        (Open-Drain Output/Input)(Digital)
  52   1                      // P1.7 = PCA ECI         (Open-Drain Output/Input)(Digital)
  53   1                                              
  54   1                      // Port 2               
  55   1                      // P2.0 = CP0             (Push-Pull Output)
C51 COMPILER V7.50   CANMAIN                                                               09/12/2006 17:28:29 PAGE 2   

  56   1                      // P2.1 = CP1             (Push-Pull Output)
  57   1                      // P2.2 = T0              (Open-Drain Output/Input)
  58   1                      // P2.3 = /INT0           (Open-Drain Output/Input)
  59   1                      // P2.4 = GP I/O          (Open-Drain Output/Input)
  60   1                      // P2.5 = GP I/O          (Open-Drain Output/Input)
  61   1                      // P2.6 = GP I/O          (Open-Drain Output/Input)
  62   1                      // P2.7 = GP I/O          (Open-Drain Output/Input)
  63   1      
  64   1                      // Port 3               
  65   1                      // P3.0 = GP I/O          (Open-Drain Output/Input)
  66   1                      // P3.1 = GP I/O          (Open-Drain Output/Input)
  67   1                      // P3.2 = GP I/O          (Open-Drain Output/Input)
  68   1                      // P3.3 = GP I/O          (Open-Drain Output/Input)
  69   1                      // P3.4 = GP I/O          (Open-Drain Output/Input)
  70   1                      // P3.5 = GP I/O          (Open-Drain Output/Input)
  71   1                      // P3.6 = GP I/O          (Open-Drain Output/Input)
  72   1                      // P3.7 = GP I/O          (Open-Drain Output/Input)
  73   1      
  74   1          EMI0CF = 0x24;    // External Memory Configuration Register
  75   1              EMI0CN=0x00;
  76   1          EMI0TC=0x01;
  77   1      }
  78          void SYSCLK_Init (void)
  79          {
  80   1         int data i;                              // delay counter
  81   1         OSCXCN = 0x67;                      // start external oscillator with
  82   1                                             // 22.1184MHz crystal
  83   1         for (i=0; i < 256; i++) ;           // XTLVLD blanking interval (>1ms)
  84   1         while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle
  85   1         OSCICN = 0x88;                      // select external oscillator as SYSCLK
  86   1                                             // source and enable missing clock
  87   1                                             // detector
  88   1      }
  89          void UART0_Init (void)
  90          {
  91   1         SCON0   = 0x50;                     // SCON0: T1 mode 1, 8-bit UART, enable RX
  92   1                                            
  93   1         TMOD    = 0x21;                     // TMOD: timer 1, mode 2, 8-bit reload
  94   1                                             // T0 16 bit Timer
  95   1         T2CON &= 0x0cf;                     //select T1 as  baudrate 
  96   1         TH1    = -(SYSCLK/BAUDRATE/16);     // set Timer1 reload value for baudrate
  97   1         TR1    = 1;                         // start Timer1
  98   1         CKCON |= 0x10;                      // Timer1 uses SYSCLK as time base
  99   1         PCON  |= 0x80;                      // SMOD00 = 1
 100   1         
 101   1      }
 102          unsigned char Can_Init(void)
 103          {
 104   1       unsigned char tt;
 105   1       unsigned int i;
 106   1       P3=0xff;
 107   1       for(i=0;i<1000;i++);
 108   1       P3=0x00;
 109   1       for(i=0;i<1000;i++);
 110   1       P3=0xff;
 111   1       for(i=0;i<1000;i++);
 112   1       ModeControlReg= RM_RR_Bit;
 113   1       tt=ModeControlReg;
 114   1       ClockDivideReg=0x88;
 115   1       InterruptEnReg=0xff;
 116   1       BusTiming0Reg= 0x03; //100 K
 117   1       BusTiming1Reg=0x2f;
C51 COMPILER V7.50   CANMAIN                                                               09/12/2006 17:28:29 PAGE 3   

 118   1       AcceptCode0Reg=0x57;
 119   1       AcceptCode1Reg=0x00;
 120   1       AcceptCode2Reg=0xaa;
 121   1       AcceptCode3Reg=0x55;
 122   1       AccepMask0Reg=0x00;
 123   1       AccepMask1Reg=0xff;
 124   1       AccepMask2Reg=0xff;
 125   1       AccepMask3Reg=0xff;
 126   1       
 127   1       RxBufstartAdr=0;
 128   1       TxErrCountReg=0;
 129   1       RxErrCountReg=0;
 130   1       ErrCodeCapReg=0;
 131   1       OutControlReg=0x1a;
 132   1       ModeControlReg=AFM_Bit;
 133   1       
 134   1       tt=StatusReg;
 135   1       while(tt==0x10)
 136   1       tt=StatusReg; 
 137   1       return tt;
 138   1      }
 139          unsigned char WriteCan()
 140          {
 141   1       unsigned char * xdata tt;
 142   1       unsigned int i;
 143   1       unsigned char tt1;
 144   1       SendBuffer[0]=0x08;
 145   1       SendBuffer[1]=0x01;
 146   1       SendBuffer[2]=0x08;
 147   1       SendBuffer[3]=0x57;
 148   1       SendBuffer[4]=0x00;
 149   1       SendBuffer[5]=0x00;
 150   1       SendBuffer[6]=0x0;
 151   1       SendBuffer[7]=0x0;
 152   1       SendBuffer[8]=0x0;
 153   1       SendBuffer[9]=0x0;
 154   1       SendBuffer[10]=0x0;
 155   1       tt=&TxFramInFo;
 156   1       
 157   1       tt1=StatusReg;
 158   1       while((tt1&RS_Bit)!=0x00)
 159   1       tt1=StatusReg; 
 160   1       
 161   1       tt1=StatusReg;
 162   1       while((tt1&TCS_Bit)==0x00)
 163   1       tt1=StatusReg;
 164   1       for(i=0;i<11;i++)
 165   1       {*tt=SendBuffer[i];
 166   2        tt++;
 167   2       }
 168   1       CommandReg=TR_Bit;
 169   1       tt1=StatusReg;
 170   1       tt1=InterruptReg;
 171   1       return tt1;
 172   1      }
 173          void INTE0_ISR (void) interrupt 0
 174          {
 175   1        unsigned char tt1;
 176   1        unsigned char * xdata tt;
 177   1        unsigned int i,count;
 178   1        tt1=InterruptReg;
 179   1        if((tt1&0x80)!=0)
C51 COMPILER V7.50   CANMAIN                                                               09/12/2006 17:28:29 PAGE 4   

 180   1        {ModeControlReg=AFM_Bit;
 181   2         return;
 182   2        }
 183   1        if((tt1&0x08)!=0)
 184   1        {CommandReg=0x0c;
 185   2         return;
 186   2        }
 187   1        if((tt1&0x01)!=0)
 188   1        {tt=&RxFramInFo;
 189   2         count=(*tt&0x0f);
 190   2         if((*tt&0x80)==0)
 191   2         count+=3;
 192   2         else
 193   2         count+=5;
 194   2         for(i=0;i<count;i++)
 195   2         {GetBuffer[i]=*tt;
 196   3          tt++;
 197   3         }
 198   2        for(i=0;i<count;i++)
 199   2        {SBUF0=GetBuffer[i];
 200   3         while(TI0==0);
 201   3         TI0=0;
 202   3         }
 203   2        CommandReg=RRB_Bit;
 204   2        GETOK=1;
 205   2        }
 206   1        tt1=ArbLostCapReg;
 207   1        tt1=ErrCodeCapReg; 
 208   1        return;
 209   1      }
 210          main()
 211          {
 212   1       SYSCLK_Init();
 213   1       config();
 214   1       UART0_Init();
 215   1      
 216   1      
 217   1       Can_Init();
 218   1       EA=1;
 219   1       EX0=1;
 220   1       GETOK=1;
 221   1       while(1)
 222   1       if(GETOK==0x01)
 223   1       {WriteCan();
 224   2       // GETOK=0;
 225   2       } 
 226   1      }
 227          
 228          
 229          
 230          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    633    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----       6
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     23       3
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.

C51 COMPILER V7.50   CANMAIN                                                               09/12/2006 17:28:29 PAGE 5   


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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