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

📄 canadc.lst

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


C51 COMPILER V7.06, COMPILATION OF MODULE CANADC
OBJECT MODULE PLACED IN canadc.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE canadc.c OPTIMIZE(1,SPEED) BROWSE ORDER DEBUG OBJECTEXTEND

stmt 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          sfr16 DP       = 0x82;                 // data pointer
   9          sfr16 TMR3RL   = 0x92;                 // Timer3 reload value
  10          sfr16 TMR3     = 0x94;                 // Timer3 counter
  11          sfr16 ADC0     = 0xbe;                 // ADC0 data
  12          sfr16 ADC0GT   = 0xc4;                 // ADC0 greater than window
  13          sfr16 ADC0LT   = 0xc6;                 // ADC0 less than window
  14          sfr16 RCAP2    = 0xca;                 // Timer2 capture/reload
  15          sfr16 T2       = 0xcc;                 // Timer2
  16          sfr16 RCAP4    = 0xe4;                 // Timer4 capture/reload
  17          sfr16 T4       = 0xf4;                 // Timer4
  18          sfr16 DAC0     = 0xd2;                 // DAC0 data
  19          sfr16 DAC1     = 0xd5;                 // DAC1 data
  20          
  21          #define BAUDRATE     115200            // Baud rate of UART in bps
  22          #define SYSCLK       22118400          // SYSCLK frequency in Hz
  23          #define SAMPLE_RATE  50000             // Sample frequency in Hz
  24          #define INT_DEC      256               // integrate and decimate ratio
  25          
  26          unsigned char xdata SendBuffer[13];
  27          unsigned char xdata GetBuffer[13];
  28          long result; 
  29          void config (void) {
  30   1      
  31   1      //Local Variable Definitions
  32   1              WDTCN = 0x07;   // Watchdog Timer Control Register
  33   1          WDTCN = 0xDE;   // Disable WDT
  34   1          WDTCN = 0xAD;
  35   1      
  36   1              XBR0 = 0xEF;    // XBAR0: Initial Reset Value
  37   1              XBR1 = 0x07;    // XBAR1: Initial Reset Value
  38   1              XBR2 = 0x44;    // XBAR2: Initial Reset Value
  39   1      // Port configuration (1 = Push Pull Output)
  40   1          P0MDOUT = 0x1D; // Output configuration for P0 
  41   1          P1MDOUT = 0x01; // Output configuration for P1 
  42   1          P2MDOUT = 0x03; // Output configuration for P2 
  43   1          P3MDOUT = 0x00; // Output configuration for P3 
  44   1          P74OUT = 0xff;  // Output configuration for P4-7
  45   1          P1MDIN = 0xFF;  // Input configuration for P1
  46   1      // View port pinout
  47   1      
  48   1                      // The current Crossbar configuration results in the 
  49   1                      // following port pinout assignment:
  50   1                      // Port 0
  51   1                      // P0.0 = UART TX0        (Push-Pull Output)
  52   1                      // P0.1 = UART RX0        (Open-Drain Output/Input)
  53   1                      // P0.2 = SPI Bus SCK     (Push-Pull Output)
  54   1                      // P0.3 = SPI Bus MISO    (Push-Pull Output)
  55   1                      // P0.4 = SPI Bus MOSI    (Push-Pull Output)
C51 COMPILER V7.06   CANADC                                                                09/12/2006 15:52:55 PAGE 2   

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

 118          unsigned char Can_Init(void)
 119          {
 120   1       unsigned char tt;
 121   1       unsigned int i;
 122   1       P3=0xff;
 123   1       for(i=0;i<1000;i++);
 124   1       P3=0x00;
 125   1       for(i=0;i<1000;i++);
 126   1       P3=0xff;
 127   1       for(i=0;i<1000;i++);
 128   1       ModeControlReg= RM_RR_Bit;
 129   1       tt=ModeControlReg;
 130   1       ClockDivideReg=0x88;
 131   1       InterruptEnReg=0xff;
 132   1       BusTiming0Reg= 0x03; //100 K
 133   1       BusTiming1Reg=0x2f;
 134   1       AcceptCode0Reg=0x57;
 135   1       AcceptCode1Reg=0x00;
 136   1       AcceptCode2Reg=0xaa;
 137   1       AcceptCode3Reg=0x55;
 138   1       AccepMask0Reg=0xff;
 139   1       AccepMask1Reg=0xff;
 140   1       AccepMask2Reg=0xff;
 141   1       AccepMask3Reg=0xff;
 142   1       
 143   1       RxBufstartAdr=0;
 144   1       TxErrCountReg=0;
 145   1       RxErrCountReg=0;
 146   1       ErrCodeCapReg=0;
 147   1       OutControlReg=0x1a;
 148   1       ModeControlReg=AFM_Bit;
 149   1       
 150   1       tt=StatusReg;
 151   1       while(tt==0x10)
 152   1       tt=StatusReg; 
 153   1       return tt;
 154   1      }
 155          unsigned char WriteCan(unsigned int a,unsigned int b)
 156          {
 157   1       unsigned char * xdata tt;
 158   1       unsigned int i;
 159   1       unsigned char tt1,count;
 160   1       count=11;
 161   1       
 162   1       tt1=StatusReg; 
 163   1       if((tt1&RS_Bit)!=0x00)return 0;
 164   1       tt1=StatusReg;
 165   1       if((tt1&TCS_Bit)==0x00)return 0;
 166   1       tt=&TxFramInFo;
 167   1       SendBuffer[0]=0x08;
 168   1       SendBuffer[1]=0x01;
 169   1       SendBuffer[2]=0x08;

⌨️ 快捷键说明

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