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

📄 main.lst

📁 新一代功能比较齐全的c8051f020单片机的串行通信c程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 139          //-----------------------------------------------------------------------------
 140          
 141          //-----------------------------------------------------------------------------
 142          // SYSCLK_Init
 143          //-----------------------------------------------------------------------------
 144          //
 145          // This routine initializes the system clock to use an 22.1184MHz crystal
 146          // as its clock source.
 147          //
 148          void SYSCLK_Init (void)
 149          {
 150   1         int i;                              // delay counter
 151   1      
 152   1         OSCXCN = 0x67;                      // start external oscillator with
 153   1                                             // 22.1184MHz crystal
 154   1      
 155   1         for (i=0; i < 256; i++) ;           // XTLVLD blanking interval (>1ms)
 156   1      
 157   1         while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle
 158   1      
 159   1         OSCICN = 0x88;                      // select external oscillator as SYSCLK
 160   1                                             // source and enable missing clock
 161   1                                             // detector
 162   1      }
 163          
 164          //-----------------------------------------------------------------------------
 165          // PORT_Init
 166          //-----------------------------------------------------------------------------
 167          //
 168          // Configure the Crossbar and GPIO ports
 169          //
 170          void PORT_Init (void)
 171          {
 172   1         XBR0    = 0x04;                     // Enable UART0
 173   1         XBR1    = 0x00;
 174   1         XBR2    = 0x40;                     // Enable crossbar and weak pull-ups
 175   1         P0MDOUT |= 0x01;                    // enable TX0 as a push-pull output
 176   1         P1MDOUT |= 0x40;                    // enable P1.6 (LED) as push-pull output
 177   1      }
 178          
 179          //-----------------------------------------------------------------------------
C51 COMPILER V6.23a  MAIN                                                                  12/19/2002 16:23:32 PAGE 4   

 180          // UART0_Init
 181          //-----------------------------------------------------------------------------
 182          //
 183          // Configure the UART0 using Timer1, for <baudrate> and 8-N-1.
 184          //
 185          void UART0_Init (void)
 186          {
 187   1         SCON0   = 0x50;                     // SCON0: mode 1, 8-bit UART, enable RX
 188   1         TMOD    = 0x20;                     // TMOD: timer 1, mode 2, 8-bit reload
 189   1         TH1    = -(SYSCLK/BAUDRATE/16);     // set Timer1 reload value for baudrate
 190   1         TR1    = 1;                         // start Timer1
 191   1         CKCON |= 0x10;                      // Timer1 uses SYSCLK as time base
 192   1         PCON  |= 0x80;                      // SMOD00 = 1
 193   1         TI0    = 1;                         // Indicate TX0 ready
 194   1      }
 195          
 196          //-----------------------------------------------------------------------------
 197          // ADC0_Init
 198          //-----------------------------------------------------------------------------
 199          //
 200          // Configure ADC0 to use Timer3 overflows as conversion source, to
 201          // generate an interrupt on conversion complete, and to use left-justified
 202          // output mode.  Enables ADC end of conversion interrupt. Leaves ADC disabled.
 203          //
 204          void ADC0_Init (void)
 205          {
 206   1         ADC0CN = 0x05;                      // ADC0 disabled; normal tracking
 207   1                                             // mode; ADC0 conversions are initiated 
 208   1                                             // on overflow of Timer3; ADC0 data is
 209   1                                             // left-justified
 210   1         REF0CN = 0x07;                      // enable temp sensor, on-chip VREF,
 211   1                                             // and VREF output buffer
 212   1         AMX0SL = 0x0f;                      // Select TEMP sens as ADC mux output
 213   1         ADC0CF = (SYSCLK/2500000) << 3;     // ADC conversion clock = 2.5MHz
 214   1         ADC0CF |= 0x01;                     // PGA gain = 2
 215   1      
 216   1         EIE2 |= 0x02;                       // enable ADC interrupts
 217   1      }
 218          
 219          //-----------------------------------------------------------------------------
 220          // Timer3_Init
 221          //-----------------------------------------------------------------------------
 222          //
 223          // Configure Timer3 to auto-reload at interval specified by <counts> (no 
 224          // interrupt generated) using SYSCLK as its time base.
 225          //
 226          void Timer3_Init (int counts)
 227          {
 228   1         TMR3CN = 0x02;                      // Stop Timer3; Clear TF3;
 229   1                                             // use SYSCLK as timebase
 230   1         TMR3RL  = -counts;                  // Init reload values
 231   1         TMR3    = 0xffff;                   // set to reload immediately
 232   1         EIE2   &= ~0x01;                    // disable Timer3 interrupts
 233   1         TMR3CN |= 0x04;                     // start Timer3
 234   1      }
 235          
 236          //-----------------------------------------------------------------------------
 237          // Interrupt Service Routines
 238          //-----------------------------------------------------------------------------
 239          
 240          //-----------------------------------------------------------------------------
 241          // ADC0_ISR
C51 COMPILER V6.23a  MAIN                                                                  12/19/2002 16:23:32 PAGE 5   

 242          //-----------------------------------------------------------------------------
 243          //
 244          // ADC0 end-of-conversion ISR 
 245          // Here we take the ADC0 sample, add it to a running total <accumulator>, and
 246          // decrement our local decimation counter <int_dec>.  When <int_dec> reaches
 247          // zero, we post the decimated result in the global variable <result>.
 248          //
 249          void ADC0_ISR (void) interrupt 15
 250          {
 251   1         static unsigned int_dec=INT_DEC;    // integrate/decimate counter
 252   1                                             // we post a new result when
 253   1                                             // int_dec = 0
 254   1         static long accumulator=0L;         // here's where we integrate the
 255   1                                             // ADC samples             
 256   1      
 257   1         AD0INT = 0;                                                                  // clear ADC conversion complete
 258   1                                             // indicator
 259   1      
 260   1              accumulator += ADC0;                // read ADC value and add to running
 261   1                                             // total
 262   1         int_dec--;                          // update decimation counter
 263   1      
 264   1         if (int_dec == 0) {                 // if zero, then post result
 265   2            int_dec = INT_DEC;               // reset counter
 266   2            result = accumulator >> 8;
 267   2            accumulator = 0L;                // reset accumulator
 268   2         }
 269   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    405    ----
   CONSTANT SIZE    =     27    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     10       6
   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 + -