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

📄 main.lst

📁 proteus与keil仿真89c55控制18b20 ds1302 字符液晶
💻 LST
字号:
C51 COMPILER V8.01   MAIN                                                                  10/03/2008 08:28:26 PAGE 1   


C51 COMPILER V8.01, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "data.h"
   2          
   3          /*---全局数据定义区---*/
   4          unsigned char str[25];          //存储需要在显示屏显示的字符
   5          unsigned char PageFlage;        //显示的当前页号
   6          unsigned char up;                       //上键按下次数
   7          unsigned char down;                     //下键按下次数
   8          unsigned char left;                     //左键按下次数
   9          unsigned char right;            //右键按下次数
  10          
  11          typedef struct time                     //时间结构体
  12          {
  13                  uchar sec;                              //秒
  14                  uchar min;                              //分
  15                  uchar hour;                             //小时
  16                  uchar day;                              //日期
  17                  uchar month;                    //月
  18                  uchar year;                             //年
  19                  uchar week;                             //星期
  20          };
  21          
  22          uchar xdata sec1        _at_ 0x4000;
  23          uchar xdata min1        _at_ 0x4001;
  24          uchar xdata hour1       _at_ 0x4002;
  25          uchar xdata day1        _at_ 0x4003;
  26          uchar xdata month1      _at_ 0x4004;
  27          uchar xdata year1       _at_ 0x4005;
  28          uchar xdata week1       _at_ 0x4006;
  29          
  30          uchar xdata sec2        _at_ 0x4007;
  31          uchar xdata min2        _at_ 0x4008;
  32          uchar xdata hour2       _at_ 0x4009;
  33          uchar xdata day2        _at_ 0x400a;
  34          uchar xdata month2      _at_ 0x400b;
  35          uchar xdata year2       _at_ 0x400c;
  36          uchar xdata week2       _at_ 0x400d;
  37          
  38          uchar xdata cal[8][7]   _at_ 0x4020;    //日历表存储
  39          
  40          /*---全局数据定义区---*/
  41          
  42          /*---外部函数引用区---*/
  43          //---显示器函数区
  44          extern char InitLcd();                                  //液晶显示器初始化函数
  45          extern void cls();                                              //液晶显示器清屏函数
  46          //液晶显示器显示函数
  47          extern uchar dprintf(uchar x,uchar y,char *string,uchar mod);
  48          //液晶显示器坐标设置函数
  49          extern void SetPos(uchar row, uchar col);
  50          extern void WriteCom(uchar cmd);                //液晶显示器命令写函数
  51          extern void WriteData(uchar Data);              //液晶显示器写数据函数
  52          
  53          //---键盘处理函数区
  54          extern uchar KeyScan();                                 //按键扫描函数
  55          extern uchar KeyProcess(uchar KeyNum);  //按键处理函数
C51 COMPILER V8.01   MAIN                                                                  10/03/2008 08:28:26 PAGE 2   

  56          
  57          //---DS1302处理函数区
  58          //1302写数据函数
  59          extern uchar Write1302(uchar Addr,uchar Data);
  60          extern uchar Read1302(uchar Addr);              //1302读数据函数
  61          
  62          //---DS18B20处理函数区
  63          extern void Init_DS18B20();                             //DS18B20复位函数
  64          extern unsigned char ReadOneChar();             //DS18B20字节读函数
  65          extern void WriteOneChar(uchar dat);    //DS18B20字节写函数
  66          extern void delay_18B20(unsigned int i);//DS18B20延时函数
  67          //extern uchar BcdToHex(uchar time,uchar Data);
  68          /*---外部函数引用区---*/
  69          
  70          /*---内部函数区---*/
  71          void BcdToChar(struct time times);              //BCD码转字符函数               
  72          void MainPage();                                                //主页显示函数
  73          int GetTemperature();                                   //读取温度函数
  74          /*---内部函数区---*/
  75          
  76          
  77          void BcdToChar(struct time times)
  78          {
  79   1              uchar str1[5],i;
  80   1      
  81   1              for(i=0;i<25;i++)
  82   1                      str[i]=0;
  83   1              for(i=0;i<5;i++)
  84   1                      str1[i]=0;
  85   1      
  86   1              strcat(str,"20");
  87   1              str1[0] = times.year >> 4 | 0x30;
  88   1              strcat(str,str1);
  89   1              str1[0] = times.year & 0x0f | 0x30;
  90   1              strcat(str,str1);
  91   1      
  92   1              strcat(str,".");
  93   1      
  94   1              str1[0] = times.month >> 4 | 0x30;
  95   1              strcat(str,str1);
  96   1              str1[0] = times.month & 0x0f | 0x30;
  97   1              strcat(str,str1);
  98   1      
  99   1              strcat(str,".");
 100   1      
 101   1              str1[0] = times.day >> 4 | 0x30;
 102   1              strcat(str,str1);
 103   1              str1[0] = times.day & 0x0f | 0x30;
 104   1              strcat(str,str1);
 105   1      
 106   1              strcat(str," w:");
 107   1      
 108   1              str1[0] = times.week & 0x0f | 0x30;
 109   1              strcat(str,str1);
 110   1      
 111   1              strcat(str," ");
 112   1      
 113   1              str1[0] = times.hour >> 4 | 0x30;
 114   1              strcat(str,str1);
 115   1              str1[0] = times.hour & 0x0f | 0x30;
 116   1              strcat(str,str1);
 117   1      
C51 COMPILER V8.01   MAIN                                                                  10/03/2008 08:28:26 PAGE 3   

 118   1              strcat(str,":");
 119   1      
 120   1              str1[0] = times.min >> 4 | 0x30;
 121   1              strcat(str,str1);
 122   1              str1[0] = times.min & 0x0f | 0x30;
 123   1              strcat(str,str1);       
 124   1      }
 125          
 126          int GetTemperature()            //读取18B20温度函数
 127          {
 128   1              uchar a=0;
 129   1              uchar b=0;
 130   1              uchar c=0;
 131   1              uchar temp,temp1,temp2;
 132   1              short cou[3],i;
 133   1      
 134   1              uchar str1[3];  
 135   1      
 136   1              Init_DS18B20();
 137   1              WriteOneChar(0xCC);     // 跳过读序号列号的操作
 138   1              WriteOneChar(0x44);     // 启动温度转换
 139   1      
 140   1              delay_18B20(200);       // this message is wery important
 141   1      
 142   1              Init_DS18B20();
 143   1              WriteOneChar(0xCC);     //跳过读序号列号的操作
 144   1              WriteOneChar(0xBE);     //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
 145   1      
 146   1              delay_18B20(200);
 147   1      
 148   1              a=ReadOneChar();        //读取温度值低位
 149   1              b=ReadOneChar();                //读取温度值高位
 150   1              temp1=b<<4;
 151   1              temp1+=(a&0xf0)>>4;
 152   1              temp2=a&0x0f;
 153   1      
 154   1          temp=((b*256+a)>>4);    //当前采集温度值除16得实际温度值
 155   1              if((temp & 0x80) == 0x80)
 156   1              {
 157   2                      temp1 = 1;
 158   2                      temp = abs((char)temp);
 159   2              }
 160   1              else
 161   1                      temp1 = 0;
 162   1      
 163   1              cou[0] = 0;
 164   1              cou[1] = 0;
 165   1              cou[2] = 0;
 166   1      
 167   1              while(temp >= 100)
 168   1              {
 169   2                      temp = temp - 100;
 170   2                      cou[0]++;
 171   2              }
 172   1      
 173   1              while(temp >= 10)
 174   1              {
 175   2                      temp = temp - 10;
 176   2                      cou[1]++;
 177   2              }
 178   1      
 179   1              cou[2] = temp;
C51 COMPILER V8.01   MAIN                                                                  10/03/2008 08:28:26 PAGE 4   

 180   1      
 181   1              for(i=0;i<25;i++)
 182   1                      str[i]=0;
 183   1      
 184   1              if(temp1 == 1)
 185   1                      strcat(str,"温度: -");
 186   1              else
 187   1                      strcat(str,"温度: +");
 188   1      
 189   1              cou[0] = cou[0] | 0x30;
 190   1              str1[0] = cou[0];
 191   1              cou[1] = cou[1] | 0x30;
 192   1              str1[1] = cou[1];
 193   1              cou[2] = cou[2] | 0x30;
 194   1              str1[2] = cou[2];
 195   1              strcat(str,str1);
 196   1      
 197   1              return temp;
 198   1      }
 199          
 200          void MainPage()
 201          {
 202   1              struct time times;
 203   1              int value;
 204   1      
 205   1              PageFlage = 1;
 206   1              left = 3;
 207   1              right = 1;
 208   1              times.min       =       Read1302(MIN|0x01);
 209   1              times.hour      =       Read1302(HOUR|0x01);
 210   1              times.day       =       Read1302(DAY|0x01);
 211   1              times.month     =       Read1302(MONTH|0x01);
 212   1              times.year      =       Read1302(YEAR|0x01);
 213   1              times.week      =       Read1302(WEEK|0x01);
 214   1              times.week      =       times.week - 1;
 215   1      
 216   1              BcdToChar(times);       //温度数值转换为字符
 217   1              
 218   1              SetPos(0,0);
 219   1              dprintf(0,0,str,1);             //显示时间
 220   1      
 221   1              value = GetTemperature();          //读取温度
 222   1      
 223   1              if(value == 0x7fff)
 224   1                      dprintf(0,16,"温度: ",1);
 225   1              else
 226   1                      dprintf(0,16,str,1);
 227   1      
 228   1              dprintf(0,48,"遥控",0);
 229   1              dprintf(32,48," ",1);
 230   1              dprintf(40,48,"日历",1);
 231   1              dprintf(72,48," ",1);
 232   1              dprintf(80,48,"计算器",1);
 233   1              dprintf(0,80,"受控车状态:  待命",1);
 234   1              dprintf(0,112,"确定",1);
 235   1              dprintf(127,112,"返回",1);
 236   1      }
 237          
 238          main()
 239          {
 240   1              int key;
 241   1              int value;
C51 COMPILER V8.01   MAIN                                                                  10/03/2008 08:28:26 PAGE 5   

 242   1              struct time times;
 243   1      
 244   1              InitLcd();
 245   1      
 246   1              dat = 0;
 247   1              clk = 0;
 248   1              PageFlage = 1;
 249   1      
 250   1              MainPage();     
 251   1              
 252   1              while(1)
 253   1              {
 254   2                      if(PageFlage == 1)
 255   2                      {
 256   3                              times.min       =       Read1302(MIN|0x01);
 257   3                              times.hour      =       Read1302(HOUR|0x01);
 258   3                              times.day       =       Read1302(DAY|0x01);
 259   3                              times.month     =       Read1302(MONTH|0x01);
 260   3                              times.year      =       Read1302(YEAR|0x01);
 261   3                              times.week      =       Read1302(WEEK|0x01);
 262   3                              times.week      =       times.week - 1;
 263   3      
 264   3                              day1 = day2 = times.day;
 265   3                              month1 = month2 = times.month;
 266   3                              year1 = year2 = times.year;
 267   3                              week1 = week2 = times.week;
 268   3              
 269   3                              BcdToChar(times);       //温度数值转换为字符
 270   3                      
 271   3                              SetPos(0,0);
 272   3                              dprintf(0,0,str,1);             //显示时间
 273   3                              
 274   3                              value = GetTemperature();          //读取温度
 275   3              
 276   3                              if(value == 0x7fff)
 277   3                                      dprintf(0,16,"温度: ",1);
 278   3                              else
 279   3                                      dprintf(0,16,str,1);
 280   3                      }
 281   2      
 282   2                      key = KeyScan();
 283   2                      KeyProcess(key);
 284   2              }
 285   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1133    ----
   CONSTANT SIZE    =     80    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     30      42
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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