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

📄 ds12cr887mnl.lst

📁 基于DS12887的多功能电子智能时钟
💻 LST
📖 第 1 页 / 共 3 页
字号:
 187   1      }
 188          
 189          //写一个字节函数
 190          void WriteOneChar(uchar dat)
 191          {
 192   1              uchar i=0;
 193   1              for (i=8; i>0; i--)
 194   1              {
 195   2                      DQ = 0;
 196   2                      DQ = dat&0x01;
 197   2                      Delay(5);
 198   2                      DQ = 1;
 199   2                      dat>>=1;
 200   2              }
 201   1      }
 202          
 203          //读取温度函数
 204          uint ReadTemperature(void)
 205          {
 206   1              uchar a=0;
 207   1              uchar b=0;
 208   1              uint t=0;
 209   1              float tt=0;
 210   1              Init_DS18B20();
 211   1              WriteOneChar(0xCC); // 跳过读序号列号的操作
 212   1              WriteOneChar(0x44); // 启动温度转换
 213   1              Init_DS18B20();
 214   1              WriteOneChar(0xCC); //跳过读序号列号的操作
 215   1              WriteOneChar(0xBE); //读取温度寄存器
 216   1              a=ReadOneChar();  //读低8位
 217   1              b=ReadOneChar(); //读高8位
 218   1              t=b;
 219   1              t<<=8;
 220   1              t=t|a;
 221   1              tt=t*0.0625;
 222   1              t= tt*10+0.5; //放大10倍输出并四舍五入
 223   1              return(t);
 224   1      }
 225          
 226          /*公历节日数据库-------------------------------------------------------------*/
 227          void days (void)  
 228          {                       
 229   1              lcm_w_test(0,0x98);//在液晶屏的第四行第一列显示以下节日提示
 230   1              if ( month == 1 && date ==  1 ){ lcm_w_word("    元旦快乐    "); }//1月
 231   1              if ( month == 1 && date == 28 ){ lcm_w_word("  世界麻风日    "); }
 232   1                
 233   1              if ( month == 2 && date ==  2 ){ lcm_w_word("  世界湿地日    "); }//2月
 234   1              if ( month == 2 && date == 13 ){ lcm_w_word("  明天情人节了  "); }              
 235   1              if ( month == 2 && date == 14 ){ lcm_w_word("  今天是情人节  "); }
 236   1                                      
 237   1              if ( month == 3 && date ==  1 ){ lcm_w_word("  国际海豹日    "); }//3月         
 238   1              if ( month == 3 && date ==  3 ){ lcm_w_word("  全国爱耳日    "); }              
 239   1              if ( month == 3 && date ==  8 ){ lcm_w_word("国际劳动妇女节  "); }              
 240   1              if ( month == 3 && date == 12 ){ lcm_w_word("    植树节      "); }              
 241   1              if ( month == 3 && date == 14 ){ lcm_w_word("  国际警察日    "); }              
C51 COMPILER V8.05a   DS12CR887MNL                                                         04/15/2009 21:34:52 PAGE 5   

 242   1              if ( month == 3 && date == 15 ){ lcm_w_word("  消费者权益日  "); }              
 243   1              if ( month == 3 && date == 17 ){ lcm_w_word("  国际航海日    "); }              
 244   1              if ( month == 3 && date == 21 ){ lcm_w_word("  世界森林日    "); }              
 245   1              if ( month == 3 && date == 22 ){ lcm_w_word("    世界水日    "); }              
 246   1              if ( month == 3 && date == 23 ){ lcm_w_word("  世界气象日    "); }              
 247   1              if ( month == 3 && date == 24 ){ lcm_w_word("世界防治结核病日"); }
 248   1                              
 249   1              if ( month == 4 && date ==  1 ){ lcm_w_word("愚人节  小心上当"); }//4           
 250   1              if ( month == 4 && date ==  7 ){ lcm_w_word("  世界卫生日    "); }              
 251   1              if ( month == 4 && date ==  8 ){ lcm_w_word("    复活节      "); }              
 252   1              if ( month == 4 && date == 13 ){ lcm_w_word("  黑色星期五    "); }
 253   1                              
 254   1              if ( month == 5 && date ==  1 ){ lcm_w_word("五一国际劳动节  "); }//5           
 255   1              if ( month == 5 && date ==  4 ){ lcm_w_word("    青年节      "); }              
 256   1              if ( month == 5 && date ==  8 ){ lcm_w_word("  世界红十字日  "); }              
 257   1              if ( month == 5 && date == 12 ){ lcm_w_word("  国际护士节    "); }              
 258   1              if ( month == 5 && date ==  5 ){ lcm_w_word("近日请注意母亲节"); }              
 259   1              if ( month == 5 && date == 15 ){ lcm_w_word("  国际家庭日    "); }
 260   1              if ( month == 5 && date == 31 ){ lcm_w_word("  世界无烟日    "); }              
 261   1                              
 262   1              if ( month == 6 && date ==  1 ){ lcm_w_word("  国际儿童节    "); }//6
 263   1              if ( month == 6 && date ==  5 ){ lcm_w_word("  世界环境日    "); }              
 264   1              if ( month == 6 && date == 26 ){ lcm_w_word("  国际禁毒日    "); }              
 265   1              if ( month == 6 && date ==  6 ){ lcm_w_word("  全国爱眼日    "); }              
 266   1              if ( month == 6 && date == 13 ){ lcm_w_word("近日请注意父亲节"); }
 267   1              if ( month == 6 && date == 15 ){ lcm_w_word("近日请注意父亲节"); }
 268   1                              
 269   1              if ( month == 7 && date ==  1 ){ lcm_w_word("  七一党生日    "); }//7
 270   1              if ( month == 7 && date ==  7 ){ lcm_w_word("抗日战争纪念日  "); }
 271   1              if ( month == 7 && date == 11 ){ lcm_w_word("  世界人口日    "); }
 272   1        
 273   1              if ( month == 8 && date ==  1 ){ lcm_w_word("  八一建军节    "); }//8
 274   1              if ( month == 8 && date ==  8 ){ lcm_w_word("  中国男子节    "); }
 275   1              if ( month == 8 && date == 15 ){ lcm_w_word("抗战胜利纪念日  "); }
 276   1        
 277   1              if ( month == 9 && date == 10 ){ lcm_w_word("  中国教师节    "); }//9
 278   1              if ( month == 9 && date == 18 ){ lcm_w_word("九一八事变纪念日"); }
 279   1              if ( month == 9 && date == 20 ){ lcm_w_word("  国际爱牙日    "); }
 280   1              if ( month == 9 && date == 27 ){ lcm_w_word("  世界旅游日    "); }
 281   1      
 282   1              if ( month == 10 && date ==  1 ){ lcm_w_word("  中国国庆节    "); }//10
 283   1              if ( month == 10 && date ==  4 ){ lcm_w_word("  世界动物日    "); }
 284   1              if ( month == 10 && date == 24 ){ lcm_w_word("    联合国日    "); }
 285   1              if ( month == 10 && date == 12 ){ lcm_w_word("明天是国际教师节"); }
 286   1              if ( month == 10 && date == 13 ){ lcm_w_word("  国际教师节    "); }
 287   1      
 288   1              if ( month == 11 && date == 10 ){ lcm_w_word("  世界青年节    "); }//11
 289   1              if ( month == 11 && date == 17 ){ lcm_w_word("  世界学生节    "); }
 290   1      
 291   1              if ( month == 12 && date ==  1 ){ lcm_w_word("  世界艾滋病日  "); }//12
 292   1              if ( month == 12 && date == 23 ){ lcm_w_word("  明晚平安夜    "); }
 293   1              if ( month == 12 && date == 24 ){ lcm_w_word("  今晚平安夜    "); }
 294   1              if ( month == 12 && date == 25 ){ lcm_w_word("    圣诞快乐    "); }
 295   1              if ( month == 12 && date == 31 ){ lcm_w_word("    明日新年    "); }
 296   1              else{ 
 297   2                              if ( hour >=  4 && hour <   6 ){ lcm_w_word("★★__▲▲__凌晨"); }
 298   2                              if ( hour >=  6 && hour <   8 ){ lcm_w_word("☆○__▲△__早晨"); }
 299   2                              if ( hour >=  8 && hour <  12 ){ lcm_w_word("__●__▲▲__上午"); }
 300   2                              if ( hour == 12)               { lcm_w_word("____▲●▲__中午"); }
 301   2                              if ( hour >= 13 && hour <  18 ){ lcm_w_word("__▲▲__●__下午"); }
 302   2                              if ( hour >= 18 && hour <  22 ){ lcm_w_word("△▲__●☆__晚上"); }
 303   2                              if ( hour >= 22 && hour <= 23 ){ lcm_w_word("△▲__★☆__夜里"); }
C51 COMPILER V8.05a   DS12CR887MNL                                                         04/15/2009 21:34:52 PAGE 6   

 304   2                              if ( hour >= 0  && hour <   4 ){ lcm_w_word("__★▲▲★__深夜"); }
 305   2                      }
 306   1      }
 307          
 308          
 309          /*电子时钟在液晶屏上显示驱动程序---------------------------------------------*/
 310          
 311          //往液晶屏填写 年 数据
 312          void lcm_w_year(void)
 313          {
 314   1              year=ds_read(9);
 315   1              lcm_w_test(0,0x80);//在液晶屏上显示的位置
 316   1              lcm_w_word("现在时间是20");
 317   1              lcm_w_test(0,0x86);//在LCM上的写入位置
 318   1              lcm_w_test(1,(year/10)+0x30);   
 319   1              lcm_w_test(1,year%10+0x30);
 320   1              lcm_w_word("年");       
 321   1      }       
 322          
 323          //往液晶屏填写 月 数据
 324          void lcm_w_month(void)
 325          {
 326   1              month=ds_read(8);
 327   1              lcm_w_test(0,0x90);     //月份在液晶屏上显示的位置
 328   1              if(month/10 != 0){lcm_w_test(1,(month/10)+0x30);}       //十位消隐
 329   1                      else{lcm_w_test(1,0x20);}//十位消隐             
 330   1              lcm_w_test(1,month%10+0x30);
 331   1              lcm_w_test(0,0x91);//在LCM上的写入位置
 332   1              lcm_w_word("月");       
 333   1      }
 334          
 335          //将星期处理并送入液晶屏的指定区域显示
 336          void lcm_w_day(void)
 337          {
 338   1              uchar sel;
 339   1              day = ds_read(6);
 340   1              sel = ds_read(6); 
 341   1              lcm_w_test(0,0x97);//写入指定区域(97H 第二行第8个字)在液晶屏上显示的位置
 342   1              if(sel==7)  {lcm_w_word("日");}    
 343   1              if(sel==6)  {lcm_w_word("六");}    
 344   1              if(sel==5)  {lcm_w_word("五");}    
 345   1              if(sel==4)  {lcm_w_word("四");}   
 346   1              if(sel==3)  {lcm_w_word("三");}
 347   1              if(sel==2)  {lcm_w_word("二");}    
 348   1              if(sel==1)  {lcm_w_word("一");}    //星期一
 349   1              lcm_w_test(0,0x95);       //在LCM上的写入位置
 350   1              lcm_w_word("星期");
 351   1      }
 352          
 353          //往液晶屏填写 日 数据
 354          void lcm_w_date(void)
 355          {
 356   1              date=ds_read(7);
 357   1              lcm_w_test(0,0x92);     //日期在液晶屏上显示的位置
 358   1              if(date/10 != 0){lcm_w_test(1,(date/10)+0x30);} //十位消隐
 359   1                      else{lcm_w_test(1,0x20);}//十位消隐
 360   1              lcm_w_test(1,date%10+0x30);
 361   1              lcm_w_test(0,0x93);     //在LCM上的写入位置
 362   1              lcm_w_word("日");
 363   1                                              
 364   1      }
 365          
C51 COMPILER V8.05a   DS12CR887MNL                                                         04/15/2009 21:34:52 PAGE 7   

 366          //往液晶屏填写 小时 数据
 367          void lcm_w_hour(void)
 368          {
 369   1              hour=ds_read(4);//读取DS12CR887的小时
 370   1              lcm_w_test(0,0x88);     //小时在液晶屏上显示的位置
 371   1              lcm_w_test(1,(hour/10)+0x30);
 372   1              lcm_w_test(1,hour%10+0x30);                     
 373   1      }
 374          
 375          //往液晶屏填写 分钟 数据
 376          void lcm_w_min(void)
 377          {
 378   1              min=ds_read(2);//读取DS12CR887的分                              
 379   1              lcm_w_test(0,0x89);       //分钟在液晶屏上显示的位置
 380   1              lcm_w_test(1,0x3a);       //小时与分钟之间显示":"
 381   1              lcm_w_test(1,(min/10)+0x30);

⌨️ 快捷键说明

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