|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 04/08/2022 03:21:37 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 model = 0;
|
|
|
|
|
21
|
|
|
|
|
22 extern unsigned char pwm_value;
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
|
|
25 struct UserInfo{
|
|
|
|
|
26 int height;
|
|
|
|
|
27 int weight;
|
|
|
|
|
28 int target_mileage;
|
|
|
|
|
29 int target_speed;
|
|
|
|
|
30 };
|
|
|
|
|
31
|
|
|
|
|
32 uchar set = 0;
|
|
|
|
|
33
|
|
|
|
|
34 struct UserInfo usr;
|
|
|
|
|
35
|
|
|
|
|
36 /*****************<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD>**************/
|
|
|
|
|
37
|
|
|
|
|
38 uchar Receive;
|
|
|
|
|
39 uchar Recive_table[40]; //<EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD>wifiģ<EFBFBD>鷴<EFBFBD><EFBFBD><EFBFBD><EFBFBD>MCU<EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
40
|
|
|
|
|
41 bit accept = 0;
|
|
|
|
|
42
|
|
|
|
|
43 void delayms(unsigned int ms)
|
|
|
|
|
44 {
|
|
|
|
|
45 1 unsigned char i=100,j;
|
|
|
|
|
46 1 for(;ms;ms--)
|
|
|
|
|
47 1 {
|
|
|
|
|
48 2 while(--i)
|
|
|
|
|
49 2 {
|
|
|
|
|
50 3 j=10;
|
|
|
|
|
51 3 while(--j);
|
|
|
|
|
52 3 }
|
|
|
|
|
53 2 }
|
|
|
|
|
54 1 }
|
|
|
|
|
55
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 04/08/2022 03:21:37 PAGE 2
|
|
|
|
|
|
|
|
|
|
56 void Uart_Init()
|
|
|
|
|
57 {
|
|
|
|
|
58 1 TMOD = 0x20 | 0x01;
|
|
|
|
|
59 1 SCON = 0x50;
|
|
|
|
|
60 1 TH1 = 0xFD;
|
|
|
|
|
61 1 TL1 = TH1;
|
|
|
|
|
62 1 PCON = 0x00;
|
|
|
|
|
63 1 EA = 1;
|
|
|
|
|
64 1 ES = 1;
|
|
|
|
|
65 1 TR1 = 1;
|
|
|
|
|
66 1 }
|
|
|
|
|
67
|
|
|
|
|
68 void us_delay(uchar t)
|
|
|
|
|
69 {
|
|
|
|
|
70 1 while(t--);
|
|
|
|
|
71 1 }
|
|
|
|
|
72
|
|
|
|
|
73 void Send_Uart(uchar value)
|
|
|
|
|
74 {
|
|
|
|
|
75 1 ES=0;
|
|
|
|
|
76 1 TI=0;
|
|
|
|
|
77 1 SBUF=value;
|
|
|
|
|
78 1 while(TI==0);
|
|
|
|
|
79 1 TI=0;
|
|
|
|
|
80 1 ES=1;
|
|
|
|
|
81 1 }
|
|
|
|
|
82
|
|
|
|
|
83 void Bluetooth_Set(uchar *puf)
|
|
|
|
|
84 {
|
|
|
|
|
85 1 while(*puf!='\0')
|
|
|
|
|
86 1 {
|
|
|
|
|
87 2 Send_Uart(*puf);
|
|
|
|
|
88 2 us_delay(5);
|
|
|
|
|
89 2 puf++;
|
|
|
|
|
90 2 }
|
|
|
|
|
91 1 }
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
|
|
94 void saveUserInfo(){
|
|
|
|
|
95 1 int target = 0;
|
|
|
|
|
96 1 target = usr.height >> 8;
|
|
|
|
|
97 1 At24c02Write(3, target);
|
|
|
|
|
98 1 delayms(2);
|
|
|
|
|
99 1 target = (usr.height) & 0x00ff;
|
|
|
|
|
100 1 At24c02Write(4, target);
|
|
|
|
|
101 1 delayms(2);
|
|
|
|
|
102 1 target = (usr.weight) >> 8;
|
|
|
|
|
103 1 At24c02Write(5, target);
|
|
|
|
|
104 1 delayms(2);
|
|
|
|
|
105 1 target = (usr.weight) & 0x00ff;
|
|
|
|
|
106 1 At24c02Write(6, target);
|
|
|
|
|
107 1 delayms(2);
|
|
|
|
|
108 1 }
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
|
|
111 void Bluetooth_Accept(){
|
|
|
|
|
112 1 int target1 = 0, target2 = 0, i = 0;
|
|
|
|
|
113 1 if(accept){
|
|
|
|
|
114 2 if(strstr(Recive_table, "inquire") != NULL){
|
|
|
|
|
115 3 memset(Recive_table, 0, sizeof(Recive_table));
|
|
|
|
|
116 3 sprintf(Recive_table, "speed:%d km/h mileage:%d m\r\n",speed, mileage);
|
|
|
|
|
117 3 Bluetooth_Set(Recive_table);
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 04/08/2022 03:21:37 PAGE 3
|
|
|
|
|
|
|
|
|
|
118 3 }else if(strstr(Recive_table, "set:") != NULL){
|
|
|
|
|
119 3 target1 = strstr(Recive_table, "(") - Recive_table;
|
|
|
|
|
120 3 target2 = strstr(Recive_table, ",") - Recive_table;
|
|
|
|
|
121 3 usr.height = 0;
|
|
|
|
|
122 3 for(i = target1 + 1; i < target2; i++){
|
|
|
|
|
123 4 usr.height = usr.height * 10 + (*(Recive_table + i) - 0x30);
|
|
|
|
|
124 4 }
|
|
|
|
|
125 3 Bluetooth_Set(Recive_table);
|
|
|
|
|
126 3 target1 = strstr(Recive_table, ",") - Recive_table;
|
|
|
|
|
127 3 target2 = strstr(Recive_table, ")") - Recive_table;
|
|
|
|
|
128 3 usr.weight = 0;
|
|
|
|
|
129 3 for(i = target1 + 1; i < target2; i++){
|
|
|
|
|
130 4 usr.weight = usr.weight * 10 + (*(Recive_table + i) - 0x30);
|
|
|
|
|
131 4 }
|
|
|
|
|
132 3 memset(Recive_table, 0, sizeof(Recive_table));
|
|
|
|
|
133 3 sprintf(Recive_table, "SET OK\r\n",usr.height, usr.weight);
|
|
|
|
|
134 3 Bluetooth_Set(Recive_table);
|
|
|
|
|
135 3
|
|
|
|
|
136 3 // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
137 3 usr.target_mileage = (usr.weight / usr.height) * (usr.weight / usr.height) / 22 * 3000;
|
|
|
|
|
138 3 usr.target_speed = 10 - (usr.weight / usr.height) * (usr.weight / usr.height) / 22 ;
|
|
|
|
|
139 3 saveUserInfo();
|
|
|
|
|
140 3 }
|
|
|
|
|
141 2 memset(Recive_table, 0, sizeof(Recive_table));
|
|
|
|
|
142 2 accept = 0;
|
|
|
|
|
143 2 }
|
|
|
|
|
144 1 }
|
|
|
|
|
145
|
|
|
|
|
146 void ReadData(){
|
|
|
|
|
147 1 mileage = At24c02Read(1) * 255 + At24c02Read(2);
|
|
|
|
|
148 1 set = At24c02Read(7);
|
|
|
|
|
149 1 if(set){
|
|
|
|
|
150 2 usr.height = 0;
|
|
|
|
|
151 2 usr.weight = 0;
|
|
|
|
|
152 2
|
|
|
|
|
153 2 At24c02Write(1, 0);
|
|
|
|
|
154 2 delayms(2);
|
|
|
|
|
155 2 At24c02Write(2, 0);
|
|
|
|
|
156 2 delayms(2);
|
|
|
|
|
157 2
|
|
|
|
|
158 2 At24c02Write(3, 0);
|
|
|
|
|
159 2 delayms(2);
|
|
|
|
|
160 2 At24c02Write(4, 0);
|
|
|
|
|
161 2 delayms(2);
|
|
|
|
|
162 2 At24c02Write(5, 0);
|
|
|
|
|
163 2 delayms(2);
|
|
|
|
|
164 2 At24c02Write(6, 0);
|
|
|
|
|
165 2
|
|
|
|
|
166 2 }else{
|
|
|
|
|
167 2 usr.height = At24c02Read(3) * 255 + At24c02Read(4);
|
|
|
|
|
168 2 usr.weight = At24c02Read(5) * 255 + At24c02Read(6);
|
|
|
|
|
169 2 }
|
|
|
|
|
170 1 }
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
|
|
176 void WriteData(){
|
|
|
|
|
177 1 int target = mileage >> 8;
|
|
|
|
|
178 1 At24c02Write(1, target);
|
|
|
|
|
179 1 delayms(2);
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 04/08/2022 03:21:37 PAGE 4
|
|
|
|
|
|
|
|
|
|
180 1 target = mileage & 0x00ff;
|
|
|
|
|
181 1 At24c02Write(2, target);
|
|
|
|
|
182 1 delayms(2);
|
|
|
|
|
183 1 }
|
|
|
|
|
184
|
|
|
|
|
185 void main(void)
|
|
|
|
|
186 {
|
|
|
|
|
187 1 InitLcd1602();
|
|
|
|
|
188 1 IRIN_Init();
|
|
|
|
|
189 1 Uart_Init();
|
|
|
|
|
190 1 ReadData();
|
|
|
|
|
191 1 while(1)
|
|
|
|
|
192 1 {
|
|
|
|
|
193 2 run();
|
|
|
|
|
194 2 display();
|
|
|
|
|
195 2 Key_scan();
|
|
|
|
|
*** WARNING C206 IN LINE 195 OF main.c: 'Key_scan': missing function-prototype
|
|
|
|
|
196 2 Bluetooth_Accept();
|
|
|
|
|
197 2 WriteData();
|
|
|
|
|
198 2 }
|
|
|
|
|
199 1 }
|
|
|
|
|
200
|
|
|
|
|
201 void Uart_Interrupt() interrupt 4
|
|
|
|
|
202 {
|
|
|
|
|
203 1 static uchar i=0;
|
|
|
|
|
204 1 if( accept) return;
|
|
|
|
|
205 1 if(RI==1) {
|
|
|
|
|
206 2 RI=0;
|
|
|
|
|
207 2 Receive=SBUF; //MCU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>wifiģ<EFBFBD>鷴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
-
|
|
|
|
|
208 2 Recive_table[i]=Receive;
|
|
|
|
|
209 2 if((Recive_table[i]=='\r')){
|
|
|
|
|
210 3 i=0;
|
|
|
|
|
211 3 accept = 1;
|
|
|
|
|
212 3 }
|
|
|
|
|
213 2 else i++; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|
|
|
|
-<EFBFBD><EFBFBD>װֵ
|
|
|
|
|
214 2 }
|
|
|
|
|
215 1 else TI=0;
|
|
|
|
|
216 1 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MODULE INFORMATION: STATIC OVERLAYABLE
|
|
|
|
|
CODE SIZE = 1000 ----
|
|
|
|
|
CONSTANT SIZE = 57 ----
|
|
|
|
|
XDATA SIZE = ---- ----
|
|
|
|
|
PDATA SIZE = ---- ----
|
|
|
|
|
DATA SIZE = 53 6
|
|
|
|
|
IDATA SIZE = ---- ----
|
|
|
|
|
BIT SIZE = 1 ----
|
|
|
|
|
END OF MODULE INFORMATION.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
|