C51 COMPILER V9.54   ADC                                                                   12/03/2024 14:58:46 PAGE 1   


C51 COMPILER V9.54, COMPILATION OF MODULE ADC
OBJECT MODULE PLACED IN .\Objects\adc.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE public\adc.c OPTIMIZE(8,SPEED) BROWSE INCDIR(.\public) DEBUG OBJECTEXTEN
                    -D PRINT(.\Listings\adc.lst) OBJECT(.\Objects\adc.obj)

line level    source

   1          #include "adc.h" 
   2          #include "string.h"
   3          #include "stdio.h"
   4          
   5          
   6          uint8_t buf[10] = {0};
   7          uint16_t adc_val = 0;
   8          
   9          
  10          void ADC_Init()
  11          {
  12   1              SYSCON |= 0xC0;//系统时钟不分频
  13   1              CKCON = 0x00;   
  14   1              P3CR = 0x00;
  15   1              P3PCR = 0x00;
  16   1              AENCON0 = 0x0F; //adc输入使能
  17   1              AENCON1 = 0x00; 
  18   1              ADCH            = 0x00;
  19   1              ADCON   = 0x80; //使能adc，选择内部参考电压
  20   1        ADT                   = 0x2F; //adc时钟为系统时钟8分频，采样时间为15个adc时钟  0x2F 1Mhz   0x0F 2Mhz
  21   1      
  22   1      }
  23          
  24          
  25          void  get_adc_val(uint8_t channel)
  26          {
  27   1          ADCH |= channel;    //选择通道      
  28   1          ADCON |= 0x01;
  29   1                      while(ADCON & 0x01); // 等待转换完成    
  30   1                      adc_val = ((uint16_t)ADDH << 2) |(ADDL & 0x03);
  31   1                ADCH = 0x00; //清零等待下次赋值
  32   1      
  33   1      }
  34          
  35          void ADC_Test(void)
  36          {
  37   1              uint8_t temp;
  38   1      
  39   1              delay_ms(50);
  40   1              ADC_Init();
  41   1              Uart_Init();
  42   1      
  43   1      
  44   1              while(1)
  45   1              {       
  46   2                      if(SCON & 0x01)
  47   2                      {
  48   3                              SCON ^= 0x01;
  49   3                              temp = SBUF;
  50   3                              switch(temp)
  51   3                              {
  52   4                                      case '0': 
  53   4                                                                      get_adc_val(0x00);
  54   4                                                                      sprintf(buf,"CH0:%d\r\n",adc_val);
C51 COMPILER V9.54   ADC                                                                   12/03/2024 14:58:46 PAGE 2   

  55   4                                                                      sendString(buf);
  56   4                                              break;
  57   4                                      case '1': 
  58   4                                                                      get_adc_val(0x01);
  59   4                                                                      sprintf(buf,"CH1:%d\r\n",adc_val);
  60   4                                                                      sendString(buf);
  61   4                                              break;
  62   4                                      case '2': 
  63   4                                                                      get_adc_val(0x02);
  64   4                                                                      sprintf(buf,"CH2:%d\r\n",adc_val);
  65   4                                                                      sendString(buf);
  66   4                                              break;
  67   4                                      case '3':       
  68   4                                                                      get_adc_val(0x03);
  69   4                                                                      sprintf(buf,"CH3:%d\r\n",adc_val);
  70   4                                                                      sendString(buf);
  71   4                                        break;
  72   4                                      default:
  73   4                                              break;                          
  74   4                              }                       
  75   3                      }
  76   2              }
  77   1      }
  78          


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


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