C51 COMPILER V9.56.0.0 MAIN 04/29/2022 01:22:41 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 6 #include 7 8 sbit LED0=P0^2; 9 sbit LED1=P0^1; 10 sbit LED2=P0^0; 11 sbit LED3=P0^4; 12 13 sbit LED4=P0^3; 14 15 sbit key1 = P1^2; 16 sbit key2 = P1^3; 17 18 sbit IN = P3^7; 19 sbit OUT = P3^6; 20 21 struct UserInfo{ 22 int num; 23 int model; 24 int start; 25 int Light; 26 }; 27 28 struct UserInfo userInfo; 29 30 void LcdDisplay(); 31 void LcdDisplay1(); 32 void Delay10ms(void); 33 34 void Uart_Init() 35 { 36 1 TMOD = 0x20 | 0x01; 37 1 SCON = 0x50; 38 1 TH1 = 0xFD; 39 1 TL1 = TH1; 40 1 PCON = 0x00; 41 1 EA = 1; 42 1 ES = 1; 43 1 TR1 = 1; 44 1 } 45 46 void us_delay(uchar t) 47 { 48 1 while(t--); 49 1 } 50 51 void Send_Uart(uchar value) 52 { 53 1 ES=0; 54 1 TI=0; 55 1 SBUF=value; C51 COMPILER V9.56.0.0 MAIN 04/29/2022 01:22:41 PAGE 2 56 1 while(TI==0); 57 1 TI=0; 58 1 ES=1; 59 1 } 60 61 void Bluetooth_Set(uchar *puf) 62 { 63 1 while(*puf!='\0') 64 1 { 65 2 Send_Uart(*puf); 66 2 us_delay(5); 67 2 puf++; 68 2 } 69 1 } 70 71 void Detection() 72 { 73 1 int i = 0; 74 1 if(key1==0) //��ⰴ��K1�Ƿ��� 75 1 { 76 2 Delay10ms(); //�������� 77 2 if(key1==0){ 78 3 if(userInfo.model == 0) userInfo.model = 1; 79 3 else userInfo.model = 0; 80 3 } 81 2 while((i<50)&&(key1==0)){ 82 3 Delay10ms(); 83 3 i++; 84 3 } 85 2 i=0; 86 2 } 87 1 88 1 if(key2==0) //��ⰴ��K1�Ƿ��� 89 1 { 90 2 Delay10ms(); //�������� 91 2 if(key2==0){ 92 3 if(userInfo.start == 0) userInfo.start = 1; 93 3 else userInfo.start = 0; 94 3 } 95 2 while((i<50)&&(key2==0)){ 96 3 Delay10ms(); 97 3 i++; 98 3 } 99 2 i=0; 100 2 } 101 1 102 1 if(IN==0) //��ⰴ��K1�Ƿ��� 103 1 { 104 2 Delay10ms(); //�������� 105 2 if(IN==0){ 106 3 userInfo.num++; 107 3 if(userInfo.num > 99) userInfo.num = 99; 108 3 } 109 2 while((i<50)&&(IN==0)){ 110 3 Delay10ms(); 111 3 i++; 112 3 } 113 2 i=0; 114 2 } 115 1 116 1 if(OUT==0) //��ⰴ��K1�Ƿ��� 117 1 { C51 COMPILER V9.56.0.0 MAIN 04/29/2022 01:22:41 PAGE 3 118 2 Delay10ms(); //�������� 119 2 if(OUT==0){ 120 3 userInfo.num--; 121 3 if(userInfo.num < 0) userInfo.num = 0; 122 3 } 123 2 while((i<50)&&(OUT==0)){ 124 3 Delay10ms(); 125 3 i++; 126 3 } 127 2 i=0; 128 2 } 129 1 } 130 131 void Dispose() 132 { 133 1 if(userInfo.start && userInfo.model){ 134 2 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; 135 2 }else{ 136 2 if(userInfo.Light < 50 && userInfo.model == 0){ 137 3 if(userInfo.num < 10 && userInfo.num > 0) LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 1; 138 3 else if(userInfo.num >= 10 && userInfo.num < 20) LED0 = 0, LED1 = 0, LED2 = 1 ,LED3 = 1; 139 3 else if(userInfo.num >= 20 && userInfo.num < 30) LED0 = 0, LED1 = 1, LED2 = 1 ,LED3 = 1; 140 3 else if(userInfo.num >= 30) LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1; 141 3 else LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; 142 3 } 143 2 } 144 1 LED4 = userInfo.model; 145 1 } 146 147 void main() 148 { 149 1 int i = 0; 150 1 uchar str[30]; 151 1 LcdInit(); 152 1 Ds1302Init(); 153 1 Uart_Init(); 154 1 while(1) 155 1 { 156 2 Ds1302ReadTime(); 157 2 LcdDisplay(); 158 2 Detection(); 159 2 sprintf(str, "%d\r\n", userInfo.model); 160 2 Bluetooth_Set(str); 161 2 Dispose(); 162 2 } 163 1 } 164 165 166 void LcdDisplay() 167 { 168 1 // TODO 显示时间 169 1 LcdWriteCom(0x80); 170 1 LcdWriteData('m'); 171 1 } 172 173 174 void Delay10ms(void) //��� 0us 175 { 176 1 unsigned char a,b,c; 177 1 for(c=1;c>0;c--) 178 1 for(b=38;b>0;b--) 179 1 for(a=130;a>0;a--); C51 COMPILER V9.56.0.0 MAIN 04/29/2022 01:22:41 PAGE 4 180 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 589 ---- CONSTANT SIZE = 5 ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 8 34 IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)