单片机驱动LIS3DH

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

/*******************************************//******STC12C5A60S2驱动LIS3DH程序**********//**********宁夏创耀信科技有限公司***********//**************作者:207Mety****************//****附录中包含本程序需要的函数及.H文件*****/#includemain.hvoidmain(void){u8_tDATA=0;u8_t*tmp=0;u8_ti,n;u8_tbuffer[26];AxesRaw_taux_raw;i16_tx[128];i16_ty[128];i16_tz[128];longX,Y,Z;UartInit();//9600bps@11.0592MHzCS=1;SCL=1;DATA=1;Send_UART1(0x0d);Send_UART1(0x0a);LIS3DH_SetODR(LIS3DH_ODR_400Hz);LIS3DH_SetMode(LIS3DH_NORMAL);LIS3DH_SetFullScale(LIS3DH_FULLSCALE_8);LIS3DH_SetAxis(LIS3DH_X_ENABLE|LIS3DH_Y_ENABLE|LIS3DH_Z_ENABLE);while(1){x[n]=spi_read(0x29)*256+spi_read(0x28);y[n]=spi_read(0x2b)*256+spi_read(0x2a);z[n]=spi_read(0x2d)*256+spi_read(0x2c);for(i=0;i128;i++){X=X+x[i];Y=Y+y[i];Z=Z+z[i];}X=X/128;Y=Y/128;Z=Z/128;n++;if(n==128){n=0;sprintf(buffer,X=%6dY=%6dZ=%6d\r\n,(int)((float)X*16/65536*1000),(int)((float)Y*16/65536*1000),(int)((float)Z*16/65536*1000));//sprintf(buffer,X=%6dY=%6dZ=%6d\r\n,x,y,z);for(i=0;i26;i++)Send_UART1(buffer[i]);Send_UART1(0x0d);Send_UART1(0x0a);}}}附录1:/********************(C)COPYRIGHT2012STMicroelectronics*********************FileName:lis3dh_driver.h*Author:MSHApplicationTeam*Author:AbhishekAnand,FabioTota*Version:$Revision:$*Date:$Date:$*Description:DescriptorHeaderforlis3dh_driver.cdriverfile**HISTORY:*Date|Modification|Author*24/06/2011|InitialRevision|FabioTota*07/06/2012|Supportformultipledriversinthesameprogram|AbhishekAnand**********************************************************************************THEPRESENTFIRMWAREWHICHISFORGUIDANCEONLYAIMSATPROVIDINGCUSTOMERS*WITHCODINGINFORMATIONREGARDINGTHEIRPRODUCTSINORDERFORTHEMTOSAVETIME.*ASARESULT,STMICROELECTRONICSSHALLNOTBEHELDLIABLEFORANYDIRECT,*INDIRECTORCONSEQUENTIALDAMAGESWITHRESPECTTOANYCLAIMSARISINGFROMTHE*CONTENTOFSUCHFIRMWAREAND/ORTHEUSEMADEBYCUSTOMERSOFTHECODING*INFORMATIONCONTAINEDHEREININCONNECTIONWITHTHEIRPRODUCTS.**THISSOFTWAREISSPECIFICALLYDESIGNEDFOREXCLUSIVEUSEWITHSTPARTS.********************************************************************************//*Definetopreventrecursiveinclusion-------------------------------------*/#ifndef__LIS3DH_DRIVER__H#define__LIS3DH_DRIVER__H/*Includes------------------------------------------------------------------*//*Exportedtypes------------------------------------------------------------*///thesecouldchangeaccordinglywiththearchitecture#ifndef__ARCHDEP__TYPES#define__ARCHDEP__TYPEStypedefunsignedcharu8_t;typedefunsignedshortintu16_t;typedefshortinti16_t;typedefsignedchari8_t;#endif/*__ARCHDEP__TYPES*/typedefu8_tLIS3DH_IntPinConf_t;typedefu8_tLIS3DH_Axis_t;typedefu8_tLIS3DH_Int1Conf_t;//definestructure#ifndef__SHARED__TYPES#define__SHARED__TYPEStypedefenum{MEMS_SUCCESS=0x01,MEMS_ERROR=0x00}status_t;typedefenum{MEMS_ENABLE=0x01,MEMS_DISABLE=0x00}State_t;typedefstruct{i16_tAXIS_X;i16_tAXIS_Y;i16_tAXIS_Z;}AxesRaw_t;#endif/*__SHARED__TYPES*/typedefenum{LIS3DH_ODR_1Hz=0x01,LIS3DH_ODR_10Hz=0x02,LIS3DH_ODR_25Hz=0x03,LIS3DH_ODR_50Hz=0x04,LIS3DH_ODR_100Hz=0x05,LIS3DH_ODR_200Hz=0x06,LIS3DH_ODR_400Hz=0x07,LIS3DH_ODR_1620Hz_LP=0x08,LIS3DH_ODR_1344Hz_NP_5367HZ_LP=0x09}LIS3DH_ODR_t;typedefenum{LIS3DH_POWER_DOWN=0x00,LIS3DH_LOW_POWER=0x01,LIS3DH_NORMAL=0x02}LIS3DH_Mode_t;typedefenum{LIS3DH_HPM_NORMAL_MODE_RES=0x00,LIS3DH_HPM_REF_SIGNAL=0x01,LIS3DH_HPM_NORMAL_MODE=0x02,LIS3DH_HPM_AUTORESET_INT=0x03}LIS3DH_HPFMode_t;typedefenum{LIS3DH_HPFCF_0=0x00,LIS3DH_HPFCF_1=0x01,LIS3DH_HPFCF_2=0x02,LIS3DH_HPFCF_3=0x03}LIS3DH_HPFCutOffFreq_t;typedefstruct{u16_tAUX_1;u16_tAUX_2;u16_tAUX_3;}LIS3DH_Aux123Raw_t;typedefenum{LIS3DH_FULLSCALE_2=0x00,LIS3DH_FULLSCALE_4=0x01,LIS3DH_FULLSCALE_8=0x02,LIS3DH_FULLSCALE_16=0x03}LIS3DH_Fullscale_t;typedefenum{LIS3DH_BLE_LSB=0x00,LIS3DH_BLE_MSB=0x01}LIS3DH_Endianess_t;typedefenum{LIS3DH_SELF_TEST_DISABLE=0x00,LIS3DH_SELF_TEST_0=0x01,LIS3DH_SELF_TEST_1=0x02}LIS3DH_SelfTest_t;typedefenum{LIS3DH_FIFO_BYPASS_MODE=0x00,LIS3DH_FIFO_MODE=0x01,LIS3DH_FIFO_STREAM_MODE=0x02,LIS3DH_FIFO_TRIGGER_MODE=0x03,LIS3DH_FIFO_DISABLE=0x04}LIS3DH_FifoMode_t;typedefenum{LIS3DH_TRIG_INT1=0x00,LIS3DH_TRIG_INT2=0x01}LIS3DH_TrigInt_t;typedefenum{LIS3DH_SPI_4_WIRE=0x00,LIS3DH_SPI_3_WIRE=0x01}LIS3DH_SPIMode_t;typedefenum{LIS3DH_X_ENABLE=0x01,LIS3DH_X_DISABLE=0x00,LIS3DH_Y_ENABLE=0x02,LIS3DH_Y_DISABLE=0x00,LIS3DH_Z_ENABLE=0x04,LIS3DH_Z_DISABLE=0x00}LIS3DH_AXISenable_t;typedefenum{LIS3DH_INT1_6D_4D_DISABLE=0x00,LIS3DH_INT1_6D_ENABLE=0x01,LIS3DH_INT1_4D_ENABLE=0x02}LIS3DH_INT_6D_4D_t;typedefenum{LIS3DH_UP_SX=0x44,LIS3DH_UP_DX=0x42,LIS3DH_DW_SX=0x41,LIS3DH_DW_DX=0x48,LIS3DH_TOP=0x60,LIS3DH_BOTTOM=0x50}LIS3DH_POSITION_6D_t;typedefenum{LIS3DH_INT_MODE_OR=0x00,LIS3DH_INT_MODE_6D_MOVEMENT=0x01,LIS3DH_INT_MODE_AND=0x02,LIS3DH_INT_MODE_6D_POSITION=0x03}LIS3DH_Int1Mode_t;//interruptclickresponse//b7=don'tcareb6=IAb5=DClickb4=Sclickb3=Sign//b2=zb1=yb0=xtypedefenum{LIS3DH_DCLICK_Z_P=0x24,LIS3DH_DCLICK_Z_N=0x2C,LIS3DH_SCLICK_Z_P=0x14,LIS3DH_SCLICK_Z_N=0x1C,LIS3DH_DCLICK_Y_P=0x22,LIS3DH_DCLICK_Y_N=0x2A,LIS3DH_SCLICK_Y_P=0x12,LIS3DH_SCLICK_Y_N=0x1A,LIS3DH_DCLICK_X_

1 / 62
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功