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

📄 temp_1.lst

📁 C8051F060下采用PT100进行PID温度控制
💻 LST
📖 第 1 页 / 共 2 页
字号:
 237   1         SFRPAGE = CONFIG_PAGE;              // set SFR page
 238   1      
 239   1         XBR0     = 0x00;
 240   1         XBR1     = 0x00;                                                                              //没用的时候都一定要写出来这样规范
 241   1         XBR2     = 0x44;                    // Enable crossbar and weak pull-up
C51 COMPILER V8.08   TEMP_1                                                                12/24/2008 09:37:52 PAGE 5   

 242   1                                             // Enable UART1
 243   1      
 244   1         P0MDOUT |= 0x01;                    // Set TX1 pin to push-pull       //对于UART都有必须的一步
 245   1         P2MDOUT |= 0x03;                    // Set P1.6(LED) to push-pull
 246   1      
 247   1       //  P1MDIN = 0xFD;                      // P1.1 Analog Input, Open Drain               //模拟输入的开漏
 248   1      
 249   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
 250   1      }
 251          
 252          //-----------------------------------------------------------------------------
 253          // UART1_Init
 254          //-----------------------------------------------------------------------------
 255          //
 256          // Return Value : None
 257          // Parameters   : None
 258          //
 259          // Configure the UART1 using Timer1, for <baudrate> and 8-N-1.
 260          //
 261          //-----------------------------------------------------------------------------
 262          void UART1_Init (void)
 263          {       /*采用了定时期1来实现不同情况下的波特率*/
 264   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page
 265   1      
 266   1         SFRPAGE = UART1_PAGE;
 267   1         SCON1   = 0x50;                     // SCON1: mode 0, 8-bit UART, enable RX
 268   1      
 269   1         SFRPAGE = TIMER01_PAGE;
 270   1         TMOD   &= ~0xF0;                                                                                     //TMR1不用
 271   1         TMOD   |=  0x20;                    // TMOD: timer 1, mode 2, 8-bit reload    定时个功能
 272   1      
 273   1       /*下面是设置这个在不同的频率要求下实现波特率的时间初始值*/
 274   1         if (SYSCLK/BAUDRATE/2/256 < 1) {
 275   2            TH1 = -(SYSCLK/BAUDRATE/2);
 276   2            CKCON |= 0x10;                   // T1M = 1; SCA1:0 = xx
 277   2         } else if (SYSCLK/BAUDRATE/2/256 < 4) {
 278   2            TH1 = -(SYSCLK/BAUDRATE/2/4);
 279   2            CKCON &= ~0x13;                  // Clear all T1 related bits
 280   2            CKCON |=  0x01;                  // T1M = 0; SCA1:0 = 01
 281   2         } else if (SYSCLK/BAUDRATE/2/256 < 12) {
 282   2            TH1 = -(SYSCLK/BAUDRATE/2/12);
 283   2            CKCON &= ~0x13;                  // T1M = 0; SCA1:0 = 00
 284   2         } else {
 285   2            TH1 = -(SYSCLK/BAUDRATE/2/48);
 286   2            CKCON &= ~0x13;                  // Clear all T1 related bits
 287   2            CKCON |=  0x02;                  // T1M = 0; SCA1:0 = 10
 288   2         }
 289   1               //CKCON这个才是决定用那个始终的,然后才能满足计数/定时的要求。
 290   1         TL1 = TH1;                          // Initialize Timer1
 291   1         TR1 = 1;                            // Start Timer1
 292   1      
 293   1         SFRPAGE = UART1_PAGE;
 294   1         TI1 = 1;  /*这个ready很重要*/                // Indicate TX1 ready
 295   1      
 296   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
 297   1      
 298   1      }
 299          
 300          //-----------------------------------------------------------------------------
 301          // ADC2_Init
 302          //-----------------------------------------------------------------------------
 303          //
C51 COMPILER V8.08   TEMP_1                                                                12/24/2008 09:37:52 PAGE 6   

 304          // Return Value : None
 305          // Parameters   : None
 306          //
 307          // Configure ADC0 to use Timer3 overflows as conversion source, to
 308          // generate an interrupt on conversion complete, and to use right-justified
 309          // output mode.  Enables ADC end of conversion interrupt. Leaves ADC disabled.
 310          //
 311          //-----------------------------------------------------------------------------
 312           void ADC2_Init (void)
 313          {
 314   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page
 315   1      
 316   1         SFRPAGE = ADC2_PAGE;
 317   1      
 318   1         ADC2CN = 0x04;                      // ADC2 disabled; normal tracking
 319   1                                             // mode; ADC2 conversions are initiated
 320   1                                             // on overflow of Timer3; ADC2 data is
 321   1                                             // right-justified
 322   1      
 323   1         REF2CN = 0x0F;                      // Enable on-chip VREF,
 324   1                                             // and VREF output buffer
 325   1         AMX2CF = 0x00;                      // AIN inputs are single-ended (default)
 326   1         AMX2SL = 0x08;                      // Select AIN2.1 pin as ADC mux input
 327   1         ADC2CF = (SYSCLK/SAR_CLK-1) << 3;     // ADC conversion clock = 2.5MHz
 328   1         EIE2 |= 0x10;                       // enable ADC interrupts
 329   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
 330   1      
 331   1      
 332   1         /*SFRPAGE   = ADC2_PAGE;
 333   1         // AMX2SL    = 0x08;
 334   1         // ADC2CF    = 0x48;
 335   1          ADC2CN    = 0x44;
 336   1          //REF2CN    = 0x07; 
 337   1         //EIE2      = 0x10;
 338   1      
 339   1              time
 340   1          SFRPAGE   = CONFIG_PAGE;
 341   1          OSCICN    = 0x83;            */
 342   1      
 343   1      
 344   1      }
 345          
 346          //-----------------------------------------------------------------------------
 347          // TIMER3_Init
 348          //-----------------------------------------------------------------------------
 349          //
 350          // Return Value : None
 351          // Parameters   :
 352          //   1)  int counts - calculated Timer overflow rate
 353          //                    range is postive range of integer: 0 to 32767
 354          //
 355          // Configure Timer3 to auto-reload at interval specified by <counts> (no
 356          // interrupt generated) using SYSCLK as its time base.
 357          //
 358          //-----------------------------------------------------------------------------
 359          void TIMER3_Init (void)
 360          {
 361   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page  满足的时间溢出频率
 362   1      
 363   1         SFRPAGE = TMR3_PAGE;
 364   1      
 365   1         TMR3CN = 0x00;                      // Stop Timer3; Clear TF3;
C51 COMPILER V8.08   TEMP_1                                                                12/24/2008 09:37:52 PAGE 7   

 366   1         TMR3CF = 0x00;                      // use SYSCLK/12 as timebase               SYSCLK/12       
 367   1      
 368   1         RCAP3   = -((long)SYSCLK/SAMPLE_RATE/12);                  // Init reload values
 369   1         TMR3    = RCAP3;                    // Set to reload immediately
 370   1         EIE2   &= ~0x01;                    // Disable Timer3 interrupts
 371   1         TR3     = 1;                        // start Timer3
 372   1      
 373   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
 374   1      }
 375          
 376          //-----------------------------------------------------------------------------
 377          // Interrupt Service Routines
 378          //-----------------------------------------------------------------------------
 379          
 380          //-----------------------------------------------------------------------------
 381          // ADC2_ISR
 382          //-----------------------------------------------------------------------------
 383          //
 384          // Here we take the ADC2 sample, add it to a running total <accumulator>, and
 385          // decrement our local decimation counter <int_dec>.  When <int_dec> reaches
 386          // zero, we post the decimated result in the global variable <Result>.
 387          //
 388          //-----------------------------------------------------------------------------
 389          void ADC2_ISR (void) interrupt 18
 390          {
 391   1         static unsigned int_dec=INT_DEC;    // Integrate/decimate counter
 392   1                                             // we post a new result when
 393   1                                             // int_dec = 0
 394   1         static long accumulator=0L;         // Here's where we integrate the
 395   1                                             // ADC samples
 396   1         char SFRPAGE_SAVE = SFRPAGE; 
 397   1         SFRPAGE = ADC2_PAGE;
 398   1         AD2INT = 0;                         // Clear ADC conversion complete
 399   1                                             // indicator
 400   1         accumulator += ADC2;                // Read ADC value and add to running
 401   1                                             // total
 402   1         int_dec--;                          // Update decimation counter
 403   1         if (int_dec == 0)                   // If zero, then post result
 404   1         {                                                                                                                                    
 405   2            lchhxy=1;
 406   2            int_dec = INT_DEC;               // Reset counter
 407   2            Result = accumulator >> 14;
 408   2            accumulator = 0L;                // Reset accumulator
 409   2         }
 410   1         SFRPAGE = SFRPAGE_SAVE;
 411   1      }
 412          
 413          //-----------------------------------------------------------------------------
 414          // Support Subroutines
 415          //-----------------------------------------------------------------------------
 416           /*void TIMER3_ISR (void)
 417           {
 418              TF3=0;
 419                  LED1=~LED1;
 420           } */
 421          //-----------------------------------------------------------------------------
 422          // Wait_MS
 423          //-----------------------------------------------------------------------------
 424          //
 425          // Return Value : None
 426          // Parameters:
 427          //   1) unsigned int ms - number of milliseconds of delay
C51 COMPILER V8.08   TEMP_1                                                                12/24/2008 09:37:52 PAGE 8   

 428          //                        range is full range of integer: 0 to 65335
 429          //
 430          // This routine inserts a delay of <ms> milliseconds.
 431          //
 432          //-----------------------------------------------------------------------------
 433          void Wait_MS(unsigned int ms)
 434          {
 435   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page
 436   1      
 437   1         SFRPAGE = TMR2_PAGE;
 438   1      
 439   1         TMR2CN = 0x00;                      // Stop Timer3; Clear TF3;
 440   1         TMR2CF = 0x00;                      // use SYSCLK/12 as timebase
 441   1      
 442   1         RCAP2 = -(SYSCLK/1000/12);          // Timer 2 overflows at 1 kHz
 443   1         TMR2 = RCAP2;
 444   1      
 445   1         ET2 = 0;                            // Disable Timer 2 interrupts
 446   1      
 447   1         TR2 = 1;                            // Start Timer 2
 448   1      
 449   1         while(ms)
 450   1         {
 451   2            
 452   2            TF2 = 0;                         // Clear flag to initialize
 453   2            while(!TF2);                     // Wait until timer overflows
 454   2            ms--;                            // Decrement ms
 455   2         }
 456   1      
 457   1         TR2 = 0;                            // Stop Timer 2
 458   1      
 459   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFRPAGE
 460   1      }
 461          
 462          //-----------------------------------------------------------------------------
 463          // End Of File
 464          //-----------------------------------------------------------------------------


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    506    ----
   CONSTANT SIZE    =     20    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     14       4
   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 + -