C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 1 C51 COMPILER V9.56.0.0, COMPILATION OF MODULE MAIN OBJECT MODULE PLACED IN main.OBJ COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE main.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND TABS(2) line level source 1 #include 2 #include"lcd.h" 3 #include"ds1302.h" 4 #include"i2c.h" 5 #include "DS18B20.h" 6 7 #include 8 #include 9 10 11 #define uchar unsigned char 12 #define uint unsigned int 13 14 sbit LED0=P2^5; 15 sbit LED1=P2^6; 16 sbit LED2=P2^1; 17 18 sbit LED3=P2^4; 19 20 sbit LED4=P2^3; 21 22 sbit key1 = P1^2; 23 sbit key2 = P1^3; 24 sbit key3 = P2^2; 25 sbit key4 = P2^7; 26 27 28 sbit IN = P3^7; 29 sbit OUT = P3^6; 30 31 sbit SCL1=P1^1; 32 sbit SDA1=P1^0; 33 34 int cut = 0; 35 36 struct Time{ 37 int hour; 38 int min; 39 int sec; 40 }; 41 42 struct UserInfo{ 43 int num; 44 int model; 45 int set; 46 int start; 47 float Light; 48 int temp; 49 struct Time time[2]; 50 }; 51 52 struct UserInfo userInfo; 53 54 void LcdDisplay(); 55 void LcdDisplay1(); C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 2 56 void Delay10ms(void); 57 58 #define SlaveAddress 0x46 //¶¨ÒåÆ÷¼þÔÚIIC×ÜÏßÖеĴӵØÖ·,¸ù¾ÝALT ADDRESSµ -ØÖ·Òý½Å²»Í¬ÐÞ¸Ä 59 //ALT ADDRESSÒý½Å½ÓµØʱµØַΪ0x46£¬½ÓµçԴʱµØÖ -·Îª0xB8 60 typedef unsigned char BYTE; 61 typedef unsigned short WORD; 62 63 BYTE BUF[8]; //½ÓÊÕÊý¾Ý»º´æÇø 64 int dis_data; //±äÁ¿ 65 66 void delay_nms(unsigned int k); 67 void InitLcd(); 68 void Init_BH1750(void); 69 70 void WriteDataLCM(uchar dataW); 71 void WriteCommandLCM(uchar CMD,uchar Attribc); 72 void DisplayOneChar(uchar X,uchar Y,uchar DData); 73 void conversion(uint temp_data); 74 75 void Single_Write_BH1750(uchar REG_Address); //µ¥¸öдÈëÊý¾Ý 76 uchar Single_Read_BH1750(uchar REG_Address); //µ¥¸ö¶ÁÈ¡ÄÚ²¿¼Ä´æÆ÷Êý¾Ý 77 void Multiple_Read_BH1750(); //Á¬ÐøµÄ¶ÁÈ¡ÄÚ²¿¼Ä´æÆ÷Êý -¾Ý 78 //------------------------------------ 79 void Delay5us(); 80 void Delay5ms(); 81 void BH1750_Start(); //ÆðʼÐźŠ82 void BH1750_Stop(); //Í£Ö¹ÐźŠ83 void BH1750_SendACK(bit ack); //Ó¦´ðACK 84 bit BH1750_RecvACK(); //¶Áack 85 void BH1750_SendByte(BYTE dat); //IICµ¥¸ö×Ö½Úд 86 BYTE BH1750_RecvByte(); //IICµ¥¸ö×Ö½Ú¶Á 87 88 89 //ºÁÃëÑÓʱ************************** 90 void delay_nms(unsigned int k) 91 { 92 1 unsigned int i,j; 93 1 for(i=0;i 99) userInfo.num = 99; C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 7 363 3 } 364 2 while((i<50)&&(IN==0)){ 365 3 Delay10ms(); 366 3 i++; 367 3 } 368 2 i=0; 369 2 } 370 1 371 1 if(OUT==0) //��ⰴ��K1�Ƿ��� 372 1 { 373 2 Delay10ms(); //�������� 374 2 if(OUT==0){ 375 3 userInfo.num--; 376 3 if(userInfo.num < 0) userInfo.num = 0; 377 3 } 378 2 while((i<50)&&(OUT==0)){ 379 3 Delay10ms(); 380 3 i++; 381 3 } 382 2 i=0; 383 2 } 384 1 385 1 if(key3==0) //��ⰴ��K1�Ƿ��� 386 1 { 387 2 Delay10ms(); //�������� 388 2 if(key3==0){ 389 3 cut++; 390 3 if(cut >= 4) cut = 0; 391 3 } 392 2 while((i<50)&&(key3==0)){ 393 3 Delay10ms(); 394 3 i++; 395 3 } 396 2 i=0; 397 2 } 398 1 399 1 if(key4==0) //��ⰴ��K1�Ƿ��� 400 1 { 401 2 Delay10ms(); //�������� 402 2 if(key4==0){ 403 3 if(cut == 0){ 404 4 userInfo.time[0].hour++; 405 4 if(userInfo.time[0].hour >= 24) userInfo.time[0].hour = 0; 406 4 }else if(cut == 1){ 407 4 userInfo.time[0].min++; 408 4 if(userInfo.time[0].min >= 59) userInfo.time[0].min = 0; 409 4 }else if(cut == 2){ 410 4 userInfo.time[1].hour++; 411 4 if(userInfo.time[1].hour >= 24) userInfo.time[1].hour = 0; 412 4 }else if(cut == 3){ 413 4 userInfo.time[1].min++; 414 4 if(userInfo.time[1].min >= 59) userInfo.time[1].min = 0; 415 4 } 416 3 while((i<50)&&(key4==0)){ 417 4 Delay10ms(); 418 4 i++; 419 4 } 420 3 i=0; 421 3 } 422 2 } 423 1 } 424 C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 8 425 426 int getTimeResult() 427 { 428 1 int result = 1; 429 1 struct Time Nowtime; 430 1 431 1 Nowtime.hour = TIME[2]/16 * 10 + (TIME[2]&0x0f); 432 1 Nowtime.min = TIME[1]/16 * 10 + (TIME[1]&0x0f); 433 1 434 1 if(Nowtime.hour < userInfo.time[0].hour || Nowtime.hour > userInfo.time[1].hour) return 0; 435 1 if(Nowtime.hour == userInfo.time[0].hour && Nowtime.min < userInfo.time[0].min) return 0; 436 1 if(Nowtime.hour == userInfo.time[1].hour && Nowtime.min > userInfo.time[1].min) return 0; 437 1 438 1 return result; 439 1 } 440 441 442 void Dispose() 443 { 444 1 445 1 if(userInfo.model == 0){ 446 2 if(getTimeResult() && userInfo.Light < 100){ 447 3 if(userInfo.num < 10 && userInfo.num > 0) LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 1; 448 3 else if(userInfo.num >= 10 && userInfo.num < 20) LED0 = 0, LED1 = 0, LED2 = 1 ,LED3 = 1; 449 3 else if(userInfo.num >= 20 && userInfo.num < 30) LED0 = 0, LED1 = 1, LED2 = 1 ,LED3 = 1; 450 3 else if(userInfo.num >= 30) LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1; 451 3 else LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; 452 3 }else{ 453 3 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; 454 3 } 455 2 }else{ 456 2 if(userInfo.start){ 457 3 LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1; 458 3 }else{ 459 3 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; 460 3 } 461 2 } 462 1 LED4 = userInfo.model; 463 1 } 464 465 void main() 466 { 467 1 int i = 0; 468 1 uchar str[10]; 469 1 Ds1302Init(); 470 1 Uart_Init(); 471 1 LcdInit(); 472 1 473 1 userInfo.time[0].hour = 18; 474 1 userInfo.time[0].min = 0; 475 1 userInfo.time[0].sec = 0; 476 1 477 1 userInfo.time[1].hour = 23; 478 1 userInfo.time[1].min = 30; 479 1 userInfo.time[1].sec = 0; 480 1 481 1 while(1) 482 1 { 483 2 Ds1302ReadTime(); 484 2 LcdDisplay(); 485 2 Detection(); 486 2 Dispose(); C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 9 487 2 sprintf(str, "%d\r\n", userInfo.temp); 488 2 Bluetooth_Set(str); 489 2 } 490 1 } 491 492 void LcdDisplay() 493 { 494 1 uint temp_data; 495 1 if(userInfo.set == 0){ 496 2 // TODO 显示时间 497 2 LcdWriteCom(0x80); 498 2 LcdWriteData('0'+TIME[4]/16); //月 499 2 LcdWriteData('0'+(TIME[4]&0x0f)); 500 2 LcdWriteData('-'); 501 2 LcdWriteData('0'+TIME[3]/16); //日 502 2 LcdWriteData('0'+(TIME[3]&0x0f)); 503 2 LcdWriteData(' '); 504 2 505 2 LcdWriteData('0'+TIME[2]/16); //时 506 2 LcdWriteData('0'+(TIME[2]&0x0f)); 507 2 LcdWriteData(':'); 508 2 LcdWriteData('0'+TIME[1]/16); //分 509 2 LcdWriteData('0'+(TIME[1]&0x0f)); 510 2 LcdWriteData(':'); 511 2 LcdWriteData('0'+TIME[0]/16); //秒 512 2 LcdWriteData('0'+(TIME[0]&0x0f)); 513 2 514 2 LcdWriteData(' '); 515 2 LcdWriteData('0'+(TIME[5]&0x0f)); 516 2 517 2 LcdWriteCom(0x80 + 0x40); 518 2 temp_data = userInfo.Light; 519 2 temp_data=temp_data%10000; 520 2 LcdWriteData(temp_data/1000+0x30); 521 2 temp_data=temp_data%1000; 522 2 LcdWriteData(temp_data/100+0x30); 523 2 temp_data=temp_data%100; 524 2 LcdWriteData(temp_data/10+0x30); 525 2 temp_data=temp_data%10; 526 2 LcdWriteData(temp_data+0x30); 527 2 LcdWriteData('L'); 528 2 LcdWriteData('x'); 529 2 LcdWriteData(' '); 530 2 LcdWriteData(userInfo.temp / 10 + 0x30); 531 2 LcdWriteData(userInfo.temp % 10 + 0x30); 532 2 LcdWriteData('C'); 533 2 534 2 LcdWriteData(' '); 535 2 LcdWriteData(userInfo.num / 10 % 10 + 0x30); 536 2 LcdWriteData(userInfo.num % 10 + 0x30); 537 2 }else{ 538 2 LcdWriteCom(0x80); 539 2 LcdWriteData('0'+ userInfo.time[0].hour/10); //时 540 2 LcdWriteData('0'+ userInfo.time[0].hour% 10); 541 2 LcdWriteData(':'); 542 2 LcdWriteData('0'+userInfo.time[0].min/10); //分 543 2 LcdWriteData('0'+ userInfo.time[0].min % 10); 544 2 LcdWriteData(':'); 545 2 LcdWriteData('0'+userInfo.time[0].sec / 10); //秒 546 2 LcdWriteData('0'+userInfo.time[0].sec % 10); 547 2 LcdWriteData(' '); 548 2 C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 10 549 2 LcdWriteData('0'+cut); 550 2 551 2 LcdWriteCom(0x80 + 0x40); 552 2 LcdWriteData('0'+ userInfo.time[1].hour/10); //时 553 2 LcdWriteData('0'+ userInfo.time[1].hour% 10); 554 2 LcdWriteData(':'); 555 2 LcdWriteData('0'+userInfo.time[1].min/10); //分 556 2 LcdWriteData('0'+ userInfo.time[1].min % 10); 557 2 LcdWriteData(':'); 558 2 LcdWriteData('0'+userInfo.time[1].sec / 10); //秒 559 2 LcdWriteData('0'+userInfo.time[1].sec % 10); 560 2 } 561 1 } 562 563 564 void Delay10ms(void) //��� 0us 565 { 566 1 unsigned char a,b,c; 567 1 for(c=1;c>0;c--) 568 1 for(b=38;b>0;b--) 569 1 for(a=130;a>0;a--); 570 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 2027 ---- CONSTANT SIZE = 5 ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 38 22 IDATA SIZE = ---- ---- BIT SIZE = ---- 1 END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)