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

📄 text1.lst

📁 单片机通信程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   TEXT1                                                                 02/26/2009 16:22:34 PAGE 1   


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

line level    source

   1          #include <reg52.h> 
   2          #include <absacc.h>
   3          #include <stdio.h>
   4          #include<intrins.h>
   5          #define uchar unsigned char
   6          #define uint unsigned int
   7          #include <lcd_1602_guang.h>
   8          uint wendu,volt;
   9          uint a[10];
  10          uint wen_du;
  11          sbit p12=P1^2;  //7135 run
  12          sbit p15=P1^5;//加热控制管脚
  13          unsigned char key;//键盘返回值
  14          uchar dayin;
  15          uchar c=0;
  16          char lstemp;//放置临时设置的温度
  17          //unsigned char *zf;//温度转字符
  18          uchar TempBuffer[10];//暂时存放要显示的直
  19          uchar bc[10];//保持要显示的值
  20          uint baochi;//保持要显示的值
  21          unsigned char table[7];//放置设定温度值的数组
  22          unsigned char count,up,down,done;
  23          char hide_t1,hide_t2;
  24          int fout;//fout是决定是否加热,加热时间
  25          sbit fs=P2^0;
  26          /*****************定时器1**********************************/
  27          
  28          void timer1()interrupt 3 using 2{
  29   1      if(fout>0)fout--;//fout减到0为止
  30   1      if(fout<0)fout++;
  31   1      TH1=(65536-55000)/256;
  32   1      TL1=(65536-55000)%256;
  33   1      
  34   1      }
  35          
  36          /******************************************************/
  37          /*********************PID结构体***********************************/
  38          typedef struct PID
  39          {
  40          uint setpoint;             //设定目标值
  41          uint proportion;          //比例系数
  42          uint integral;            //积分系数
  43          uint derivative;          //微分系数
  44          int lasterror;            // 上次偏差
  45          int sumerror;             //历史误差计数
  46          }PID;
  47           
  48          /*********************PID结构体***********************************/
  49          /*********************************PD算法********************************************/
  50          uint PIDCalc(PID*pp,uint NextPoint)
  51          {
  52   1      int derror,error;
  53   1      error=pp->setpoint*10-NextPoint;
  54   1      derror=error-pp->lasterror; 
  55   1      pp->lasterror=error;
C51 COMPILER V8.02   TEXT1                                                                 02/26/2009 16:22:34 PAGE 2   

  56   1      return(pp->proportion*error+pp->derivative*derror);
  57   1      }
  58          
  59          PID stPID;   //定义一个STpid变量
  60          
  61          
  62          /******************************************************/
  63          void dl_1ms(void)
  64          {unsigned char z;
  65   1      
  66   1      for(z=124;z>0;z--); 
  67   1      
  68   1      }
  69          /******************************************************/
  70          delay(void)
  71             {
  72   1        int d;
  73   1        for(d=20000;d>0;d--){}   //延时10ms
  74   1           }
  75          
  76          /*****************  整数型转字符型方便打印*************************************/
  77                  void IntToStr( uint t, unsigned char *sc, unsigned char n) 
  78          {
  79   1              unsigned char a[5]; char i, j;                                  
  80   1              a[0]=(t/10000)%10;         //取得整数值到数组           
  81   1              a[1]=(t/1000)%10;                                       
  82   1              a[2]=(t/100)%10;                                        
  83   1              a[3]=(t/10)%10;                                         
  84   1              a[4]=(t/1)%10;                                          
  85   1                                                            
  86   1              for(i=0; i<5; i++)         //转成ASCII码                
  87   1                      a[i]=a[i]+'0';                                          
  88   1              for(i=0; a[i]=='0' && i<=3; i++);                       
  89   1              for(j=5-n; j<i; j++)       //填充空格                   
  90   1                      { *sc=' ';  sc++; }                                     
  91   1              for(; i<5; i++)                                         
  92   1                      { *sc=a[i]; sc++; }  //加入有效的数字                   
  93   1              *sc='\0'; 
  94   1      } 
  95          
  96          
  97          /*****************发射函数***************************/
  98          
  99          void transmit(uint aa)
 100          {
 101   1              uchar i;
 102   1              uint bite;
 103   1                                      fs=0;       //起始位            26
 104   1                                      _nop_();
 105   1                                      
 106   1                                      _nop_();
 107   1                                      _nop_();
 108   1                                      _nop_();
 109   1                                      
 110   1                                      _nop_();
 111   1                                      _nop_();
 112   1                                      _nop_();
 113   1                                      
 114   1                                      _nop_();
 115   1                                      _nop_();
 116   1                                      _nop_();
 117   1                                      
C51 COMPILER V8.02   TEXT1                                                                 02/26/2009 16:22:34 PAGE 3   

 118   1                                      _nop_();
 119   1                                      _nop_();
 120   1                                      _nop_();
 121   1                                      
 122   1                                      _nop_();
 123   1                                      _nop_();
 124   1                                      _nop_();
 125   1                                      
 126   1                                      _nop_();
 127   1                                      _nop_();
 128   1                                      _nop_();
 129   1                                      
 130   1                                      _nop_();
 131   1                                      _nop_();
 132   1                                      _nop_();
 133   1                                                                      
 134   1                                      _nop_();
 135   1                                      _nop_();
 136   1                                      _nop_();
 137   1      
 138   1                                      fs=1;
 139   1      
 140   1                                      _nop_();
 141   1                                      _nop_();
 142   1                                      _nop_();
 143   1                                      
 144   1                                      _nop_();
 145   1                                      _nop_();
 146   1                                      _nop_();
 147   1                                      
 148   1              for(i=0;i<16;i++)
 149   1              { 
 150   2                      bite=aa&0x8000;                                           //由高到低
 151   2                      aa=aa<<1;
 152   2                      if(bite==0)
 153   2                               {
 154   3                                      fs=0;           //0                              8-13
 155   3                                      _nop_();
 156   3                                      _nop_();
 157   3                                      _nop_();                                
 158   3                                      _nop_();                 
 159   3                                      fs=1;
 160   3                              }
 161   2                else  
 162   2                              {
 163   3                                      fs=0;           //1                              18-23
 164   3                                      _nop_();
 165   3                                      _nop_();
 166   3                                      _nop_();
 167   3                                      
 168   3                                      _nop_();
 169   3                                      _nop_();
 170   3                                      _nop_();
 171   3                                      
 172   3                                      _nop_();
 173   3                                      _nop_();
 174   3                                      _nop_();
 175   3                                      
 176   3                                      _nop_();
 177   3                                      _nop_();
 178   3                                      _nop_();
 179   3                                      
C51 COMPILER V8.02   TEXT1                                                                 02/26/2009 16:22:34 PAGE 4   

 180   3                                      _nop_();
 181   3                                      _nop_();                           
 182   3                                      fs=1;
 183   3                              }
 184   2              }
 185   1              for(i=0;i<50;i++);      
 186   1      }
 187          
 188          
 189          /******************************************************/
 190          
 191          
 192          
 193          
 194          void int0() interrupt 0 using 1
 195          {  
 196   1      
 197   1              volt=TH0*256+TL0;
 198   1              a[c]=volt/2-10000+115;//单片机周期1us ,ad7135周期2us,后面加的115是模数转换时的偏差
 199   1        
 200   1         c++;
 201   1         TL0=0;
 202   1              TH0=0;
 203   1              if(c==6)
 204   1              {p12=0;
 205   2              }
 206   1      }
 207          /******************显示当前温度********************************************/
 208          void diswendu()
 209          {
 210   1          IntToStr(baochi,&TempBuffer[0],5);
 211   1              display_string(0,0,&TempBuffer[0]);
 212   1          IntToStr(wendu,&bc[0],5);
 213   1              display_char(0,1,bc[0]);  
 214   1              display_char(1,1,bc[1]); 
 215   1              display_char(2,1,bc[2]); 
 216   1              display_char(3,1,bc[3]); 
 217   1              display_char(4,1,'.'); 
 218   1              display_char(5,1,bc[4]); 
 219   1              display_char(6,1,0xdf);
 220   1              display_char(7,1,'c');
 221   1      }
 222          /****************************************************************/
 223          /***********************读取6次去除最大最小值,取其中4个值***********************/
 224          void pxbj()
 225          {
 226   1      
 227   1      
 228   1      uchar i,j; 
 229   1       unsigned long sum=0;
 230   1       uint temp;
 231   1      for(j=0;j<=5;j++) 
 232   1      { for (i=0;i<6-j;i++) 
 233   2        if (a[i]>a[i+1]) 
 234   2             { temp=a[i]; 

⌨️ 快捷键说明

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