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

📄 tempfan.lst

📁 Automatic Temperature Controlled Fan With PWM Conrol in Keil
💻 LST
字号:
C51 COMPILER V8.12   TEMPFAN                                                               03/21/2009 14:46:21 PAGE 1   


C51 COMPILER V8.12, COMPILATION OF MODULE TEMPFAN
OBJECT MODULE PLACED IN TempFan.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE TempFan.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg52.H>
   2          #include <stdio.h>
   3          #include <string.h>
   4          #include <intrins.h>
   5          #include "ADC.c"
   6          #include "LCD.c"
   7          
   8          sbit PWMPIN= P3^7;
   9          bit USRFLG=0;
  10          unsigned char pwm_width;
  11          void itoa(unsigned int value  ,unsigned char *string);
  12          void Speed(unsigned char Temp);
  13          
  14          
  15          //***************************************************************
  16          
  17          //              Timer 0 interrupt
  18          
  19          //***************************************************************
  20          
  21          void timer0() interrupt 1 
  22          {
  23   1        if(!USRFLG)
  24   1        {       //Start of High level
  25   2          USRFLG = 1; //Set flag
  26   2          PWMPIN = 1;     //Set PWM o/p pin
  27   2          TH0 = pwm_width;        //Load timer
  28   2          TF0 = 0;                //Clear interrupt flag
  29   2       //               return;         //Return
  30   2        }
  31   1        else 
  32   1        {  //Start of Low level
  33   2           USRFLG = 0; //Clear flag
  34   2           PWMPIN = 0;     //Clear PWM o/p pin
  35   2           TH0 = 255 - pwm_width;  //Load timer
  36   2           TF0 = 0;        //Clear Interrupt flag
  37   2      //                return;         //return
  38   2        }
  39   1      }
  40          
  41          
  42          //***************************************************************
  43          
  44          //                      Serial Port initialization for 9600 baud
  45          
  46          //***************************************************************
  47          
  48          void SerInit()
  49          {
  50   1              TMOD |=0x20;
  51   1              TH1=-3;
  52   1              SCON=0x50;
  53   1              TR1=1;
  54   1              TI=1;
  55   1      }
C51 COMPILER V8.12   TEMPFAN                                                               03/21/2009 14:46:21 PAGE 2   

  56          
  57          //***************************************************************
  58          
  59          //                      Delay for 1 MS
  60          
  61          //***************************************************************
  62          
  63          void Delay_MS(unsigned int value)
  64          {
  65   1              unsigned int x,y;
  66   1              for(x=0;x<1000;x++)
  67   1                      for(y=0;y<value;y++);
  68   1      }
  69          //***************************************************************
  70          
  71          //                      PWM setup
  72          
  73          //***************************************************************
  74          void pwm_setup()
  75          {
  76   1         TMOD = 0;
  77   1         pwm_width = 160;
  78   1         EA = 1;
  79   1         ET0 = 1;
  80   1         TR0 = 1;
  81   1         TH0=0;
  82   1         TL0=0;
  83   1      }
  84          //***************************************************************
  85          
  86          //                      Delay for 1 MS
  87          
  88          //***************************************************************
  89          
  90          void main()
  91          { 
  92   1              unsigned int Temp;
  93   1              unsigned char Ascii[10];
  94   1              ADCinit();
  95   1              SerInit();
  96   1              lcd_init();
  97   1      
  98   1              lcd_com(15); // first line
  99   1              lcd_puts("   TEMPERATURE ");
 100   1              lcd_com(0xC0);     //second line
 101   1              lcd_puts(" CONTROLLED FAN");
 102   1              Delay_MS(100);
 103   1              
 104   1              lcd_com(0x01);  
 105   1              lcd_com(0x80);
 106   1              lcd_com(0x0C);
 107   1              lcd_puts("TEMP    deg C");
 108   1              pwm_setup();
 109   1              while(1)
 110   1              {
 111   2                      AddressLatch();
 112   2                      Start();
 113   2                      EOCCheck();
 114   2                      Temp=(unsigned char)ReadADC();
 115   2                      Speed(Temp);
 116   2                      itoa(Temp ,Ascii);
 117   2                      lcd_com(0x84);
C51 COMPILER V8.12   TEMPFAN                                                               03/21/2009 14:46:21 PAGE 3   

 118   2                      lcd_puts(Ascii);
 119   2      
 120   2              }
 121   1      }
 122          
 123          //***************************************************************
 124          
 125          //                      Integer to Ascii Conversion
 126          
 127          //***************************************************************
 128           void itoa(unsigned int value  ,unsigned char *string)
 129          {
 130   1      
 131   1              if(value<10)
 132   1              {
 133   2      
 134   2                              string[3]='\0';
 135   2                              string[2]=((value%10)+0x30);
 136   2                              value=value/10;
 137   2                              string[1]=((value%10)+0x30);
 138   2                              string[0]=' ';
 139   2              }
 140   1              else if(value<100)
 141   1              {
 142   2                              string[3]='\0';
 143   2                              string[2]=((value%10)+0x30);
 144   2                              value=value/10;
 145   2                              string[1]=((value%10)+0x30);
 146   2                              string[0]=' ';
 147   2              }
 148   1              else if(value<1000)
 149   1              {
 150   2      
 151   2                      string[3]='\0';
 152   2                      string[2]=((value%10)+0x30);
 153   2                      value=value/10;
 154   2                      string[1]=((value%10)+0x30);
 155   2                      value=value/10;
 156   2                      string[0]=((value%10)+0x30);
 157   2      
 158   2              }
 159   1              else if(value<10000)
 160   1              {
 161   2                      string[4]='\0';
 162   2                      string[3]=((value%10)+0x30);
 163   2                      value=value/10;
 164   2                      string[2]=((value%10)+0x30);
 165   2                      value=value/10;
 166   2                      string[1]=((value%10)+0x30);
 167   2                      value=value/10;
 168   2                      string[0]=((value%10)+0x30);
 169   2              }
 170   1      }
 171          
 172          //********************************************************************
 173          
 174          
 175          //********************************************************************
 176           void Speed(unsigned char Temp)
 177           {
 178   1              if(Temp>50)
 179   1               pwm_width=0;
C51 COMPILER V8.12   TEMPFAN                                                               03/21/2009 14:46:21 PAGE 4   

 180   1              else if(Temp<50)
 181   1                      if(Temp<30)
 182   1                      pwm_width=255;
 183   1                      else 
 184   1                  pwm_width=(255-((Temp-30)*6));
 185   1        }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    941    ----
   CONSTANT SIZE    =     46    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      1      22
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      2    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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