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

📄 canadc.lst

📁 C8051F020控制的SJA1000can总线芯片的驱动程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 170   1       SendBuffer[3]=a;
 171   1       SendBuffer[4]=b;
 172   1       SendBuffer[5]=0x0;
 173   1       SendBuffer[6]=0x0;
 174   1       SendBuffer[7]=0x0;
 175   1       SendBuffer[8]=0x0;
 176   1       SendBuffer[9]=0x0;
 177   1       SendBuffer[10]=0x0;
 178   1       for(i=0;i<count;i++)
 179   1       {*tt=SendBuffer[i];
C51 COMPILER V7.06   CANADC                                                                09/12/2006 15:52:55 PAGE 4   

 180   2        tt++;
 181   2       }
 182   1       CommandReg=TR_Bit;
 183   1       return 1;
 184   1      }
 185          
 186          void INTE0_ISR (void) interrupt 0
 187          {
 188   1        unsigned char tt1;
 189   1        unsigned char * xdata tt;
 190   1        unsigned int i,count;
 191   1        tt1=InterruptReg;
 192   1        if((tt1&0x04)!=0)
 193   1        {
 194   2         tt1=StatusReg;
 195   2         if((tt1&0x80)!=0)
 196   2         ModeControlReg=AFM_Bit;
 197   2         return;
 198   2        }
 199   1       
 200   1        if((tt1&0x08)!=0)
 201   1        {CommandReg=0x0c;
 202   2         return;
 203   2        }
 204   1        if((tt1&0x01)!=0)
 205   1        {tt=&RxFramInFo;
 206   2         count=(*tt&0x0f);
 207   2         if((*tt&0x80)==0)
 208   2         count+=3;
 209   2         else
 210   2         count+=5;
 211   2         for(i=0;i<count;i++)
 212   2         {GetBuffer[i]=*tt;
 213   3          tt++;
 214   3         }
 215   2        
 216   2        CommandReg=RRB_Bit;
 217   2        }
 218   1        tt1=ArbLostCapReg;
 219   1        tt1=ErrCodeCapReg; 
 220   1        return;
 221   1      }
 222          
 223          void ADC0_Init (void)
 224          {
 225   1         ADC0CN = 0x05;                      // ADC0 disabled; normal tracking
 226   1                                             // mode; ADC0 conversions are initiated 
 227   1                                             // on overflow of Timer3; ADC0 data is
 228   1                                             // left-justified
 229   1         REF0CN = 0x07;                      // enable temp sensor, on-chip VREF,
 230   1                                             // and VREF output buffer
 231   1         AMX0SL = 0x0f;                      // Select TEMP sens as ADC mux output
 232   1         ADC0CF = (SYSCLK/2500000) << 3;     // ADC conversion clock = 2.5MHz
 233   1         ADC0CF |= 0x01;                     // PGA gain = 2
 234   1      
 235   1         EIE2 |= 0x02;                       // enable ADC interrupts
 236   1      }
 237          
 238          //-----------------------------------------------------------------------------
 239          // Timer3_Init
 240          //-----------------------------------------------------------------------------
 241          //
C51 COMPILER V7.06   CANADC                                                                09/12/2006 15:52:55 PAGE 5   

 242          // Configure Timer3 to auto-reload at interval specified by <counts> (no 
 243          // interrupt generated) using SYSCLK as its time base.
 244          //
 245          void Timer3_Init (int counts)
 246          {
 247   1         TMR3CN = 0x02;                      // Stop Timer3; Clear TF3;
 248   1                                             // use SYSCLK as timebase
 249   1         TMR3RL  = -counts;                  // Init reload values
 250   1         TMR3    = 0xffff;                   // set to reload immediately
 251   1         EIE2   &= ~0x01;                    // disable Timer3 interrupts
 252   1         TMR3CN |= 0x04;                     // start Timer3
 253   1      }
 254          
 255          //-----------------------------------------------------------------------------
 256          // Interrupt Service Routines
 257          //-----------------------------------------------------------------------------
 258          
 259          //-----------------------------------------------------------------------------
 260          // ADC0_ISR
 261          //-----------------------------------------------------------------------------
 262          //
 263          // ADC0 end-of-conversion ISR 
 264          // Here we take the ADC0 sample, add it to a running total <accumulator>, and
 265          // decrement our local decimation counter <int_dec>.  When <int_dec> reaches
 266          // zero, we post the decimated result in the global variable <result>.
 267          //
 268          void ADC0_ISR (void) interrupt 15
 269          {
 270   1         static unsigned int_dec=INT_DEC;    // integrate/decimate counter
 271   1                                             // we post a new result when
 272   1                                             // int_dec = 0
 273   1         static long accumulator=0L;         // here's where we integrate the
 274   1                                             // ADC samples             
 275   1      
 276   1         AD0INT = 0;                                                                  // clear ADC conversion complete
 277   1                                             // indicator
 278   1      
 279   1              accumulator += ADC0;                // read ADC value and add to running
 280   1                                             // total
 281   1         int_dec--;                          // update decimation counter
 282   1      
 283   1         if (int_dec == 0) {                 // if zero, then post result
 284   2            int_dec = INT_DEC;               // reset counter
 285   2            result = accumulator >> 8;
 286   2            accumulator = 0L;                // reset accumulator
 287   2         }
 288   1      }
 289          
 290          main()
 291          {
 292   1       unsigned long temperature;                   // temperature in hundredths of a
 293   1                                           // degree C
 294   1       unsigned int  temp_int, temp_frac;
 295   1       SYSCLK_Init();
 296   1       config();
 297   1       UART0_Init();
 298   1       Can_Init();
 299   1       Timer3_Init (SYSCLK/SAMPLE_RATE);   // initialize Timer3 to overflow at
 300   1                                             // sample rate
 301   1      
 302   1       ADC0_Init ();                       // init ADC
 303   1       AD0EN = 1;                          // enable ADC
C51 COMPILER V7.06   CANADC                                                                09/12/2006 15:52:55 PAGE 6   

 304   1       EA=1;
 305   1       EX0=1;
 306   1       IP=0x01;
 307   1       while(1)
 308   1       {
 309   2        temperature = result;
 310   2       // calculate temperature in hundredths of a degree
 311   2        temperature = temperature - 42380;
 312   2        temperature = (temperature * 100L) / 156;
 313   2        temp_int = temperature / 100;
 314   2        temp_frac = temperature - (temp_int * 100);
 315   2        if(WriteCan(temp_int,temp_frac)==0x01)
 316   2        {SBUF0=0xAA;
 317   3         while(TI0==0);
 318   3         TI0=0;
 319   3         SBUF0=0x55;
 320   3         while(TI0==0);
 321   3         TI0=0;
 322   3        }
 323   2       
 324   2       }
 325   1      }
 326          
 327          
 328          
 329          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1184    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     34    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     36    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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