C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 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 sbit LED5=P1^7; 22 23 sbit key1 = P1^2; 24 sbit key2 = P1^3; 25 sbit key3 = P2^2; 26 sbit key4 = P2^7; 27 28 29 sbit IN = P3^7; 30 sbit OUT = P3^6; 31 32 sbit SCL1=P1^1; 33 sbit SDA1=P1^0; 34 35 int cut = 0; 36 37 int led_num = 0; 38 39 struct Time{ 40 int hour; 41 int min; 42 int sec; 43 }; 44 45 struct UserInfo{ 46 int num; 47 int model; 48 int set; 49 int start; 50 float Light; 51 int temp; 52 struct Time time[2]; 53 }; 54 55 struct UserInfo userInfo; C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 2 56 57 void LcdDisplay(); 58 void LcdDisplay1(); 59 void Delay10ms(void); 60 61 #define SlaveAddress 0x46 //定义器件在IIC总线中的从地址,根据ALT ADDRESS地址引脚不 -修改 62 //ALT ADDRESS引脚接地时地址为0x46,接电源时地址为0xB8 63 typedef unsigned char BYTE; 64 typedef unsigned short WORD; 65 66 BYTE BUF[8]; //接收数据缓存区 67 int dis_data; //变量 68 69 void delay_nms(unsigned int k); 70 void InitLcd(); 71 void Init_BH1750(void); 72 73 void WriteDataLCM(uchar dataW); 74 void WriteCommandLCM(uchar CMD,uchar Attribc); 75 void DisplayOneChar(uchar X,uchar Y,uchar DData); 76 void conversion(uint temp_data); 77 78 void Single_Write_BH1750(uchar REG_Address); //单个写入数据 79 uchar Single_Read_BH1750(uchar REG_Address); //单个读取内部寄存器数据 80 void Multiple_Read_BH1750(); //连续的读取内部寄存器数据 81 //------------------------------------ 82 void Delay5us(); 83 void Delay5ms(); 84 void BH1750_Start(); //起始信号 85 void BH1750_Stop(); //停止信号 86 void BH1750_SendACK(bit ack); //应答ACK 87 bit BH1750_RecvACK(); //读ack 88 void BH1750_SendByte(BYTE dat); //IIC单个字节写 89 BYTE BH1750_RecvByte(); //IIC单个字节读 90 91 92 //毫秒延时************************** 93 void delay_nms(unsigned int k) 94 { 95 1 unsigned int i,j; 96 1 for(i=0;i= 5) led_num = 0; 341 4 }else{ 342 4 if(userInfo.set == 0) userInfo.set = 1; 343 4 else userInfo.set = 0; 344 4 cut = 0; 345 4 } 346 3 LcdWriteCom(0x01); //清屏 347 3 } 348 2 while((i<50)&&(key2==0)){ 349 3 Delay10ms(); 350 3 i++; 351 3 } 352 2 i=0; 353 2 } 354 1 355 1 if(IN==0) // 光电门 进 356 1 { 357 2 Delay10ms(); 358 2 if(IN==0){ // 去抖 359 3 userInfo.num++; 360 3 if(userInfo.num > 99) userInfo.num = 99; 361 3 } 362 2 while((i<50)&&(IN==0)){ 363 3 Delay10ms(); 364 3 i++; C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 7 365 3 } 366 2 i=0; 367 2 } 368 1 369 1 370 1 if(OUT==0) // 光电门 出 371 1 { 372 2 Delay10ms(); 373 2 if(OUT==0){ // 去抖 374 3 userInfo.num--; 375 3 if(userInfo.num < 0) userInfo.num = 0; 376 3 } 377 2 while((i<50)&&(OUT==0)){ 378 3 Delay10ms(); 379 3 i++; 380 3 } 381 2 i=0; 382 2 } 383 1 384 1 385 1 if(key3==0) // 按键3 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 // 按键四 400 1 if(key4==0) 401 1 { 402 2 Delay10ms(); 403 2 if(key4==0){ 404 3 // 根据cut的值,修改不同的对象 405 3 if(cut == 0){ 406 4 userInfo.time[0].hour++; 407 4 if(userInfo.time[0].hour >= 24) userInfo.time[0].hour = 0; 408 4 }else if(cut == 1){ 409 4 userInfo.time[0].min++; 410 4 if(userInfo.time[0].min >= 59) userInfo.time[0].min = 0; 411 4 }else if(cut == 2){ 412 4 userInfo.time[1].hour++; 413 4 if(userInfo.time[1].hour >= 24) userInfo.time[1].hour = 0; 414 4 }else if(cut == 3){ 415 4 userInfo.time[1].min++; 416 4 if(userInfo.time[1].min >= 59) userInfo.time[1].min = 0; 417 4 } 418 3 while((i<50)&&(key4==0)){ 419 4 Delay10ms(); 420 4 i++; 421 4 } 422 3 i=0; 423 3 } 424 2 } 425 1 } *** WARNING C280 IN LINE 301 OF main.c: 'num': unreferenced local variable C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 8 426 427 428 // 获取时间是否达到 返回1为定时时间到 429 int getTimeResult() 430 { 431 1 int result = 1; 432 1 struct Time Nowtime; 433 1 434 1 Nowtime.hour = TIME[2]/16 * 10 + (TIME[2]&0x0f); 435 1 Nowtime.min = TIME[1]/16 * 10 + (TIME[1]&0x0f); 436 1 437 1 if(Nowtime.hour < userInfo.time[0].hour || Nowtime.hour > userInfo.time[1].hour) return 0; 438 1 if(Nowtime.hour == userInfo.time[0].hour && Nowtime.min < userInfo.time[0].min) return 0; 439 1 if(Nowtime.hour == userInfo.time[1].hour && Nowtime.min > userInfo.time[1].min) return 0; 440 1 441 1 return result; 442 1 } 443 444 445 // 点灯 446 void Dispose() 447 { 448 1 449 1 if(userInfo.model == 0){ 450 2 if(getTimeResult() && userInfo.Light < 100){ 451 3 if(userInfo.num < 10 && userInfo.num > 0) LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 1; 452 3 else if(userInfo.num >= 10 && userInfo.num < 20) LED0 = 0, LED1 = 0, LED2 = 1 ,LED3 = 1; 453 3 else if(userInfo.num >= 20 && userInfo.num < 30) LED0 = 0, LED1 = 1, LED2 = 1 ,LED3 = 1; 454 3 else if(userInfo.num >= 30) LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1; 455 3 else LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; 456 3 }else{ 457 3 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; 458 3 } 459 2 }else{ 460 2 if(led_num){ 461 3 if(led_num == 1) LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 1; 462 3 else if(led_num == 2) LED0 = 0, LED1 = 0, LED2 = 1 ,LED3 = 1; 463 3 else if(led_num == 3) LED0 = 0, LED1 = 1, LED2 = 1 ,LED3 = 1; 464 3 else if(led_num == 4) LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1; 465 3 }else{ 466 3 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; 467 3 } 468 2 } 469 1 LED4 = userInfo.model; 470 1 } 471 472 // main 473 void main() 474 { 475 1 int i = 0; 476 1 uchar str[10]; 477 1 Ds1302Init(); // 时钟初始化 478 1 Uart_Init(); 479 1 LcdInit(); // lcd初始化 480 1 481 1 userInfo.time[0].hour = 18; 482 1 userInfo.time[0].min = 0; 483 1 userInfo.time[0].sec = 0; 484 1 485 1 userInfo.time[1].hour = 23; 486 1 userInfo.time[1].min = 30; 487 1 userInfo.time[1].sec = 0; C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 9 488 1 489 1 while(1) 490 1 { 491 2 Ds1302ReadTime(); // 读取时间 492 2 LcdDisplay(); 493 2 Detection(); 494 2 Dispose(); 495 2 } 496 1 } *** WARNING C280 IN LINE 476 OF main.c: 'str': unreferenced local variable 497 498 // 显示 499 void LcdDisplay() 500 { 501 1 uint temp_data; 502 1 if(userInfo.set == 0){ 503 2 // TODO 显示时间 504 2 LcdWriteCom(0x80); 505 2 LcdWriteData('0'+TIME[4]/16); //月 506 2 LcdWriteData('0'+(TIME[4]&0x0f)); 507 2 LcdWriteData('-'); 508 2 LcdWriteData('0'+TIME[3]/16); //日 509 2 LcdWriteData('0'+(TIME[3]&0x0f)); 510 2 LcdWriteData(' '); 511 2 512 2 LcdWriteData('0'+TIME[2]/16); //时 513 2 LcdWriteData('0'+(TIME[2]&0x0f)); 514 2 LcdWriteData(':'); 515 2 LcdWriteData('0'+TIME[1]/16); //分 516 2 LcdWriteData('0'+(TIME[1]&0x0f)); 517 2 LcdWriteData(':'); 518 2 LcdWriteData('0'+TIME[0]/16); //秒 519 2 LcdWriteData('0'+(TIME[0]&0x0f)); 520 2 521 2 LcdWriteData(' '); 522 2 LcdWriteData('0'+(TIME[5]&0x0f)); 523 2 524 2 LcdWriteCom(0x80 + 0x40); 525 2 temp_data = userInfo.Light; 526 2 temp_data=temp_data%10000; 527 2 LcdWriteData(temp_data/1000+0x30); 528 2 temp_data=temp_data%1000; 529 2 LcdWriteData(temp_data/100+0x30); 530 2 temp_data=temp_data%100; 531 2 LcdWriteData(temp_data/10+0x30); 532 2 temp_data=temp_data%10; 533 2 LcdWriteData(temp_data+0x30); 534 2 LcdWriteData('L'); 535 2 LcdWriteData('x'); 536 2 LcdWriteData(' '); 537 2 LcdWriteData(userInfo.temp / 10 + 0x30); 538 2 LcdWriteData(userInfo.temp % 10 + 0x30); 539 2 LcdWriteData('C'); 540 2 541 2 LcdWriteData(' '); 542 2 LcdWriteData(userInfo.num / 10 % 10 + 0x30); 543 2 LcdWriteData(userInfo.num % 10 + 0x30); 544 2 }else{ 545 2 LcdWriteCom(0x80); 546 2 LcdWriteData('0'+ userInfo.time[0].hour/10); //时 547 2 LcdWriteData('0'+ userInfo.time[0].hour% 10); 548 2 LcdWriteData(':'); C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 10 549 2 LcdWriteData('0'+userInfo.time[0].min/10); //分 550 2 LcdWriteData('0'+ userInfo.time[0].min % 10); 551 2 LcdWriteData(':'); 552 2 LcdWriteData('0'+userInfo.time[0].sec / 10); //秒 553 2 LcdWriteData('0'+userInfo.time[0].sec % 10); 554 2 LcdWriteData(' '); 555 2 556 2 LcdWriteData('0'+cut); 557 2 558 2 LcdWriteCom(0x80 + 0x40); 559 2 LcdWriteData('0'+ userInfo.time[1].hour/10); //时 560 2 LcdWriteData('0'+ userInfo.time[1].hour% 10); 561 2 LcdWriteData(':'); 562 2 LcdWriteData('0'+userInfo.time[1].min/10); //分 563 2 LcdWriteData('0'+ userInfo.time[1].min % 10); 564 2 LcdWriteData(':'); 565 2 LcdWriteData('0'+userInfo.time[1].sec / 10); //秒 566 2 LcdWriteData('0'+userInfo.time[1].sec % 10); 567 2 } 568 1 } 569 570 571 void Delay10ms(void) //��� 0us 572 { 573 1 unsigned char a,b,c; 574 1 for(c=1;c>0;c--) 575 1 for(b=38;b>0;b--) 576 1 for(a=130;a>0;a--); 577 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 2049 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 42 22 IDATA SIZE = ---- ---- BIT SIZE = ---- 1 END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 2 WARNING(S), 0 ERROR(S)