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

📄 rt1602c+ds18b20_整数.lst

📁 RT1602C+DS18B20_整数.rar
💻 LST
字号:
C51 COMPILER V7.09   RT1602C_DS18B20_整数                                                  04/15/2006 08:02:58 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE RT1602C_DS18B20_整数
OBJECT MODULE PLACED IN RT1602C+DS18B20_整数.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\C51.EXE RT1602C+DS18B20_整数.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //单片机RT1602_C语言程序__DS18B20读写一体化C51源程序
   2          //只能显示两位整数,书中例程
   3          //2006年3月8951_LCD_1602_Q_D_MCU适用
   4          //AT89C54_Ver1.00
   5          //[注]:AT89C51的晶振频率为12MHz
   6          
   7          #include <REGX51.H>
   8          #include <stdio.h> 
   9          #include <absacc.h>
  10          #include <intrins.h> 
  11          #include <SS89BIN.h> 
  12             
  13          sbit E_E=P3^3;                                                                  //片选,下降沿触发
  14          sbit R_S=P3^4;                                                                  //H数据寄存器,L指令寄存器 
  15          sbit R_W=P3^5;                                                                  //H读数据,L写数据  
  16          sbit TMDAT=P3^0;                                                                //根据实际情况定义端口
  17          
  18          void dmsec(unsigned int count)                                  //延时1ms
  19                  {unsigned int i;                                                        
  20   1              while(count--)
  21   1                      {for(i=0;i<125;i++);
  22   2                      }
  23   1          }
  24          void tmreset(void)                                                              //复位
  25                  {unsigned int i;
  26   1              TMDAT=0;                                                                        
  27   1              i=103;while(i>0)i--;                                            //延时900us                                                                     
  28   1              TMDAT=1;                                                                        
  29   1              i=4;while(i>0)i--;              
  30   1              }                                                                               
  31          void tmpre(void)                                                                //等待接收数据
  32                  {unsigned int i;
  33   1              while(TMDAT);
  34   1              while(~TMDAT);
  35   1              i=4;while(i>0)i--;
  36   1              }
  37          bit tmrbit(void)                                                                //读一个bit
  38                  {unsigned int i;
  39   1              bit dat;
  40   1              TMDAT=0;i++;
  41   1              TMDAT=1;i++;i++;
  42   1              dat=TMDAT;
  43   1              i=8;while(i>0)i--;
  44   1              return(dat);
  45   1              }
  46          unsigned char tmrbyte(void)                                             //读一个byte
  47                  {unsigned int i,j,dat;
  48   1              dat=0;
  49   1              for(i=0;i<=8;i++)
  50   1                      {j=tmrbit();
  51   2                      dat=(j<<7)|(dat>>1);
  52   2                      }
  53   1              return(dat);
  54   1              }
  55          void tmwbyte(unsigned char dat)                                 //写一个byte
C51 COMPILER V7.09   RT1602C_DS18B20_整数                                                  04/15/2006 08:02:58 PAGE 2   

  56                  {unsigned int i;
  57   1              unsigned char j;
  58   1              bit testb;
  59   1              for(j=1;j<=8;j++)
  60   1                      {testb=dat&0x01;
  61   2                      dat=dat>>1;
  62   2                      if(testb)
  63   2                              {TMDAT=0;                                                       //写1
  64   3                              i++;i++;
  65   3                              TMDAT=1;
  66   3                              i=8;while(i>0)i--;
  67   3                              }
  68   2                      else
  69   2                              {TMDAT=0;                                                       //写0
  70   3                              i=8;while(i>0)i--;
  71   3                              TMDAT=1;
  72   3                              i++;i++;
  73   3                              }
  74   2                      }
  75   1              }
  76          void tmstart(void)                                                              //DS18B20开始工作
  77                  {tmreset();
  78   1              tmpre();
  79   1              dmsec(1);
  80   1              tmwbyte(0xCC);                                                          //skip rom
  81   1              tmwbyte(0x44);                                                          //convert
  82   1              }
  83          unsigned char tmrtemp(void)
  84                  {unsigned char a,b,y1,y2,y3;
  85   1              tmreset();
  86   1              tmpre();
  87   1              dmsec(1);
  88   1              tmwbyte(0xCC);                                                          //skip rom
  89   1              tmwbyte(0xBE);                                                          //convert
  90   1              a=tmrbyte();                                                            //LSB
  91   1              b=tmrbyte();                                                            //MSB
  92   1              y1=a>>4;
  93   1              y2=b<<4;
  94   1              y3=y1|y2;
  95   1              return(y3);
  96   1              }
  97          
  98          
  99          void TIME(int nt)                                                               //延时函数
 100                  {long int it=0;
 101   1              for(it=0;it<nt*1000;it++);
 102   1              return;
 103   1              }
 104          void DELAY(void)                                                                //判断液晶显示器是否忙的子程序
 105                  {P1=0xFF;
 106   1              R_S=0;R_W=1;E_E=0;
 107   1              _nop_();
 108   1              E_E=1;
 109   1              while(P1_7);                                                            //如果P1.7为高电平表示忙就循环等待
 110   1              return;
 111   1              }
 112          void WR1602C(char mun,char rs)                                  //写入控制命令的子程序
 113                  {P1=mun;                                                                        //将代码送到P1口
 114   1              R_S=rs;                                                                         //1数据寄存器,0指令寄存器 
 115   1              R_W=0;E_E=0;                                                            //执行显示命令
 116   1              DELAY();                                                                        //判断液晶模块是否忙
 117   1              E_E=1;                                                                          //显示完成,程序停车
C51 COMPILER V7.09   RT1602C_DS18B20_整数                                                  04/15/2006 08:02:58 PAGE 3   

 118   1              return;
 119   1              }
 120          
 121          void main(void)
 122          {       unsigned int c02;       
 123   1              P3_1=0;P3_2=1;TIME(3);                                          //指示灯闪烁
 124   1              P3_1=1;P3_2=0;TIME(3);  
 125   1              P3_1=0;P3_2=1;TIME(3);
 126   1      
 127   1              WR1602C(B0000_0001,0);                                          //清屏并光标复位                                                                        
 128   1              WR1602C(B0011_1000,0);                                          //设置显示模式:8位2行5x7点阵
 129   1              WR1602C(B0000_1111,0);                                          //显示器开,光标开,光标允许闪烁
 130   1              WR1602C(B0000_0110,0);                                          //文字不动,光标自动右移
 131   1              WR1602C(B1110_1000,0);                                          //写入显示起始地址(第一行第一个位置)
 132   1              WR1602C(B0100_0001,1);                                          //字母A的代码
 133   1              WR1602C(B0100_0010,1);
 134   1              WR1602C(B0100_0011,1);
 135   1              TIME(5);
 136   1      
 137   1      START:
 138   1              tmstart();      
 139   1              c02=tmrtemp();                                                          //读温度
 140   1              
 141   1              WR1602C(B1100_0000,0);                                          //写入显示起始地址(第二行第一个位置)
 142   1              WR1602C(0x4E,1);WR1602C(0x6F,1);                        //第二排从头开始显示NowTemp:
 143   1              WR1602C(0x77,1);WR1602C(0x54,1);
 144   1              WR1602C(0x65,1);WR1602C(0x6D,1);                                
 145   1              WR1602C(0x70,1);WR1602C(0x3A,1);
 146   1      
 147   1              WR1602C(c02/10+48,1);                                           //温度整数位_十位
 148   1              WR1602C(c02%10+48,1);                                           //温度整数位_个位
 149   1              WR1602C(0x2E,1);                                                        //显示.
 150   1      
 151   1              TIME(5);        
 152   1              goto START;     
 153   1      
 154   1      
 155   1      }
 156          
 157          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    600    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      10
   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 + -