|
|
C51 COMPILER V9.56.0.0 MAIN 04/09/2022 18:14:52 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 <reg51.h> |
|
|
2 #include <intrins.h> |
|
|
3 #include "lcd.h" |
|
|
4 #include "pwm.h" |
|
|
5 #include "i2c.h" |
|
|
6 #include "IRIN.h" |
|
|
7 #include <string.h> |
|
|
8 #include <stdio.h> |
|
|
9 # include <stdlib.h> |
|
|
10 |
|
|
11 #define uint unsigned int |
|
|
12 #define uchar unsigned char |
|
|
13 |
|
|
14 typedef unsigned char uint8; |
|
|
15 typedef unsigned int uint16; |
|
|
16 |
|
|
17 extern uint mileage; |
|
|
18 extern uint speed; |
|
|
19 |
|
|
20 uint Seep_model = 0; |
|
|
21 |
|
|
22 extern unsigned char pwm_value; |
|
|
23 |
|
|
24 uchar play = 0; |
|
|
25 |
|
|
26 // model |
|
|
27 uchar model = 0; |
|
|
28 |
|
|
29 struct UserInfo usr; |
|
|
30 |
|
|
31 uchar Receive; |
|
|
32 uchar Recive_table[40]; |
|
|
33 |
|
|
34 bit accept = 0; |
|
|
35 |
|
|
36 void delayms(unsigned int ms) |
|
|
37 { |
|
|
38 1 unsigned char i=100,j; |
|
|
39 1 for(;ms;ms--) |
|
|
40 1 { |
|
|
41 2 while(--i) |
|
|
42 2 { |
|
|
43 3 j=10; |
|
|
44 3 while(--j); |
|
|
45 3 } |
|
|
46 2 } |
|
|
47 1 } |
|
|
48 |
|
|
49 void Uart_Init() |
|
|
50 { |
|
|
51 1 TMOD = 0x20 | 0x01; |
|
|
52 1 SCON = 0x50; |
|
|
53 1 TH1 = 0xFD; |
|
|
54 1 TL1 = TH1; |
|
|
55 1 PCON = 0x00; |
|
|
C51 COMPILER V9.56.0.0 MAIN 04/09/2022 18:14:52 PAGE 2 |
|
|
|
|
|
56 1 EA = 1; |
|
|
57 1 ES = 1; |
|
|
58 1 TR1 = 1; |
|
|
59 1 } |
|
|
60 |
|
|
61 void us_delay(uchar t) |
|
|
62 { |
|
|
63 1 while(t--); |
|
|
64 1 } |
|
|
65 |
|
|
66 void Send_Uart(uchar value) |
|
|
67 { |
|
|
68 1 ES=0; |
|
|
69 1 TI=0; |
|
|
70 1 SBUF=value; |
|
|
71 1 while(TI==0); |
|
|
72 1 TI=0; |
|
|
73 1 ES=1; |
|
|
74 1 } |
|
|
75 |
|
|
76 void Bluetooth_Set(uchar *puf) |
|
|
77 { |
|
|
78 1 while(*puf!='\0') |
|
|
79 1 { |
|
|
80 2 Send_Uart(*puf); |
|
|
81 2 us_delay(5); |
|
|
82 2 puf++; |
|
|
83 2 } |
|
|
84 1 } |
|
|
85 |
|
|
86 // 保存用户的数据 |
|
|
87 void saveUserInfo(){ |
|
|
88 1 int target = 0; |
|
|
89 1 At24c02Write(3, usr.Seep_model); |
|
|
90 1 delayms(2); |
|
|
91 1 target = (usr.target_mileage) >> 8; |
|
|
92 1 At24c02Write(5, target); |
|
|
93 1 delayms(2); |
|
|
94 1 target = (usr.target_mileage) & 0x00ff; |
|
|
95 1 At24c02Write(6, target); |
|
|
96 1 delayms(2); |
|
|
97 1 } |
|
|
98 |
|
|
99 void Bluetooth_Accept(){ |
|
|
100 1 int target1 = 0, target2 = 0, i = 0; |
|
|
101 1 if(accept){ |
|
|
102 2 if(strstr(Recive_table, "inquire") != NULL){ |
|
|
103 3 memset(Recive_table, 0, sizeof(Recive_table)); |
|
|
104 3 sprintf(Recive_table, "speed:%d m/min mileage:%d m\r\n",speed, mileage); |
|
|
105 3 Bluetooth_Set(Recive_table); |
|
|
106 3 }else if(strstr(Recive_table, "model") != NULL){ |
|
|
107 3 if(model == 0) model = 1; |
|
|
108 3 else model = 0; |
|
|
109 3 if(model == 0) Seep_model = 0; |
|
|
110 3 memset(Recive_table, 0, sizeof(Recive_table)); |
|
|
111 3 sprintf(Recive_table, "Model SET OK\r\n"); |
|
|
112 3 Bluetooth_Set(Recive_table); |
|
|
113 3 At24c02Write(4, model); |
|
|
114 3 }else if(strstr(Recive_table, "clear") != NULL){ |
|
|
115 3 // 清空里程 |
|
|
116 3 mileage = 0; |
|
|
117 3 Bluetooth_Set("reset mileage OK!\r\n"); |
|
|
C51 COMPILER V9.56.0.0 MAIN 04/09/2022 18:14:52 PAGE 3 |
|
|
|
|
|
118 3 } |
|
|
119 2 else if(strstr(Recive_table, "speed") != NULL){ |
|
|
120 3 Seep_model++; |
|
|
121 3 if(Seep_model >= 4) Seep_model = 0; |
|
|
122 3 usr.Seep_model = Seep_model; |
|
|
123 3 } |
|
|
124 2 else if(strstr(Recive_table, "set:") != NULL){ |
|
|
125 3 target1 = strstr(Recive_table, "(") - Recive_table; |
|
|
126 3 target2 = strstr(Recive_table, ",") - Recive_table; |
|
|
127 3 usr.Seep_model = 0; |
|
|
128 3 for(i = target1 + 1; i < target2; i++){ |
|
|
129 4 usr.Seep_model = usr.Seep_model * 10 + (*(Recive_table + i) - 0x30); |
|
|
130 4 } |
|
|
131 3 if(usr.Seep_model > 1) usr.Seep_model = 1; |
|
|
132 3 target1 = strstr(Recive_table, ",") - Recive_table; |
|
|
133 3 target2 = strstr(Recive_table, ")") - Recive_table; |
|
|
134 3 usr.target_mileage = 0; |
|
|
135 3 for(i = target1 + 1; i < target2; i++){ |
|
|
136 4 usr.target_mileage = usr.target_mileage * 10 + (*(Recive_table + i) - 0x30); |
|
|
137 4 } |
|
|
138 3 |
|
|
139 3 if(usr.Seep_model > 9999) usr.Seep_model = 9999; |
|
|
140 3 Bluetooth_Set("User SET OK!\r\n"); |
|
|
141 3 saveUserInfo(); |
|
|
142 3 } |
|
|
143 2 memset(Recive_table, 0, sizeof(Recive_table)); |
|
|
144 2 accept = 0; |
|
|
145 2 } |
|
|
146 1 } |
|
|
147 |
|
|
148 // 读取数据 |
|
|
149 void ReadData(){ |
|
|
150 1 // 里程 |
|
|
151 1 mileage = At24c02Read(1) * 255 + At24c02Read(2); |
|
|
152 1 |
|
|
153 1 // 用户的模式 |
|
|
154 1 usr.Seep_model = At24c02Read(3); |
|
|
155 1 |
|
|
156 1 model = At24c02Read(4); |
|
|
157 1 // 用户的目标里程 |
|
|
158 1 usr.target_mileage = At24c02Read(5) * 255 + At24c02Read(6); |
|
|
159 1 } |
|
|
160 |
|
|
161 // 写入数据 |
|
|
162 void WriteData(){ |
|
|
163 1 int target = mileage >> 8; |
|
|
164 1 At24c02Write(1, target); |
|
|
165 1 us_delay(200); |
|
|
166 1 target = mileage & 0x00ff; |
|
|
167 1 At24c02Write(2, target); |
|
|
168 1 us_delay(200); |
|
|
169 1 } |
|
|
170 |
|
|
171 // main 函数 |
|
|
172 void main(void) |
|
|
173 { |
|
|
174 1 LcdInit(); |
|
|
175 1 IRIN_Init(); |
|
|
176 1 Uart_Init(); |
|
|
177 1 ReadData(); |
|
|
178 1 while(1) |
|
|
179 1 { |
|
|
C51 COMPILER V9.56.0.0 MAIN 04/09/2022 18:14:52 PAGE 4 |
|
|
|
|
|
180 2 run(); |
|
|
181 2 display(); |
|
|
182 2 Key_scan(); |
|
|
*** WARNING C206 IN LINE 182 OF main.c: 'Key_scan': missing function-prototype |
|
|
183 2 Bluetooth_Accept(); |
|
|
184 2 WriteData(); |
|
|
185 2 } |
|
|
186 1 } |
|
|
187 |
|
|
188 // 串口中断 |
|
|
189 void Uart_Interrupt() interrupt 4 |
|
|
190 { |
|
|
191 1 static uchar i=0; |
|
|
192 1 if(accept) return; |
|
|
193 1 if(RI==1) { |
|
|
194 2 RI=0; |
|
|
195 2 Receive=SBUF; |
|
|
196 2 Recive_table[i]=Receive; |
|
|
197 2 if((Recive_table[i]=='\r')){ |
|
|
198 3 i=0; |
|
|
199 3 accept = 1; |
|
|
200 3 } |
|
|
201 2 else i++; |
|
|
202 2 } |
|
|
203 1 else TI=0; |
|
|
204 1 } |
|
|
|
|
|
|
|
|
MODULE INFORMATION: STATIC OVERLAYABLE |
|
|
CODE SIZE = 1004 ---- |
|
|
CONSTANT SIZE = 117 ---- |
|
|
XDATA SIZE = ---- ---- |
|
|
PDATA SIZE = ---- ---- |
|
|
DATA SIZE = 52 6 |
|
|
IDATA SIZE = ---- ---- |
|
|
BIT SIZE = 1 ---- |
|
|
END OF MODULE INFORMATION. |
|
|
|
|
|
|
|
|
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
|
|
|
|