mpu6050详细C语言程序Word下载.docx

上传人:b****3 文档编号:7752960 上传时间:2023-05-09 格式:DOCX 页数:24 大小:19.81KB
下载 相关 举报
mpu6050详细C语言程序Word下载.docx_第1页
第1页 / 共24页
mpu6050详细C语言程序Word下载.docx_第2页
第2页 / 共24页
mpu6050详细C语言程序Word下载.docx_第3页
第3页 / 共24页
mpu6050详细C语言程序Word下载.docx_第4页
第4页 / 共24页
mpu6050详细C语言程序Word下载.docx_第5页
第5页 / 共24页
mpu6050详细C语言程序Word下载.docx_第6页
第6页 / 共24页
mpu6050详细C语言程序Word下载.docx_第7页
第7页 / 共24页
mpu6050详细C语言程序Word下载.docx_第8页
第8页 / 共24页
mpu6050详细C语言程序Word下载.docx_第9页
第9页 / 共24页
mpu6050详细C语言程序Word下载.docx_第10页
第10页 / 共24页
mpu6050详细C语言程序Word下载.docx_第11页
第11页 / 共24页
mpu6050详细C语言程序Word下载.docx_第12页
第12页 / 共24页
mpu6050详细C语言程序Word下载.docx_第13页
第13页 / 共24页
mpu6050详细C语言程序Word下载.docx_第14页
第14页 / 共24页
mpu6050详细C语言程序Word下载.docx_第15页
第15页 / 共24页
mpu6050详细C语言程序Word下载.docx_第16页
第16页 / 共24页
mpu6050详细C语言程序Word下载.docx_第17页
第17页 / 共24页
mpu6050详细C语言程序Word下载.docx_第18页
第18页 / 共24页
mpu6050详细C语言程序Word下载.docx_第19页
第19页 / 共24页
mpu6050详细C语言程序Word下载.docx_第20页
第20页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

mpu6050详细C语言程序Word下载.docx

《mpu6050详细C语言程序Word下载.docx》由会员分享,可在线阅读,更多相关《mpu6050详细C语言程序Word下载.docx(24页珍藏版)》请在冰点文库上搜索。

mpu6050详细C语言程序Word下载.docx

#defineACCEL_ZOUT_H0x3F

#defineACCEL_ZOUT_L0x40

//#defineTEMP_OUT_H0x41

//#defineTEMP_OUT_L0x42

//

#defineGYRO_XOUT_H0x43

#defineGYRO_XOUT_L0x44

#defineGYRO_YOUT_H0x45

#defineGYRO_YOUT_L0x46

#defineGYRO_ZOUT_H0x47

#defineGYRO_ZOUT_L0x48

#definePWR_MGMT_10x6B//电源管理,典型值:

0x00(正常启用)

//#defineWHO_AM_I0x75//IIC地址寄存器(默认数值0x68,只读)

//****************************

#defineMPU6050_Addr0xD0//定义器件在IIC总线中的从地址,根据ALTADDRESS地址引脚不同修改

unsignedcharTX_DATA[4];

//显示据缓存区

unsignedcharBUF[10];

//接收数据缓存区

chartest=0;

//IIC用到

shortT_X,T_Y,T_Z,T_T;

//X,Y,Z轴,温度

//模拟IIC端口输出输入定义

#defineSCL_HGPIOB->

BSRR=GPIO_Pin_6

#defineSCL_LGPIOB->

BRR=GPIO_Pin_6

#defineSDA_HGPIOB->

BSRR=GPIO_Pin_7

#defineSDA_LGPIOB->

BRR=GPIO_Pin_7

#defineSCL_readGPIOB->

IDR&

GPIO_Pin_6

#defineSDA_readGPIOB->

GPIO_Pin_7

/*函数申明-----------------------------------------------*/

voidRCC_Configuration(void);

voidGPIO_Configuration(void);

voidNVIC_Configuration(void);

voidUSART1_Configuration(void);

voidWWDG_Configuration(void);

voidDelay(u32nTime);

voidDelayms(vu32m);

/*变量定义----------------------------------------------*/

/*******************************/

voidDATA_printf(uchar*s,shorttemp_data)

{

if(temp_data<

0){

temp_data=-temp_data;

*s='

-'

;

}

else*s='

'

*++s=temp_data/100+0x30;

temp_data=temp_data%100;

//取余运算

*++s=temp_data/10+0x30;

temp_data=temp_data%10;

*++s=temp_data+0x30;

}

*FunctionName:

I2C_GPIO_Config

*Description:

ConfigrationSimulationIICGPIO

*Input:

None

*Output:

None

*Return:

*******************************************************************************/

voidI2C_GPIO_Config(void)

GPIO_InitTypeDefGPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;

GPIO_Init(GPIOB,&

GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;

I2C_delay

SimulationIICTimingseriesdelay

voidI2C_delay(void)

u8i=30;

//这里可以优化速度,经测试最低到5还能写入

while(i)

{

i--;

}

voiddelay5ms(void)

inti=5000;

I2C_Start

MasterStartSimulationIICCommunication

WheatherStart

boolI2C_Start(void)

SDA_H;

SCL_H;

I2C_delay();

if(!

SDA_read)returnFALSE;

//SDA线为低电平则总线忙,退出

SDA_L;

if(SDA_read)returnFALSE;

//SDA线为高电平则总线出错,退出

returnTRUE;

I2C_Stop

MasterStopSimulationIICCommunication

voidI2C_Stop(void)

SCL_L;

}

I2C_Ack

MasterSendAcknowledgeSingle

voidI2C_Ack(void)

{

I2C_NoAck

MasterSendNoAcknowledgeSingle

voidI2C_NoAck(void)

I2C_WaitAck

MasterReseriveSlaveAcknowledgeSingle

WheatherReseriveSlaveAcknowledgeSingle

boolI2C_WaitAck(void)//返回为:

=1有ACK,=0无ACK

if(SDA_read)

{

returnFALSE;

I2C_SendByte

MasterSendaBytetoSlave

WillSendDate

voidI2C_SendByte(u8SendByte)//数据从高位到低位//

u8i=8;

while(i--)

if(SendByte&

0x80)

else

SendByte<

<

=1;

SCL_H;

I2C_RadeByte

MasterReseriveaByteFromSlave

DateFromSlave

unsignedcharI2C_RadeByte(void)//数据从高位到低位//

u8ReceiveByte=0;

ReceiveByte<

ReceiveByte|=0x01;

returnReceiveByte;

//ZRX

//单字节写入*******************************************

boolSingle_Write(unsignedcharSlaveAddress,unsignedcharREG_Address,unsignedcharREG_data)//void

if(!

I2C_Start())returnFALSE;

I2C_SendByte(SlaveAddress);

//发送设备地址+写信号//I2C_SendByte(((REG_Address&

0x0700)>

>

7)|SlaveAddress&

0xFFFE);

//设置高起始地址+器件地址

I2C_WaitAck()){I2C_Stop();

I2C_SendByte(REG_Address);

//设置低起始地址

I2C_WaitAck();

I2C_SendByte(REG_data);

I2C_Stop();

delay5ms();

//单字节读取*****************************************

unsignedcharSingle_Read(unsignedcharSlaveAddress,unsignedcharREG_Address)

{unsignedcharREG_data;

//I2C_SendByte(((REG_Address&

7)|REG_Address&

test=1;

I2C_SendByte((u8)REG_Address);

I2C_Start();

I2C_SendByte(SlaveAddress+1);

REG_data=I2C_RadeByte();

I2C_NoAck();

//returnTRUE;

returnREG_data;

}

/*

********************************************************************************

**函数名称:

RCC_Configuration(void)

**函数功能:

时钟初始化

**输入:

**输出:

**返回:

*/

voidRCC_Configuration(void)

/*RCCsystemreset(fordebugpurpose)*/

RCC_DeInit();

/*EnableHSE*/

RCC_HSEConfig(RCC_HSE_ON);

/*WaittillHSEisready*/

HSEStartUpStatus=RCC_WaitForHSEStartUp();

if(HSEStartUpStatus==SUCCESS)

/*HCLK=SYSCLK*/

RCC_HCLKConfig(RCC_SYSCLK_Div1);

/*PCLK2=HCLK*/

RCC_PCLK2Config(RCC_HCLK_Div1);

/*PCLK1=HCLK/2*/

RCC_PCLK1Config(RCC_HCLK_Div2);

/*Flash2waitstate*/

FLASH_SetLatency(FLASH_Latency_2);

/*EnablePrefetchBuffer*/

FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

/*PLLCLK=8MHz*9=72MHz*/

RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

/*EnablePLL*/

RCC_PLLCmd(ENABLE);

/*WaittillPLLisready*/

while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)

/*SelectPLLassystemclocksource*/

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

/*WaittillPLLisusedassystemclocksource*/

while(RCC_GetSYSCLKSource()!

=0x08)

/*EnableGPIOA,GPIOB,GPIOC,GPIOD,GPIOE,GPIOF,GPIOGandAFIOclocks*/

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOF,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG|RCC_APB2Periph_AFIO,ENABLE);

GPIO_Configuration(void)

端口初始化

voidGPIO_Configuration(void)

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2