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

📄 function.lst

📁 全国电子设计大赛:智能电动车的设计.实现功能:以AT89C52单片机为核心
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.20   FUNCTION                                                              11/15/2005 18:46:54 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE FUNCTION
OBJECT MODULE PLACED IN Function.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil Uvision V7.20\C51\BIN\C51.EXE Function.C BROWSE DEBUG OBJECTEXTEND SYMBOLS

line level    source

   1          //*************************************************************************************************
   2          //  Module Name :  Function.C
   3          //  CreateDate  :  2005-01-09
   4          //  ModifData   :  2005-06-01
   5          //  Description :  
   6          //  Author      :  李远正
   7          //  Version     :  V1.0
   8          //*************************************************************************************************
   9          
  10          #include <c8051f020.h>
  11          #include "Function.H"
  12          
  13          //-------------------------------------------------------------------------------------------------
  14          //-------------------------------------------------------------------------------------------------
  15          // Global VARIABLES
  16          
  17          //=================================================================================================
  18          // Temperature
  19          //=================================================================================================
  20          // Get the temperature of the chip
  21          // 
  22          unsigned int GetTemperature( void )
  23          {
  24   1          unsigned long temp;
  25   1              unsigned int  TEMPER;
  26   1      
  27   1          AMX0SL = 0x0F;      // 选择温度传感器作为 ADC 输入
  28   1              ADC0CF = 0x61;      // 设置 ADC 的时钟 = SYSCLK/8, ADC 增益 = 2
  29   1              ADC0CN = 0xC1;      // 允许 ADC;允许低功耗跟踪方式
  30   1                                  // 清除转换完成中断
  31   1                                                      // 选择 ADBUSY 作为转换启动源 
  32   1                                                      // 清除窗口比较中断
  33   1                                                      // 设置输出数据格式为左对齐
  34   1              AD0BUSY = 1;        // 启动 ADC 转换
  35   1      
  36   1              while( AD0INT==0 ) ; AD0INT = 0;     // Wait for convert...
  37   1      
  38   1      //      temp   = (ADC0-42380)*420/65536;      // 精确到   1 度
  39   1              temp   = (ADC0-42380)*4200/65536;     // 精确到 0.1 度
  40   1              TEMPER = ( unsigned int )temp;
  41   1              return( TEMPER );
  42   1      }
  43          
  44          
  45          //=================================================================================================
  46          // ADC
  47          //=================================================================================================
  48          // ADC 10 Bit ( datum: 0-1023 ) 
  49          // 
  50          unsigned int ADConvert0( unsigned char channel, unsigned char configure )
  51          {
  52   1          AMX0SL = channel;
  53   1              AMX0CF = configure;
  54   1      
  55   1          ADC0CF = 0x60;      // 设置 ADC 的时钟 = SYSCLK/8, ADC 增益 = 1
C51 COMPILER V7.20   FUNCTION                                                              11/15/2005 18:46:54 PAGE 2   

  56   1              ADC0CN = 0xC0;      // 允许 ADC;允许低功耗跟踪方式
  57   1                                  // 清除转换完成中断
  58   1                                                      // 选择 ADBUSY 作为转换启动源 
  59   1                                                      // 清除窗口比较中断
  60   1                                                      // 设置输出数据格式为右对齐
  61   1              AD0BUSY = 1;        // 启动 ADC 转换
  62   1      
  63   1              while( AD0INT==0 ) ; AD0INT = 0;     // Wait for convert...
  64   1      
  65   1              return( ADC0 );
  66   1      }
  67          
  68          //=================================================================================================
  69          // DAC
  70          //=================================================================================================
  71          // DAC0 convert 12 Bit ( datum: 0-4095 )
  72          // 
  73          void DAConvert0( unsigned int datum )
  74          {
  75   1      //    datum <<= 6;             // 数据左对齐
  76   1      
  77   1          DAC0L   = datum &0xFF;   // 先写入低字节
  78   1              DAC0H   = datum >>8;     // 后写入高字节( 启动转换 )
  79   1      }
  80          
  81          //-------------------------------------------------------------------------------------------------
  82          // DAC1 convert 12 Bit ( datum: 0-4095 )
  83          // 
  84          void DAConvert1( unsigned int datum )
  85          {
  86   1      //    datum <<= 6;             // 数据左对齐
  87   1      
  88   1          DAC1L   = datum &0xFF;   // 先写入低字节
  89   1              DAC1H   = datum >>8;     // 后写入高字节( 启动转换 )
  90   1      }
  91          /*
  92          //=================================================================================================
  93          // PWM Out  (16 Bit)
  94          void PWM16( unsigned char channel,unsigned int datum )
  95          {
  96              switch( channel )
  97                  {
  98                      case 0: PCA0CPM0 = 0x82; PCA0CPL0 = datum &0xFF; PCA0CPH0 = datum >>8; break;
  99                          case 1: PCA0CPM1 = 0x82; PCA0CPL1 = datum &0xFF; PCA0CPH1 = datum >>8; break;
 100                          case 2: PCA0CPM2 = 0x82; PCA0CPL2 = datum &0xFF; PCA0CPH2 = datum >>8; break;
 101                          case 3: PCA0CPM3 = 0x82; PCA0CPL3 = datum &0xFF; PCA0CPH3 = datum >>8; break;
 102                          case 4: PCA0CPM4 = 0x82; PCA0CPL4 = datum &0xFF; PCA0CPH4 = datum >>8; break;
 103                          default:break;
 104                  }
 105          }
 106          */
 107          //-------------------------------------------------------------------------------------------------
 108          // PWM Out  (8 Bit)
 109          void PWM8( unsigned char channel,unsigned char datum )
 110          {
 111   1          switch( channel )
 112   1              {
 113   2                  case 0: PCA0CPM0 = 0x02; PCA0CPH0 = datum; break;
 114   2                      case 1: PCA0CPM1 = 0x02; PCA0CPH1 = datum; break;
 115   2                      case 2: PCA0CPM2 = 0x02; PCA0CPH2 = datum; break;
 116   2                      case 3: PCA0CPM3 = 0x02; PCA0CPH3 = datum; break;
 117   2                      case 4: PCA0CPM4 = 0x02; PCA0CPH4 = datum; break;
C51 COMPILER V7.20   FUNCTION                                                              11/15/2005 18:46:54 PAGE 3   

 118   2                      default:break;
 119   2              }
 120   1      }
 121          
 122          /*
 123          //=================================================================================================
 124          // ADC0_Init
 125          //=================================================================================================
 126          //
 127          // Configure ADC0 to use Timer3 overflows as conversion source, to
 128          // generate an interrupt on conversion complete, and to use left-justified
 129          // output mode.  Enables ADC end of conversion interrupt. Leaves ADC disabled.
 130          //
 131          void ADC0_Init (void)
 132          {
 133             ADC0CN = 0x05;                      // ADC0 disabled; normal tracking
 134                                                 // mode; ADC0 conversions are initiated 
 135                                                 // on overflow of Timer3; ADC0 data is
 136                                                 // left-justified
 137             REF0CN = 0x07;                      // enable temp sensor, on-chip VREF,
 138                                                 // and VREF output buffer
 139             AMX0SL = 0x0f;                      // Select TEMP sens as ADC mux output
 140             ADC0CF = (SYSCLK/2500000) << 3;     // ADC conversion clock = 2.5MHz
 141             ADC0CF |= 0x01;                     // PGA gain = 2
 142          
 143             EIE2 |= 0x02;                       // enable ADC interrupts
 144          }
 145          
 146          //=================================================================================================
 147          // ADC0_ISR
 148          //=================================================================================================
 149          //
 150          // ADC0 end-of-conversion ISR 
 151          // Here we take the ADC0 sample, add it to a running total <accumulator>, and
 152          // decrement our local decimation counter <int_dec>.  When <int_dec> reaches
 153          // zero, we post the decimated result in the global variable <result>.
 154          //
 155          void ADC0_ISR (void) interrupt 15
 156          {
 157             static unsigned int_dec=INT_DEC;    // integrate/decimate counter
 158                                                 // we post a new result when
 159                                                 // int_dec = 0
 160             static long accumulator=0L;         // here's where we integrate the
 161                                                 // ADC samples             
 162          
 163             AD0INT = 0;                                                                  // clear ADC conversion complete
 164                                                 // indicator
 165          
 166                  accumulator += ADC0;                // read ADC value and add to running
 167                                                 // total
 168             int_dec--;                          // update decimation counter
 169          
 170             if (int_dec == 0) {                 // if zero, then post result
 171                int_dec = INT_DEC;               // reset counter
 172                result = accumulator >> 8;
 173                accumulator = 0L;                // reset accumulator
 174             }
 175          }
 176          
 177          */
 178          
 179          //=================================================================================================
C51 COMPILER V7.20   FUNCTION                                                              11/15/2005 18:46:54 PAGE 4   

 180          //=================================================================================================
 181          
 182          #define SYSCLK       11059200          // SYSCLK frequency in Hz
 183          
 184          //=================================================================================================
 185          // UART0_Init
 186          //=================================================================================================
 187          // Configure the UART0 using Timer2, for <baudrate> and 8-N-1.
 188          // 
 189          #define BAUDRATE0    115200            // Baud rate of UART0 in bps
 190          
 191          //-------------------------------------------------------------------------------------------------
 192          // 
 193          void UART0_Init ( void )
 194          {
 195   1              SCON0  = 0x50;                      // SCON0: Mode 1, 8-bit UART, enable RX. ( For USBS   )
 196   1      //      SCON0  = 0x90;                      // SCON0: Mode 2, 9-bit UART, enable RX. ( For CH375S )
 197   1                                              // Bit 7-6: SM00,SM10
 198   1                                              // Bit 5  : SM20
 199   1                                              // Bit 4  : REN0
 200   1                                              // Bit 3-2: TB80,RB80
 201   1                                                                                      // Bit 1-0: TI0, RI0
 202   1      
 203   1          CKCON |= 0x20;                      // (CKCON.5) Timer2 uses SYSCLK as time base
 204   1              PCON  |= 0x80;                      // (PCON.7) = SMOD0 = 1
 205   1      
 206   1              RCAP2  = -(SYSCLK/BAUDRATE0/32);    // Set Timer2 reload value for baudrate
 207   1              T2     = RCAP2;                     // initialize Timer value
 208   1      
 209   1          TR2    = 1;                         // (T2CON.2) = TR2, Start Timer2 
 210   1      
 211   1      #if UART0_INT_EN  == 1                  // Enable UART0 interrupts
                      ES0    = 1;                         // Enable UART0 interrupts
              #endif
 214   1      }
 215          /*
 216          //-------------------------------------------------------------------------------------------------
 217          // SendByte
 218          void UART0SendByte ( unsigned char datum )
 219          {
 220                  ES0    = 0;                         // Disable UART0 interrupts
 221          
 222                  TI0    = 0;
 223                  SBUF0  = datum; 
 224                  while ( TI0 == 0 ) ;                // Waiting...
 225          
 226          #if UART0_INT_EN  == 1                  // Enable UART0 interrupts
 227                  ES0    = 1;                         // Enable UART0 interrupts
 228          #endif
 229          }
 230          
 231          //-------------------------------------------------------------------------------------------------
 232          // RecvByte
 233          unsigned char UART0RecvByte ( void )
 234          {
 235              unsigned char datum,count;
 236          

⌨️ 快捷键说明

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