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

📄 can232.lst

📁 C8051F020控制的SJA1000can总线芯片的驱动程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   CAN232                                                                09/12/2006 21:12:06 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE CAN232
OBJECT MODULE PLACED IN can232.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE can232.c OPTIMIZE(0,SPEED) BROWSE 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[13];
  11          unsigned char GetBuffer[13];
  12          unsigned char CommBuffer[15];
  13          unsigned char CommP;
  14          int  CommRP,CommRCount;
  15          int  Can0RP,Can0RCount;
  16          int  Can0TP;
  17          int  CommTP;
  18          unsigned char xdata  CommRBuffer[1024];
  19          //unsigned char xdata  CommRBuffer[1024]={0x08,0x55,0x00,0x11,0x22,0x33,0x55,0x44,0x360,0x44,0x36};
  20          unsigned char xdata  Can0RBuffer[1024];
  21          void config (void) {
  22   1      
  23   1      //Local Variable Definitions
  24   1              WDTCN = 0x07;   // Watchdog Timer Control Register
  25   1          WDTCN = 0xDE;   // Disable WDT
  26   1          WDTCN = 0xAD;
  27   1      
  28   1              XBR0 = 0xEF;    // XBAR0: Initial Reset Value
  29   1              XBR1 = 0x07;    // XBAR1: Initial Reset Value
  30   1              XBR2 = 0x44;    // XBAR2: Initial Reset Value
  31   1      // Port configuration (1 = Push Pull Output)
  32   1          P0MDOUT = 0x1D; // Output configuration for P0 
  33   1          P1MDOUT = 0x01; // Output configuration for P1 
  34   1          P2MDOUT = 0x03; // Output configuration for P2 
  35   1          P3MDOUT = 0x00; // Output configuration for P3 
  36   1          P74OUT = 0xff;  // Output configuration for P4-7
  37   1          P1MDIN = 0xFF;  // Input configuration for P1
  38   1      // View port pinout
  39   1      
  40   1                      // The current Crossbar configuration results in the 
  41   1                      // following port pinout assignment:
  42   1                      // Port 0
  43   1                      // P0.0 = UART TX0        (Push-Pull Output)
  44   1                      // P0.1 = UART RX0        (Open-Drain Output/Input)
  45   1                      // P0.2 = SPI Bus SCK     (Push-Pull Output)
  46   1                      // P0.3 = SPI Bus MISO    (Push-Pull Output)
  47   1                      // P0.4 = SPI Bus MOSI    (Push-Pull Output)
  48   1                      // P0.5 = SPI Bus NSS     (Open-Drain Output/Input)
  49   1                      // P0.6 = SMBus SDA       (Open-Drain Output/Input)
  50   1                      // P0.7 = SMBus SCL       (Open-Drain Output/Input)
  51   1      
  52   1                      // Port 1
  53   1                      // P1.0 = UART TX1        (Push-Pull Output)(Digital)
  54   1                      // P1.1 = UART RX1        (Open-Drain Output/Input)(Digital)
  55   1                      // P1.2 = PCA CEX0        (Open-Drain Output/Input)(Digital)
C51 COMPILER V7.50   CAN232                                                                09/12/2006 21:12:06 PAGE 2   

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

 118   1       P3=0xff;
 119   1       for(i=0;i<1000;i++);    //ModeControlReg= RM_RR_Bit;改动
 120   1       ModeControlReg= RM_RR_Bit|STM_Bit;
 121   1       tt=ModeControlReg;
 122   1       ClockDivideReg=0x88;
 123   1       InterruptEnReg=0xff;
 124   1       BusTiming0Reg= 0x03; //100 K
 125   1       BusTiming1Reg=0x2f;
 126   1       AcceptCode0Reg=0x57;
 127   1       AcceptCode1Reg=0x00;
 128   1       AcceptCode2Reg=0xaa;
 129   1       AcceptCode3Reg=0x55;
 130   1       AccepMask0Reg=0xff;
 131   1       AccepMask1Reg=0xff;
 132   1       AccepMask2Reg=0xff;
 133   1       AccepMask3Reg=0xff;
 134   1       
 135   1       RxBufstartAdr=0;
 136   1       TxErrCountReg=0;
 137   1       RxErrCountReg=0;
 138   1       ErrCodeCapReg=0;
 139   1       OutControlReg=0x1a;
 140   1       ModeControlReg=AFM_Bit;
 141   1       
 142   1       tt=StatusReg;
 143   1       while(tt==0x10)
 144   1       tt=StatusReg; 
 145   1       return tt;
 146   1      }
 147          void WriteCan()
 148          {
 149   1       unsigned char * xdata tt;
 150   1       unsigned int i;
 151   1       unsigned char tt1,count;
 152   1       count=(CommRBuffer[CommTP]&0x0f);
 153   1       if((CommRBuffer[CommTP]&0x80)==0x00)
 154   1       count+=3;
 155   1       else
 156   1       count+=5;
 157   1      
 158   1      
 159   1       tt1=StatusReg; 
 160   1       if((tt1&RS_Bit)!=0x00)return;
 161   1       tt1=StatusReg;
 162   1       if((tt1&TCS_Bit)==0x00)return;
 163   1       tt=&TxFramInFo;
 164   1      
 165   1      
 166   1      
 167   1       for(i=0;i<count;i++)
 168   1       {SendBuffer[i]=CommRBuffer[CommTP++];
 169   2        if(CommTP==1024)CommTP=0;
 170   2       }
 171   1      
 172   1      
 173   1      
 174   1       //EA=0;
 175   1       for(i=0;i<count;i++)
 176   1       {*tt=SendBuffer[i];
 177   2        tt++;
 178   2       }
 179   1       CommandReg=TR_Bit;
C51 COMPILER V7.50   CAN232                                                                09/12/2006 21:12:06 PAGE 4   

 180   1      //EA=1;
 181   1       CommRCount-=count;
 182   1       return ;

⌨️ 快捷键说明

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