📄 bthcomm.lst
字号:
C51 COMPILER V7.10 BTHCOMM 10/14/2005 13:18:00 PAGE 1
C51 COMPILER V7.10, COMPILATION OF MODULE BTHCOMM
OBJECT MODULE PLACED IN bthcomm.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe bthcomm.c NOREGPARMS OBJECTEXTEND LARGE DEBUG PRINT REGISTERBANK(0) OPTIMIZ
-E(5)
line level source
1 #include "bthcomm.h"
2 #include "W77E58.H"
3 #include "string.h"
4 #include "ctype.h"
5
6 char code bthat[] = {"at\r"};
7 char code bthate[] = {"ate\r"};
8 char code bthinq[] = {"at**bdinq\r"};
9 char code bthlist[] = {"at**bdlist\r"};
10 char code bthlink[] = {"atdd"};
11 char code bthserv[] = {",s1\r"};
12 char code strplus[] = {"+++"};
13 char code strok[] = {"OK"};
14 char code stratok[] = {"atOK"};
15 char code strconn[] = {"CONNECT"};
16 char code strinqok[]= {"d1:BD:"};
17 char code strbd[] = {"BD:"};
18
19 char code bthdisconn[] = {"ath\r"};
20 char code bthinqact[] = {"inquiryactiveOK"};
21 char code bthinqemp[] = {"listemptyOK"};
22 char code bthresetc[] = {"at**reset\r"};
23
24 ////////////////////////////////////////////////////
25 /*void WatchDog(void) interrupt 12
26 {
27 if(WDIF)
28 {
29 TA=0xAA;
30 TA=0x55;
31 WDIF = 0;
32 }
33 TA=0xAA;
34 TA=0x55;
35 RWT=1;//clear the watchdog flag
36 }*/
37 //////////////////////////////////////////////////////
38 void Time1(void) interrupt 1 using 1
39 {
40 1 time++;
41 1 if(time==15)
42 1 {
43 2 // onesecond=~onesecond;
44 2 second++;
45 2 time=0;
46 2 second1++;
47 2
48 2 }
49 1 if(second==60)
50 1 {
51 2 second=0;
52 2 minute++;
53 2 }
54 1 minute=minute%60;
C51 COMPILER V7.10 BTHCOMM 10/14/2005 13:18:00 PAGE 2
55 1
56 1 }
57 ///////////////////////////////////////////////////
58 void series0_send_char(char *p)
59 {
60 1 char c;
61 1 c=*p;
62 1 while(1)
63 1 if(TI==1) break;
64 1 TI=0;
65 1 SBUF = c;
66 1 }
67 ////////////////////////////////////////////////////
68 /*void series1_send_char(char *p)
69 {
70 char c;
71 c=*p;
72 while(1)
73 if(TI1==1) break;
74 TI1=0;
75 SBUF1 = c;
76 }*/
77 /////////////////////////////////////////////////
78 void series0_send_array(char * pc)
79 {
80 1 while(1)
81 1 {
82 2 series0_send_char(pc);
83 2 WD_Reset
84 2 pc++;
85 2 if(*pc=='\0')
86 2 break;
87 2 }
88 1 }
89 /////////////////////////////////////////////////
90 /*void series1_send_array(char * pc)
91 {
92 while(1)
93 {
94 series1_send_char(pc);
95 pc++;
96 if(*pc=='\0')
97 break;
98 }
99 }*/
100 ////////////////////////////////////////////////
101 char series0_recv_char()
102 {
103 1 char c;
104 1 second = 0;
105 1 while(1)
106 1 {
107 2 if(RI==1) break;
108 2 WD_Reset
109 2 if(second>=3) return -1;
110 2 }
111 1 RI=0;
112 1 c = SBUF;
113 1 return c;
114 1 }
115 //////////////////////////////////////////////////
116 void series0_recv_array()
C51 COMPILER V7.10 BTHCOMM 10/14/2005 13:18:00 PAGE 3
117 {
118 1 char c,t,t1,Count;
119 1 bit s,s0,s1,s2,s3,s5,s6;
120 1 s = 1;
121 1 s0 = 0;
122 1 s1 = 0;
123 1 s2 = 0;
124 1 s3 = 0;
125 1 s5 = 0;
126 1 s6 = 0;
127 1 CommCnt = 0;
128 1 Count = 0;
129 1 while(1)
130 1 {
131 2 c=series0_recv_char();
132 2 if(c==-1)
133 2 break;
134 2 //
135 2 if(c=='n')
136 2 t=Count;
137 2 if((c=='a')&&((t+1)==Count))
138 2 s0 = 1;
139 2 if((c=='m')&&((t+2)==Count))
140 2 s1 = 1;
141 2 if((c=='e')&&((t+3)==Count))
142 2 s2 = 1;
143 2 if((c==':')&&((t+4)==Count))
144 2 s3 = 1;
145 2 if(s0&s1&s2&s3)
146 2 {
147 3 s = 0;
148 3 s0 = 0;
149 3 s1 = 0;
150 3 s2 = 0;
151 3 s3 = 0;
152 3 }
153 2
154 2 //
155 2 if(c=='d')
156 2 {
157 3 t1=Count;
158 3 s6=1;
159 3 s =1;
160 3 }
161 2 if((c==':')&&s6)
162 2 {
163 3 if((t1+2)==Count)
164 3 s6= 0;
165 3 else s = 0;
166 3
167 3 }
168 2 if(c>0x20&&s)
169 2 {
170 3 RecvBuf[CommCnt]=c;
171 3 CommCnt++;
172 3 }
173 2 Count++;
174 2 }
175 1 }
176 ///////////////////////////////////////////////
177 /*char series1_recv_char()
178 {
C51 COMPILER V7.10 BTHCOMM 10/14/2005 13:18:00 PAGE 4
179 char c;
180 second = 0;
181 while(1)
182 {
183 if(RI1==1) break;
184 if(second>=3) return -1;
185 }
186 RI1=0;
187 c = SBUF1;
188 return c;
189 }
190 ///////////////////////////////////////////////
191 void series1_recv_array()
192 {
193 char c;
194 CommCnt1 = 0;
195 while(1)
196 {
197 c = series1_recv_char();
198
199 if(Recving1==0)
200 {
201 if(c==0x02)//起始
202 {
203 RecvBuf1[0]=0x02;
204 CommCnt1 =1;
205 Recving1 =1;
206 }
207 else
208 {
209 Recving1=0;
210 CommCnt1=0;
211 }
212 }
213 else
214 {
215 RecvBuf1[CommCnt1] = c;
216 if(c==0x03)
217 {
218 ComLen1 =CommCnt1+2;
219 }
220 if(ComLen1 == CommCnt1)
221 {
222 Recving1=0;
223 CommCnt1=0;
224 RecvOk1 =1;
225 return;
226 }
227 CommCnt1++;
228 }
229 }
230 }*/
231 ///////////////////////////////////////////////
232 char * strnfind(char * p1, char * p2, char n)
233 {
234 1 char *p;
235 1 p = strchr(p1, *p2);
236 1 if(p)
237 1 {
238 2 if(strncmp(p, p2, n) == 0)
239 2 return p;
240 2 else
C51 COMPILER V7.10 BTHCOMM 10/14/2005 13:18:00 PAGE 5
241 2 return NULL;
242 2 }
243 1 else
244 1 return NULL;
245 1 }
246 //////////////////////////////////////////////////
247 char BthDevInq(void)
248 {
249 1
250 1 char *pa, *pc, *pt ;
251 1 char n,m;
252 1 TI = 1;
253 1 pa = bthat;
254 1 second1 = 0;
255 1 do
256 1 {
257 2 series0_send_array(pa);
258 2 series0_recv_array();
259 2 pc = RecvBuf;
260 2 pt = strok;
261 2 n = strncmp(pc,pt,2);
262 2 pt = stratok;
263 2 m = strncmp(pc,pt,4);
264 2 WD_Reset
265 2 if(second1>50) return 1; //1: at指令出错
266 2 }while(n!=0&&m!=0);
267 1
268 1 second1 = 0;
269 1 pa = bthate;
270 1 do
271 1 {
272 2 series0_send_array(pa);
273 2 series0_recv_array();
274 2 pc = RecvBuf;
275 2 pt = strok;
276 2 n = strncmp(pc,pt,2);
277 2 WD_Reset
278 2 if(second1>50) return 2; //2:ate指令出错
279 2 }while(n!=0);
280 1
281 1 second1 = 0;
282 1 pa = bthinq;
283 1 do
284 1 {
285 2 series0_send_array(pa);
286 2 series0_recv_array();
287 2 pc = RecvBuf;
288 2 pt = strok;
289 2 n = strncmp(pc,pt,2);
290 2 WD_Reset
291 2 if(second1>50) return 3; //inqury 指令出错
292 2 }while(n!=0);
293 1
294 1 pa = bthlist;
295 1 second1 = 0;
296 1 while(1)
297 1 {
298 2 series0_send_array(pa);
299 2 series0_recv_array();
300 2 pc = bthinqact;
301 2 pt = RecvBuf;
302 2 n = strncmp(pt,pc,15);
C51 COMPILER V7.10 BTHCOMM 10/14/2005 13:18:00 PAGE 6
303 2 WD_Reset
304 2 if(n==0) continue;
305 2
306 2 pc = bthinqemp;
307 2 m = strncmp(pc,pt,11);
308 2 WD_Reset
309 2 if(m==0) return 6; //6:在天线范围内无蓝牙设备
310 2
311 2 pc = strinqok;
312 2 n = strncmp(pc,pt,6);
313 2 if(n==0)
314 2 {
315 3 //将查询到的所有蓝牙设备记录到结构体BthDevice中
316 3 pc = strbd;
317 3 DeviceCoun = 0;
318 3 do
319 3 {
320 4 pt = strnfind(pt, pc, 3);
321 4 if(pt!=NULL)
322 4 {
323 5 BD[DeviceCoun].DeviceNum[0] = *(pt-3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -