📄 main.lst
字号:
248 4 else TapCounter++;
249 4 }
250 3
251 3 //Single Tap, process method is similar with Double Tap
252 3 if((Interrupt&0x40)==0x40) //Single Tap interrupt,
253 3 {
254 4 if((RotateStatus==0x05) && (LastRotateStatus==0x05) )
ARM COMPILER V2.42, main 11/08/08 15:14:09 PAGE 5
255 4 {
256 5 if(TapStatus==0x00)
257 5 {
258 6 TapStatus=0x20;
259 6 TapCounter=0x00;
260 6 PutChar(TapStatus);
261 6 }
262 5
263 5 }
264 4
265 4 }
266 3 else
267 3 {
268 4 if(TapCounter>=75)
269 4 {
270 5 TapStatus=0x00;
271 5 TapCounter=0x00;
272 5 PutChar(TapStatus);
273 5 }
274 4 else TapCounter++;
275 4 }
276 3
277 3
278 3 if((Interrupt&0x80)==0x80) // Data Rdy interrupt, get X Y Z data for shake and rotate function
279 3 {
280 4
281 4 // Get high byte and low byte data of X Y Z, and combine into Word
282 4 DataX1=(unsigned char)I2C_READ_REGISTER(0x32);
283 4 DataX2=(unsigned char)I2C_READ_REGISTER(0x33);
284 4 DataY1=(unsigned char)I2C_READ_REGISTER(0x34);
285 4 DataY2=(unsigned char)I2C_READ_REGISTER(0x35);
286 4 DataZ1=(unsigned char)I2C_READ_REGISTER(0x36);
287 4 DataZ2=(unsigned char)I2C_READ_REGISTER(0x37);
288 4
289 4 DataX=DataX2;
290 4 DataX=(DataX<<8) | DataX1;
291 4
292 4 DataY=DataY2;
293 4 DataY=(DataY<<8) | DataY1;
294 4
295 4 DataZ=DataZ2;
296 4 DataZ=(DataZ<<8) | DataZ1;
297 4
298 4
299 4 //Rotate: Judgement methods for Right, left, Up, Down, Top, Bottom are same, only take "Down" for a
-detail example
300 4 // note that: the rotate status is related with the assemble direction of the ADXL345EVB
301 4
302 4 // Down: 0.7G < Y < 1.3G -0.5G < X <0.5G -0.5G < Z <0.5G
303 4 if( (DataY < 0xA6) && (DataY > 0x5A) && ((DataX <0x40) || (DataX >0xFFBF)) && ((DataZ <0x40) || (Da
-taZ >0xFFBF)) )
304 4 {
305 5 if(LastRotateStatus==0x04) // Last RotateStatus==Down
306 5 {
307 6
308 6 if(RotateCounter==10) // wait time counter overflow, which means "Down" status hold for a certain
- time
309 6 {
310 7 RotateCounter=0; // clear tiem counter
311 7
312 7 if(RotateStatus!=0x04) // RotateStatus!=Down before, and "Down" Status has hold for a certain time
313 7 {
314 8 RotateStatus=0x04; // set RotateStatus = Down
315 8 PutChar(RotateStatus); // send status to PC demo
316 8 }
317 7
ARM COMPILER V2.42, main 11/08/08 15:14:09 PAGE 6
318 7 }
319 6 else RotateCounter++;
320 6 }
321 5 else // Last RotateStatus!=Down
322 5 {
323 6 LastRotateStatus=0x04; // set Last RotateStatus = Down
324 6 RotateCounter=0; // start time counter
325 6 }
326 5 }
327 4 // Up: -1.30.7G < Y < -0.7G -0.5G < X <0.5G -0.5G < Z <0.5G
328 4 else if( (DataY < 0xFFA5) && (DataY > 0xFF59) && ((DataX <0x40) || (DataX >=0xFFBF)) && ((DataZ <0x
-40) || (DataZ >0xFFBF)) )
329 4 {
330 5 if(LastRotateStatus==0x03)
331 5 {
332 6
333 6 if(RotateCounter==10)
334 6 {
335 7 RotateCounter=0;
336 7
337 7 if(RotateStatus!=0x03)
338 7 {
339 8 RotateStatus=0x03;
340 8 PutChar(RotateStatus);
341 8 }
342 7
343 7 }
344 6 else RotateCounter++;
345 6 }
346 5 else
347 5 {
348 6 LastRotateStatus=0x03;
349 6 RotateCounter=0;
350 6 }
351 5 }
352 4 // Left: 0.7G < X < 1.3G -0.5G < Y <0.5G -0.5G < Z <0.5G
353 4 else if( (DataX < 0xA6) && (DataX > 0x5A) && ((DataY <0x40) || (DataY >0xFFBF)) && ((DataZ <0x40) |
-| (DataZ >0xFFBF)) )
354 4 {
355 5 if(LastRotateStatus==0x01)
356 5 {
357 6
358 6 if(RotateCounter==10)
359 6 {
360 7 RotateCounter=0;
361 7
362 7 if(RotateStatus!=0x01)
363 7 {
364 8 RotateStatus=0x01;
365 8 PutChar(RotateStatus);
366 8 }
367 7
368 7 }
369 6 else RotateCounter++;
370 6 }
371 5 else
372 5 {
373 6 LastRotateStatus=0x01;
374 6 RotateCounter=0;
375 6 }
376 5 }
377 4 // Right: -1.30.7G < X < -0.7G -0.5G < Y <0.5G -0.5G < Z <0.5G
378 4 else if( (DataX < 0xFFA5) && (DataX > 0xFF59) && ((DataY <0x40) || (DataY >0xFFBF)) && ((DataZ <0x4
-0) || (DataZ >0xFFBF)) )
379 4 {
380 5 if(LastRotateStatus==0x02)
ARM COMPILER V2.42, main 11/08/08 15:14:09 PAGE 7
381 5 {
382 6
383 6 if(RotateCounter==10)
384 6 {
385 7 RotateCounter=0;
386 7
387 7 if(RotateStatus!=0x02)
388 7 {
389 8 RotateStatus=0x02;
390 8 PutChar(RotateStatus);
391 8 }
392 7
393 7 }
394 6 else RotateCounter++;
395 6 }
396 5 else
397 5 {
398 6 LastRotateStatus=0x02;
399 6 RotateCounter=0;
400 6 }
401 5 }
402 4 // Bottom: 0.7G < Z < 1.3G -0.5G < X <0.5G -0.5G < Y <0.5G
403 4 else if( (DataZ < 0xA6) && (DataZ > 0x5A) && ((DataX <0x40) || (DataX >0xFFBF)) && ((DataY <0x40) ||
- (DataY >0xFFBF)) )
404 4 {
405 5 if(LastRotateStatus==0x06)
406 5 {
407 6
408 6 if(RotateCounter==10)
409 6 {
410 7 RotateCounter=0;
411 7
412 7 if(RotateStatus!=0x06)
413 7 {
414 8 RotateStatus=0x06;
415 8 PutChar(RotateStatus);
416 8 }
417 7
418 7 }
419 6 else RotateCounter++;
420 6 }
421 5 else
422 5 {
423 6 LastRotateStatus=0x06;
424 6 RotateCounter=0;
425 6 }
426 5 }
427 4 // Top: -1.30.7G < Z < -0.7G -0.5G < X <0.5G -0.5G < Y <0.5G
428 4 else if( (DataZ < 0xFFA5) && (DataZ > 0xFF59) && ((DataX <0x40) || (DataX >0xFFBF)) && ((DataY <0x40
-) || (DataY >0xFFBF)) )
429 4 {
430 5
431 5 if(LastRotateStatus==0x05)
432 5 {
433 6
434 6 if(RotateCounter==10)
435 6 {
436 7 RotateCounter=0;
437 7
438 7 if(RotateStatus!=0x05)
439 7 {
440 8 RotateStatus=0x05;
441 8 PutChar(RotateStatus);
442 8 }
443 7
444 7 }
ARM COMPILER V2.42, main 11/08/08 15:14:09 PAGE 8
445 6 else RotateCounter++;
446 6 }
447 5 else
448 5 {
449 6 LastRotateStatus=0x05;
450 6 RotateCounter=0;
451 6 }
452 5 }
453 4
454 4
455 4 //Shake function is available only when RotateStatus==Up
456 4
457 4
458 4 // threshold for "Forward", X < -2.5G,
459 4 if((DataX>=0x8000) &&(DataX<0xFEBF))
460 4 {
461 5
462 5 if(ShakeDetectStep==0x00) // shake direction detect step
463 5 {
464 6 LastShakeStatus=ShakeStatus; // refresh LastShakeStatus and ShakeStatus,
465 6 ShakeStatus=0x08;
466 6
467 6 if(LastShakeStatus==ShakeStatus) // Wait for time counter overflow, which means "Forward" status
- hold for a certain time
468 6 {
469 7
470 7 if(ShakeDetectCounter>1) // time counter overflow,
471 7 {
472 8 ShakeDetectStep=0x01; // shake direction has been detected
473 8 ShakeDetectCounter=0x00; // clear ShakeDetectCounter
474 8 ShakeStopCounter=0x00; // start to detect the stop of shake step
475 8 PutChar(ShakeStatus); // send status to PC demo
476 8 }
477 7 else ShakeDetectCounter++;
478 7 }
479 6 else //"Forward" status does not hold for a certain time,
480 6 {
481 7 if(ShakeDetectCounter==0) // exceed the threshold for the first time, then register the status
482 7 LastShakeStatus=ShakeStatus;
483 7 else // shake direction does not hold for a certain time, this is not a valid skake,
484 7 {
485 8 ShakeDetectStep=0x01; // shake has been detected, but this is not a valid skake, so does not
-send status to PC demo
486 8 ShakeStopCounter=0x00; // start to detect the stop of shake step
487 8 ShakeStatus=0x00; // clear status
488 8 ShakeDetectCounter=0x00; // clear ShakeDetectCounter
489 8 }
490 7 }
491 6
492 6 }
493 5 else // not in shake direction detect step, a over threshold action is found in stop detect step
494 5 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -