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

📄 +

📁 基于51单片机的智能温湿度报警系统
💻
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V9.00   1                                                                     01/19/2013 19:53:11 PAGE 1   


C51 COMPILER V9.00, COMPILATION OF MODULE 1
OBJECT MODULE PLACED IN 1.OBJ
COMPILER INVOKED BY: D:\k\C51\BIN\C51.EXE 1.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <REGX52.h>
   2          #include <intrins.h> 
   3          typedef unsigned char  U8;     
   4          typedef signed   char  S8;   
   5          typedef unsigned int   U16;     
   6          typedef signed   int   S16;     
   7          typedef unsigned long  U32;     
   8          typedef signed   long  S32;        
   9          typedef float          F32;      
  10          typedef double         F64;      
  11          
  12          sbit  DHT1  = P3^2;
  13          sbit  DHT2  = P3^3;
  14          U8 FLAG1,k1,FLAG2,k2;
  15          U8 count1,temp1, count2,temp2;
  16          U8 TZ1,TX1,HZ1,HX1,check1,TZ2,TX2,HZ2,HX2,check2;
  17          U8 TH_1,TL_1,HH_1,HL_1,checkdata1,comdata1, TH_2,TL_2,HH_2,HL_2,checkdata2 ,comdata2;
  18          U8 str[11]={"RS232"}, str2[5]={"rs322"};
  19          U8 AA=0,n=0;DD=0;
  20          U16 TEMP_H1=30,TEMP_L1=5,HUM_H1=70,HUM_L1=40;   
  21          U16 TEMP_H2=30,TEMP_L2=5,HUM_H2 =70,HUM_L2=40;
  22          sbit RS=P2^7;                                                                           
  23          sbit RW=P2^6;
  24          sbit E=P2^5;
  25          sbit hum_alarm_led1= P2^0; 
  26          sbit temp_alarm_led1= P2^1; 
  27          sbit temp_alarm_led2=P2^4; 
  28          sbit hum_alarm_led2 = P2^3; 
  29          sbit K1=P1^0;     
  30          sbit K2=P1^1;   
  31          sbit K3=P1^2;    
  32          sbit K4=P1^3;  
  33          sbit K5=P1^4;     
  34          sbit K6=P1^5;     
  35          sbit K7=P1^6;      
  36          sbit K8=P1^7;  
  37          U8 LCD_51,LCD_41,LCD_31,LCD_21,LCD_11; 
  38          U8 LCD_52,LCD_42,LCD_32,LCD_22,LCD_12;
  39          U8 code  LCDData[] ="0123456789";       
  40          U8 xdata first_line[16] ="X  %    Y  %    ";            
  41          U8 xdata second_line[16]="      :  :      ";     
  42          U8 timedata[3]={0x00,0x00,0x00};
  43          
  44          //char data dis[8]={0x00,0x00,0x00,0x00,0x00,0x00};      
  45          U16 con=0,con1=0,con2=0;          
  46          U8 xdata shuju[5][32];
  47          U16 p=0,M=0;
  48          U8 xdata  a1,a11,b1,b11,c1,c11,c111; 
  49          
  50          
  51                                                                                                                                                                                                                                                                                                             
  52          void delay1ms(U16 t)     
  53          {U16 i,j;
  54   1        for(i=0;i<t;i++)
  55   1          for(j=0;j<120;j++)
C51 COMPILER V9.00   1                                                                     01/19/2013 19:53:11 PAGE 2   

  56   1              ;
  57   1      } 
  58          
  59          void  Delay_10us(void)
  60                {
  61   1              U8 i;
  62   1         i--;i--;i--;
  63   1         i--;i--;i--;
  64   1             }
  65          void check_busy(void) 
  66          {
  67   1              while(1)
  68   1              {
  69   2              P0=0xff;
  70   2              E=0;_nop_();
  71   2              RS=0;_nop_();_nop_();
  72   2              RW=1;_nop_();_nop_();
  73   2              E=1;_nop_();_nop_();_nop_();nop_();
  74   2              if((P0&0x80)==0)
  75   2              {
  76   3                      break;
  77   3              }
  78   2              E=0;
  79   2              }
  80   1      }
  81          void write_command(U8 tempdata)
  82          {       E=0;_nop_();_nop_(); 
  83   1              RS=0; //寄存器选择指令
  84   1              _nop_();_nop_();RW=0;
  85   1              P0=tempdata;
  86   1          _nop_();_nop_();E=1;  
  87   1              _nop_();_nop_();E=0; _nop_();
  88   1              check_busy();
  89   1      }
  90          void write_data(U8 tempdata)
  91          {       E=0;_nop_();_nop_();  
  92   1              RS=1;//寄存器选择数据 
  93   1          _nop_();_nop_();RW=0;
  94   1              P0=tempdata;
  95   1          _nop_();_nop_();E=1; 
  96   1          _nop_();_nop_();E=0; _nop_(); 
  97   1              check_busy(); //检查忙
  98   1      }
  99          void init_lcd1602()      //LCD初始化
 100          {
 101   1       write_command(0x01);                                                   
 102   1       write_command(0x38);                                                   
 103   1       write_command(0x0c);                                                   
 104   1       write_command(0x06);             
 105   1       delay1ms(5);// Delay(5);        
 106   1      }
 107          void display(void)
 108          { 
 109   1            U8 i;
 110   1            write_command(0x80);
 111   1                  for(i=0;i<16;i++)
 112   1                      {
 113   2              write_data(first_line[i]);                                                
 114   2                      }
 115   1          write_command(0xc0);
 116   1                  for(i=0;i<16;i++)
 117   1                      {
C51 COMPILER V9.00   1                                                                     01/19/2013 19:53:11 PAGE 3   

 118   2       write_data(second_line[i]);
 119   2                      }
 120   1      }
 121          void display_pro(void)
 122          {        
 123   1             LCD_51=LCDData[(str[0]/10)%10];
 124   1             LCD_41=LCDData[str[0]%10];
 125   1             LCD_21=LCDData[(str[2]/10)%10];  
 126   1             LCD_11=LCDData[str[2]%10];                                                       
 127   1                 first_line[1]=LCD_51;        
 128   1                 first_line[2]=LCD_41;                  
 129   1                 first_line[5]=LCD_21;
 130   1                 first_line[6]=LCD_11;
 131   1                 second_line[4]=LCDData[str[5]];
 132   1                 second_line[5]=LCDData[str[6]];
 133   1                 second_line[7]=LCDData[str[7]];
 134   1                 second_line[8]=LCDData[str[8]];
 135   1                 second_line[10]=LCDData[str[9]];
 136   1                 second_line[11]=LCDData[str[10]];    
 137   1             LCD_52=LCDData[(str2[0]/10)%10];
 138   1             LCD_42=LCDData[str2[0]%10];
 139   1             LCD_22=LCDData[(str2[2]/10)%10]; 
 140   1             LCD_12=LCDData[str2[2]%10];                                      
 141   1                 first_line[9]=LCD_52;                                        
 142   1                 first_line[10]=LCD_42;
 143   1                 first_line[11]='%';
 144   1                 first_line[13]=LCD_22;
 145   1                 first_line[14]=LCD_12;
 146   1                    display();
 147   1      }
 148           void display_tiaoshi(void)
 149          {               
 150   1                 str[5]=timedata[2]/10; 
 151   1                 str[6]=timedata[2]%10;
 152   1                 str[7]=timedata[1]/10; 
 153   1                 str[8]=timedata[1]%10; 
 154   1                 second_line[4]=LCDData[str[5]];
 155   1                 second_line[5]=LCDData[str[6]]; 
 156   1                 second_line[7]=LCDData[str[7]];
 157   1                second_line[8]=LCDData[str[8]];              
 158   1                 display();
 159   1      }
 160          
 161          void tiaoshi() 
 162          {
 163   1       while(1)
 164   1      { display_tiaoshi();
 165   2       
 166   2        if(K5==0)
 167   2        {
 168   3          con++;
 169   3          }
 170   2         if(con==1) //shi
 171   2           {
 172   3                
 173   3                if(K6==0) timedata[2]++; display_tiaoshi();delay1ms(30);
 174   3                if (timedata[2]==23) 
 175   3                 {display_tiaoshi();delay1ms(30);timedata[2]=0;display_tiaoshi();
 176   4                  timedata[2]++;display_tiaoshi();
 177   4                 }
 178   3            if(K7==0) timedata[2]--;display_tiaoshi();delay1ms(30);
 179   3                 if (timedata[2]==0) 
C51 COMPILER V9.00   1                                                                     01/19/2013 19:53:11 PAGE 4   

 180   3                 {timedata[2]=23;delay1ms(30);timedata[2]--;display_tiaoshi();
 181   4                 }
 182   3           }
 183   2      
 184   2        if(con==2) //fen
 185   2           {if(K6==0) timedata[1]++;display_tiaoshi();delay1ms(30);
 186   3                if (timedata[1]==59) 
 187   3                {display_tiaoshi();delay1ms(30); timedata[2]++;timedata[1]++;timedata[1]=0;timedata[1]++;
 188   4                display_tiaoshi();delay1ms(30);
 189   4                 }
 190   3            if(K7==0) timedata[1]--;display_tiaoshi();delay1ms(30);
 191   3                 if (timedata[1]==0) 
 192   3                 {timedata[1]=59;delay1ms(30); timedata[1]--;display_tiaoshi();//delay1ms(30);
 193   4                 }
 194   3               }      
 195   2        
 196   2        if(con==3)
 197   2           {con=0;EA=1;return;
 198   3               }
 199   2       }
 200   1      }
 201          void  COM1()
 202             {
 203   1           U8 i;
 204   1           for(i=0;i<8;i++)      
 205   1                  {
 206   2                       FLAG1=2;       
 207   2                      while((!DHT1)&&FLAG1++);
 208   2                              Delay_10us();
 209   2                          Delay_10us();
 210   2                              Delay_10us();
 211   2                              temp1=0;
 212   2                   if(DHT1)temp1=1;
 213   2                          FLAG1=2;
 214   2                       while((DHT1)&&FLAG1++);
 215   2                if(FLAG1==1)break;
 216   2                         comdata1<<=1; 
 217   2                         comdata1|=temp1;       
 218   2                   }
 219   1                }
 220                  void RH1()
 221                  {
 222   1             DHT1=0;
 223   1                delay1ms(20); 
 224   1                 DHT1=1;
 225   1             Delay_10us();
 226   1                 Delay_10us();
 227   1                 Delay_10us();
 228   1                 Delay_10us();
 229   1             DHT1=1;
 230   1       if(!DHT1)//是否响应信号                
 231   1                 {
 232   2                FLAG1=2;
 233   2      while((!DHT1)&&FLAG1++);
 234   2                 FLAG1=2;
 235   2      while((DHT1)&&FLAG1++);
 236   2      COM1(); 
 237   2                HH_1=comdata1;
 238   2                 COM1(); 
 239   2                 HL_1=comdata1;
 240   2                 COM1();       
 241   2                TH_1=comdata1;
C51 COMPILER V9.00   1                                                                     01/19/2013 19:53:11 PAGE 5   

 242   2                 COM1();
 243   2                 TL_1=comdata1;
 244   2                 COM1();
 245   2                 checkdata1=comdata1;
 246   2                 DHT1=1;
 247   2      temp1=(TH_1+TL_1+HH_1+HL_1);
 248   2                 if(temp1==checkdata1)
 249   2                 {
 250   3                        HZ1=HH_1;
 251   3                        HX1=HL_1;
 252   3                        TZ1=TH_1;
 253   3                        TX1=TL_1;
 254   3                        check1=checkdata1;
 255   3                 }
 256   2                }
 257   1      }
 258                  void  COM2()
 259                {
 260   1             U8 i;
 261   1                for(i=0;i<8;i++)         
 262   1                  {
 263   2                      FLAG2=2;        
 264   2                      while((!DHT2)&&FLAG2++);
 265   2                              Delay_10us();
 266   2                          Delay_10us();
 267   2                              Delay_10us();
 268   2                              temp2=0;
 269   2                   if(DHT2)temp2=1;
 270   2                          FLAG2=2;
 271   2                       while((DHT2)&&FLAG2++);
 272   2               if(FLAG2==1)break;
 273   2                comdata2<<=1;
 274   2                         comdata2|=temp2;     
 275   2                   }
 276   1               }
 277          void RH2()
 278                  {
 279   1                DHT2=0;
 280   1               delay1ms(20); 
 281   1                 DHT2=1;
 282   1             Delay_10us();
 283   1                 Delay_10us();
 284   1                 Delay_10us();
 285   1                 Delay_10us();
 286   1             DHT2=1;
 287   1             if(!DHT2)                 
 288   1              {
 289   2                 FLAG2=2;
 290   2              while((!DHT2)&&FLAG2++);
 291   2                 FLAG2=2;
 292   2         while((DHT2)&&FLAG2++);
 293   2      COM2();

⌨️ 快捷键说明

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