1、 File: MMA7660_Orientation.c Description: Orientation Detection Algorithm Ver 1.0.0 Released Jun.2009 C O N F I D E N T I A L
2、 This code is released under the Non-Disclosure Agreement (NDA) between customer and Freescale, and is allowed to use in Freescale's products only
3、 THIS CODE IS ONLY INTENDED AS AN EXAMPLE FOR DEMONSTRATING THE FREESCALE MICROCONTROLLERS. IT HAS ONLY BEEN GIVEN A MINIMUM LEVEL OF TEST. IT IS PROVIDED 'AS SEEN' WITH NO GUARANTEES AND NO PROMISE OF SUPPORT.
4、 Freescale is not obligated to provide any support, upgrades or new releases of the Software. Freescale may make changes to the Software at any time, without any obligation to notify or provide updated versio
5、ns of the Software to you. Freescale expressly disclaims any warranty for the Software. The Software is provided as is, without warranty of any kind, either express or implied, including, without limitation, the implied warranties of merchantability, fitness for a particular pu
6、rpose, or non-infringement. You assume the entire risk arising out of the use or performance of the Software, or any systems you design using the software (if any). Nothing may be construed as a warranty or representation by Freescale that the Software or any derivative work deve
7、loped with or incorporating the Software will be free from infringement of the intellectual property rights of third parties. In no event will Freescale be liable, whether in contract, tort, or otherwise, for any incidental, special, indirect, consequential or punitive damages, i
8、ncluding, but not limited to, damages for any loss of use, loss of time, inconvenience, commercial loss, or lost profits, savings, or revenues to the full extent such may be disclaimed by law. The Software is not fault tolerant and is not designed, manufactured or intended by Freesc
9、ale for incorporation into products intended for use or resale in on-line control equipment in hazardous, dangerous to life or potentially life-threatening environments requiring fail-safe performance, such as in the operation of nuclear facilities, aircraft navigation or communica
10、tion systems, air traffic control, direct life support machines or weapons systems, in which the failure of products could lead directly to death, personal injury or severe physical or environmental damage (High Risk Activities). You specifically represent and warrant that you
11、 will not use the Software or any derivative work of the Software for High Risk Activities. Freescale and the Freescale logos are registered trademarks of Freescale Semiconductor Inc. / #include "MMA7660_Orientation.h" e
12、xtern VUINT8 MMA7660_SPCNT_Value; extern VUINT8 MMA7660_INTSU_Value; extern VUINT8 MMA7660_MODE_Value; extern VUINT8 MMA7660_SR_Value; extern VUINT8 MMA7660_PDET_Value; extern VUINT8 MMA7660_PD_Value; extern VINT8 Xnew8, Ynew8, Znew8; extern VUINT8 MMA7660_InterruptFlag; VUINT8 MMA7660_Orien
13、tationStatus; ORIENTATION MMA7660_Orientation; void MMA7660_Orientation_InterruptService(void){ VUINT8 temp8u; if(!MMA7660_InterruptFlag) return; MMA7660_InterruptFlag = 0; MMA7660_OrientationStatus = mma7660_IICRead_Alert(MMA7660_TILT)&0x1F; IIC_Read_MMA7660_XYZ6(&Xnew8,
14、Ynew8, &Znew8); if(Znew8>=MMA7660_Sin30pos) MMA7660_Orientation = FLAT; else if(Znew8<=MMA7660_Sin30neg) MMA7660_Orientation = FLAT_DOWN; else { temp8u = MMA7660_OrientationStatus&0x1C; if(temp8u==0) { if((MMA7660_OrientationStatus&0x03)==0x02) MMA7660_Orientat
15、ion = FLAT_DOWN; else MMA7660_Orientation = FLAT; } else { if(temp8u==0x04) MMA7660_Orientation = YDOWN; else if(temp8u==0x08) MMA7660_Orientation = YUP; else if(temp8u==0x14) MMA7660_Orientation = XDOWN; else if(temp8u==0x18) MMA7660_Orientation = X
16、UP; } } } void MMA7660_Orientation_Startup(void){ MMA7660_SPCNT_Value = 60; //Sleep delay = 60/1616 = 60s MMA7660_INTSU_Value = 0x03; //Only Front/Back position change and Up/Down/Right/Left Position change cause interrupts MMA7660_SR_Value = 0xFC; //FILT[2:0] = 111 -
17、 8 samples per filter //AWSR[1:0] = 11 - 1 samples/second on auto-wake mode //AMSR[2:0] = 100 - 8 samples/second on active mode MMA7660_MODE_Value = 0x39; //Interrupt output high active //Interr
18、upt output open drain //Sleep counter clock divided by 16 //Auto-Sleep enabled //Auto-Wake enabled //Test Mode off //Active Mode MMA7660_Init(); 我们是深圳本土最受客户青睐、成长最快、最关注增值服务的MID电子元件提供商之一。我们深圳的长期大量现货型号有:MMA7660, MMA7455, MMA8452QR1, MXC6225XU, MMC3140MS, TS1003,MPU-3050, ALC5621, ALC5625, WM8988, ES8388,联系热线:13714686590,杨先生






