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

📄 18bb20.lst

📁 刚通过的1820温度显示程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V6.12  18BB20                                                                 04/20/2008 13:57:54 PAGE 1   


C51 COMPILER V6.12, COMPILATION OF MODULE 18BB20
OBJECT MODULE PLACED IN .\18bb20.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\18bb20.c DEBUG OBJECTEXTEND

stmt level    source

   1          
   2          #include "reg51.h"
   3          #include "intrins.h"
   4          
   5          #define uchar unsigned char
   6          #define uint  unsigned int
   7          #define NOP() _nop_();
   8          
   9          //液晶显示功能引脚定义					
  10          sbit A0 = P3^0;//数据1/命令0选择
  11          sbit _WR = P3^7;//读写					
  12          sbit E1 = P3^4;	//片选1(Master)					
  13          sbit E2 = P3^3;//片选2(slave)                 
  14          #define lcd_data P2//数据
  15          
  16          //液晶显示常用操作宏定义
  17          #define set_E1() (E1=1)          //1片选M
  18          #define set_E2() (E2=1)          //1片选S
  19          #define set_A0() (A0=1)          //1数据    
  20          #define set_WR() (_WR=1)         //1读
  21          
  22          #define clr_E1() (E1=0)          //0
  23          #define clr_E2() (E2=0)          //0
  24          #define clr_A0() (A0=0)          //0命令
  25          #define clr_WR() (_WR=0)         //0写
  26          
  27          //液晶显示控制命令表
  28          #define disp_off			0xAE		//显示关闭
  29          #define disp_on 			0xAF		//显示打开
  30          #define disp_start_line  	0xC0		//显示起始地址(后5位-表示0-31行)
  31          #define page_addr_set		0xB8		//页地址设置(0~3)
  32          #define col_addr_set		0x00		//列地址设置(0~61)
  33          #define status_busy			0x80		//0=ready
  34          #define mode_write          0xEE        //写模式
  35          #define dynamic_driver      0xA4        //动态驱动 
  36          #define adc_select			0xA0		//clockwise
  37          #define clk32 	            0xA9		//刷新时钟设置1/32
  38          #define clk16 	            0xA8		//刷新时钟设置1/16
  39          #define reset    			0xE2		//软件复位
  40          
  41          //温度显示功能引脚定义
  42          bit flag;//温度标记;1为负温度;0为正温度
  43          sbit DQ = P1^1;
  44          //液晶显示缓存区定义
  45          uchar dot_buffer[32];					//点阵缓存区
  46          uchar disp_buffer[8];   				//ram数据显示缓存区
  47          
  48          ///////////////////////////////////////////////
  49          //液晶显示的函数
  50          //////////////////////////////////////////////
  51          void lcd_init(void);					//LCD初始化
  52          void lcd_clr(void);                     //LCD清屏
  53          void wait_ready(void);					//等待ready
  54          
  55          //点阵码显示输出(用于图片输出);参数为:起始行,起始列,宽度,表格table名称;
C51 COMPILER V6.12  18BB20                                                                 04/20/2008 13:57:54 PAGE 2   

  56          void draw_bmp(uchar col,uchar layer,uchar width,uchar *bmp); 
  57          
  58          //单个ascci码输出(ascii_code为ascii编码)  
  59          ////参数为:起始行;起始层:0为下面1为上面;直接给ASCII码如"A";显示模式0正常1反白;                        
  60          void disp_one_ascii(uchar col,uchar layer,uchar ascii_code,uchar mode);
  61          
  62          //ram数据(数字)显示输出输出disp_buffer里面的数组; 
  63          //参数为:起始行;起始层:0为下面1为上面;显示个数;显示模式0正常1反白;                                        
             -             
  64          void disp_ram_data(uchar col,uchar layer,uchar n,uchar mode); 
  65             
  66          //通用混合字串显示 
  67          //参数为:起始行;起始层:0为下面1为上面;要显示的内容如"太川";显示模式0正常1反白;                         
  68          void dprintf(uchar col,uchar layer,uchar *buf,uchar mode);  
  69             
  70          //////////////////////////////////////////////////////////
  71          //温度测量的函数
  72          /////////////////////////////////////////////////////////
  73          void write_byte(uchar val);  //向DS18B20写入1个字节 
  74          uchar read_byte(void);        //从18b20读一个字节.返回读到的内容
  75          dreset();                //初始化18B20
  76          get_temperature(void);//读取温度子程序并对值保存
  77          ///////////////////////////////////////////////////////////////
  78          //////////////////////////////////////////////////////////////
  79          
  80          void delay(uint x)   ////when crystal is 12M ,a*2+5 us  ,子程序调用要5us,while 就等于DJNZ指令
  81          { 
  82   1      while (x--);
  83   1      }
  84          //////////////////////
  85          void write_byte(uchar val)  //向DS18B20写入1个字节 
  86          {
  87   1          uchar i;
  88   1          for(i=0;i<8;i++)
  89   1          {
  90   2              DQ=0;
  91   2              _nop_();                      //要求>1us,但又不能超过15us
  92   2              _nop_();
  93   2              if(0x01&val)
  94   2                   DQ=1;
  95   2              delay(20);                  //要求总时间在60-120us
  96   2              DQ=1;                  //释放总线
  97   2              _nop_();_nop_();                    //要求>1us      
  98   2              val=val>>1;
  99   2          }  
 100   1      }
 101          ////////////////////
 102          uchar read_byte(void)        //从18b20读一个字节.返回读到的内容
 103          {
 104   1          uchar i,j;
 105   1          j=0;                              
 106   1          for(i=0;i<8;i++)
 107   1           {DQ=1;
 108   2            DQ=0;  
 109   2      		j=j>>1;
 110   2              
 111   2                                   //要求>1us,但又不能超过15us
 112   2              DQ=1;                  //释放总线
 113   2              _nop_();
 114   2              _nop_();
 115   2              if(DQ)
 116   2              j|=0x80;
C51 COMPILER V6.12  18BB20                                                                 04/20/2008 13:57:54 PAGE 3   

 117   2              delay(30); 
 118   2           }
 119   1      	    return  (j);
 120   1       }
 121           ///////////////////
 122          dreset()                //初始化18B20 
 123          { 
 124   1          bit presence=0;      //定义一个应答信号     
 125   1          DQ=1; 
 126   1       	 DQ=0;
 127   1           delay(80);                 //置总线为低电平并保持至少480us       
 128   1          DQ=1;                //等电阻拉高总线并保持15-60us 
 129   1         delay(5);     
 130   1          presence=DQ;              //接受应答信号 
 131   1         delay(13);  //延时60-240us  
 132   1         DQ=1;   
 133   1      	//if (presence) dprintf(0,1,"NO",0);
 134   1      	  // else dprintf(0,1,"OK!",0);//返回应答信号 
 135   1      }
 136          //////////////////
 137          
 138          
 139          
 140          /* 读取温度子程序       */
 141           get_temperature(void)
 142          {
 143   1          uchar msb=0;//高8位
 144   1          uchar lsb=0;//低8位
 145   1          dreset();         /* 发送复位信号     */
 146   1          delay(30);
 147   1          write_byte(0xcc);          /* 跳过ROM          */
 148   1          write_byte(0x44);         /* 发送转换温度命令 */
 149   1      	 dreset();
 150   1          delay(30);
 151   1          write_byte(0xcc);
 152   1          write_byte(0xBE);         /* 发送读memory命令 */
 153   1          lsb =read_byte();
 154   1          msb =read_byte();
 155   1          dreset();
 156   1      	 delay(10000);
 157   1      	if(msb&0xf8)  {  flag=1;msb=~msb; lsb=~lsb+1;  }    //如果为负温度取反加1		   		   			
 158   1      	else  flag=0; 	
 159   1      			
 160   1      	msb=(msb<<4)|(lsb>>4);
 161   1      	if (flag)      disp_buffer[0]=253;                //负温度指示标号根据自己表格位置修改
 162   1      	if (msb/100)   disp_buffer[0]=msb/100;            //百位数
 163   1         else           disp_buffer[0]=251;               //正温度指示标号根据自己表格位置修改
 164   1      	disp_buffer[1]=msb%100/10;                       //十位数
 165   1      	disp_buffer[2]=msb%10;                          //个位数
 166   1      	disp_buffer[3]=254;                              //小数点指示标号根据自己表格位置修改
 167   1      	disp_buffer[4]=(lsb&0x0f)*625/1000;            //小数点第一位
 168   1         //disp_buffer[5]=(lsb&0x0f)*625%1000/100;        //小数点第二位
 169   1      	//disp_buffer[6]=(lsb&0x0f)*625%100/10;          //小数点第三位
 170   1      	//disp_buffer[7]=(lsb&0x0f)*625%10;            //小数点第四位
 171   1      
 172   1      
 173   1      }
 174          
 175          ///////////////////////////////////////////////////////////////////////////
 176          /////////////////////////////////////////////////////////////////////////////
 177          ///////////////////////////////////////////////////////////////////////////
 178          unsigned char code top[] =                  // 数据表图片上半部分
C51 COMPILER V6.12  18BB20                                                                 04/20/2008 13:57:54 PAGE 4   

 179          {
 180                0x00,0x00,0x00,0x60,0x70,0xF0,0xF8,0xF8,
 181                0xF8,0x40,0xFC,0x44,0x44,0x44,0x4C,0x78,
 182                0x60,0x60,0x70,0x58,0x44,0xFC,0xC7,0xFD,
 183                0x41,0x01,0x01,0x03,0x02,0x06,0x0C,0x18,
 184                0x04,0x02,0x02,0x02,0xFE,0x40,0x40,0x40,
 185                0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,
 186                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 187                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 188                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 189                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 190                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 191                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 192                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 193                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 194                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 195                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
 196                0x01,0x00,0x00,0x01,0x06,0x04,0x08,0x18,
 197                0x10,0x10,0x10,0x10,0x08,0x0C,0x07,0x03,
 198                0x02,0x02,0x04,0x04,0x04,0x04,0x04,0x04,
 199                0x04,0x04,0x06,0x02,0x01,0x00,0x00,0x00,
 200                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 201                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 202                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 203                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 204                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 205                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 206                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 207                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 208                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 209                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
 210          };
 211          
 212          unsigned char code bot[] =                  // 数据表图片下半部分
 213          {
 214                0x00,0x00,0x20,0x20,0x20,0xE0,0x60,0x38,
 215                0xAC,0xE0,0x20,0x00,0x80,0x80,0x88,0x88,
 216                0xC8,0xC8,0xF8,0xB0,0x80,0x80,0x80,0x80,
 217                0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
 218                0xC0,0x30,0x08,0x80,0x00,0x00,0x00,0x00,
 219                0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,
 220                0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,
 221                0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x20,
 222                0x3C,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,
 223                0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,
 224                0x00,0x00,0x34,0x64,0xC4,0x84,0x04,0x04,
 225                0xFC,0x04,0x04,0x04,0x84,0xC4,0x74,0x04,
 226                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 227                0x60,0x30,0x10,0xD0,0x90,0x10,0x10,0x12,
 228                0x1E,0x10,0x10,0x10,0x90,0x30,0x00,0x00,
 229                0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x05,
 230                0x06,0x0F,0x19,0x10,0x00,0x00,0x00,0x00,
 231                0x00,0x08,0x18,0x18,0x0F,0x00,0x00,0x00,
 232                0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,
 233                0x06,0x03,0x00,0x00,0x00,0x01,0x03,0x06,
 234                0x0C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
 235                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 236                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
 237                0x21,0x20,0x30,0x28,0x29,0x25,0x3F,0x25,
 238                0x25,0x27,0x20,0x20,0x20,0x20,0x20,0x00,
 239                0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x02,
 240                0x02,0x02,0xFF,0x02,0x03,0x03,0x02,0x02,
C51 COMPILER V6.12  18BB20                                                                 04/20/2008 13:57:54 PAGE 5   

 241                0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,
 242                0x01,0x01,0x01,0x41,0x61,0x21,0x21,0x21,
 243                0x33,0x17,0x0D,0x15,0x25,0x23,0x41,0x41,
 244                0x01,0x01,0x00,0x00
 245          };
 246          
 247                                                
 248          
 249          typedef struct typFNT_GB16                 // 汉字字模数据结构
 250          {
 251                 signed char Index[2];              
 252                 char Msk[32];                      
 253          };
 254          
 255          
 256          struct typFNT_GB16 code GB_16[] =          
 257          {
 258          "欢", 0x04,0x34,0xC4,0x04,0xC4,0x3C,0x20,0x10,
 259                0x0F,0xE8,0x08,0x08,0x28,0x18,0x00,0x00,
 260                0x10,0x08,0x06,0x01,0x82,0x8C,0x40,0x30,
 261                0x0C,0x03,0x0C,0x10,0x60,0xC0,0x40,0x00,
 262          
 263          "迎", 0x40,0x42,0x44,0xC8,0x00,0xFC,0x04,0x02,
 264                0x82,0xFC,0x04,0x04,0x04,0xFE,0x04,0x00,
 265                0x00,0x40,0x20,0x1F,0x20,0x47,0x42,0x41,
 266                0x40,0x7F,0x40,0x42,0x44,0x63,0x20,0x00,
 267          
 268          "光", 0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F,
 269                0x40,0xC0,0x50,0x48,0x46,0x64,0x40,0x00,
 270                0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,
 271                0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,
 272          
 273          "临", 0x00,0xFC,0x00,0xFF,0x40,0x20,0x10,0x0C,
 274                0x2B,0x48,0xC8,0x08,0x08,0x8C,0x08,0x00,
 275                0x00,0x1F,0x00,0xFF,0x00,0xFF,0x41,0x41,
 276                0x41,0x7F,0x41,0x41,0x41,0xFF,0x01,0x00,

⌨️ 快捷键说明

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