update
parent
f10257b47b
commit
ef6cdc2390
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -476,13 +476,13 @@ ARM Macro Assembler Page 8
|
|||
00000200
|
||||
00000000
|
||||
Command Line: --debug --xref --diag_suppress=9931 --cpu=Cortex-M3 --apcs=interw
|
||||
ork --depend=..\obj\startup_stm32f10x_md.d -o..\obj\startup_stm32f10x_md.o -I"D
|
||||
:\Hardware Project\GeBalanceBot\4.WHEELTEC B570 ƽºâС³µÔ´Â루¿âº¯Êý¾«¼òÈëÃÅ°æ£
|
||||
©\USER\RTE" -I"D:\Program Files\Keilv5\ARM\PACK\ARM\CMSIS\4.5.0\CMSIS\Include"
|
||||
-I"D:\Program Files\Keilv5\ARM\PACK\Keil\STM32F1xx_DFP\1.1.0\Device\Include" --
|
||||
predefine="__UVISION_VERSION SETA 521" --predefine="_RTE_ SETA 1" --predefine="
|
||||
STM32F10X_MD SETA 1" --list=.\startup_stm32f10x_md.lst ..\MiniBalance_COER\star
|
||||
tup_stm32f10x_md.s
|
||||
ork --depend=..\obj\startup_stm32f10x_md.d -o..\obj\startup_stm32f10x_md.o -I"E
|
||||
:\HardwareProject\GeBalanceBot\4.WHEELTEC B570 平衡小车源码(库函数精简入门版)
|
||||
\USER\RTE" -I"D:\Program Files\Keilv5\ARM\PACK\ARM\CMSIS\4.5.0\CMSIS\Include" -
|
||||
I"D:\Program Files\Keilv5\ARM\PACK\Keil\STM32F1xx_DFP\1.1.0\Device\Include" --p
|
||||
redefine="__UVISION_VERSION SETA 521" --predefine="_RTE_ SETA 1" --predefine="S
|
||||
TM32F10X_MD SETA 1" --list=.\startup_stm32f10x_md.lst ..\MiniBalance_COER\start
|
||||
up_stm32f10x_md.s
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "bsp_iic.h"
|
||||
|
||||
#include "bluetooth.h"
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: i2c_Delay
|
||||
|
@ -207,6 +207,7 @@ void IIC_NAck(void)
|
|||
*/
|
||||
void IIC_Init(void)
|
||||
{
|
||||
PB_USART_printf(USART2, (u8*)"IIC Init..\r\n");
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_I2C_PORT, ENABLE); /* 打开GPIO时钟 */
|
||||
|
@ -218,6 +219,10 @@ void IIC_Init(void)
|
|||
|
||||
/* 给一个停止信号, 复位I2C总线上的所有设备到待机模式 */
|
||||
IIC_Stop();
|
||||
|
||||
|
||||
// uint8_t data = i2c_CheckDevice(0x75);
|
||||
// PB_USART_printf(USART2, (u8*)"IIC Init Res = %d\r\n", (int)data);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -19,20 +19,19 @@ void System_Init(void)
|
|||
NVIC_Config();
|
||||
LED_GPIO_Config();
|
||||
USART1_Init(115200);
|
||||
IIC_Init();
|
||||
//IIC_Init();
|
||||
Motor_Init();
|
||||
MOTO_PWM_Init(3599,0);
|
||||
|
||||
OLED_Init();
|
||||
OLED_Clear();
|
||||
OLED_ShowCHinese(0,0,2);
|
||||
OLED_ShowCHinese(16,0,3);
|
||||
OLED_ShowString(88,0,(u8*)"m/min",16);
|
||||
OLED_ShowString(0, 2,(u8*)"Left : RPM",12);
|
||||
OLED_ShowString(0, 3,(u8*)"Right: RPM",12);
|
||||
OLED_ShowString(0, 4,(u8*)"P: I: D: ",16);
|
||||
OLED_ShowString(0, 6,(u8*)"Set_C: RPM",12);
|
||||
OLED_ShowString(0, 7,(u8*)"Set_P: m/min",12);
|
||||
// OLED_Init();
|
||||
// OLED_Clear();
|
||||
// OLED_ShowCHinese(0,0,2);
|
||||
// OLED_ShowCHinese(16,0,3);
|
||||
// OLED_ShowString(88,0,(u8*)"m/min",16);
|
||||
// OLED_ShowString(0, 2,(u8*)"Left : RPM",12);
|
||||
// OLED_ShowString(0, 3,(u8*)"Right: RPM",12);
|
||||
// OLED_ShowString(0, 4,(u8*)"P: I: D: ",16);
|
||||
// OLED_ShowString(0, 6,(u8*)"Set_C: RPM",12);
|
||||
|
||||
Encoder_Init_TIM2();
|
||||
TIM2 -> CNT=30000;
|
||||
|
|
|
@ -84,11 +84,15 @@ void _sys_exit(int x)
|
|||
/// 重定向c库函数printf到USART1
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
/* 发送一个字节数据到USART1 */
|
||||
USART_SendData(USART1, (uint8_t)ch);
|
||||
/* 等待发送完毕 */
|
||||
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
|
||||
return (ch);
|
||||
// /* 发送一个字节数据到USART1 */
|
||||
// USART_SendData(USART2, (uint8_t)ch);
|
||||
// /* 等待发送完毕 */
|
||||
// while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
|
||||
// return (ch);
|
||||
|
||||
while((USART1->SR&0X40)==0);// 使用串口1
|
||||
USART1->DR = (u8) ch;
|
||||
return ch;
|
||||
}
|
||||
|
||||
/// 重定向c库函数scanf到USART1
|
||||
|
|
|
@ -21,6 +21,7 @@ All rights reserved
|
|||
#include "sys.h"
|
||||
#include "delay.h"
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
Function: IIC_MPU6050_Init
|
||||
Input : none
|
||||
|
|
|
@ -57,13 +57,13 @@ All rights reserved
|
|||
|
||||
|
||||
//IO方向设置
|
||||
#define SDA_IN() {GPIOB->CRH&=0XFFFFFF0F;GPIOB->CRH|=8<<4;}
|
||||
#define SDA_OUT() {GPIOB->CRH&=0XFFFFFF0F;GPIOB->CRH|=3<<4;}
|
||||
#define SDA_IN() {GPIOB->CRH&=0XFFFF0FFF;GPIOB->CRH|=8<<4;}
|
||||
#define SDA_OUT() {GPIOB->CRH&=0XFFFF0FFF;GPIOB->CRH|=3<<4;}
|
||||
|
||||
//IO操作函数
|
||||
#define IIC_SCL PBout(8) //SCL
|
||||
#define IIC_SDA PBout(9) //SDA
|
||||
#define READ_SDA PBin(9) //输入SDA
|
||||
#define IIC_SCL PBout(10) //SCL
|
||||
#define IIC_SDA PBout(11) //SDA
|
||||
#define READ_SDA PBin(11) //输入SDA
|
||||
|
||||
//IIC所有操作函数
|
||||
void IIC_MPU6050_Init(void); // 初始化IIC的IO口
|
||||
|
|
|
@ -8,9 +8,12 @@
|
|||
个接口,TXD,RXD,5V,GND
|
||||
1. PA2 -> 蓝牙RXD 2.PA3 -> 蓝牙TXD
|
||||
********************************************************************************/
|
||||
#include "stdarg.h"
|
||||
#include "stdio.h"
|
||||
#include "bluetooth.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
volatile unsigned char *rx2_address;
|
||||
volatile unsigned int rx2_count;
|
||||
volatile unsigned int rx2_length;
|
||||
|
@ -88,6 +91,145 @@ void USART2_Send(unsigned char *tx_buf, int len)
|
|||
}
|
||||
|
||||
|
||||
/**----------------------------------------------------------------------
|
||||
* Function : USART2_Send
|
||||
* Description : À¶ÑÀͨ¹ýUSART2·¢Ë͵½ÊÖ»ú
|
||||
* Author : zhanli&719901725@qq.com
|
||||
* Date : 2023/05/20 zhanli
|
||||
*---------------------------------------------------------------------**/
|
||||
void USART2_SendStr(unsigned char *tx_buf)
|
||||
{
|
||||
USART_ClearFlag(USART2, USART_FLAG_TC);
|
||||
USART_ClearITPendingBit(USART2, USART_FLAG_TXE);
|
||||
while(*tx_buf != 0)
|
||||
{
|
||||
USART_SendData(USART2, *tx_buf++);
|
||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) != 1);
|
||||
USART_ClearFlag(USART2, USART_FLAG_TC);
|
||||
USART_ClearITPendingBit(USART2, USART_FLAG_TXE);
|
||||
}
|
||||
}
|
||||
|
||||
static char *itoa(int value, char *string, int radix)
|
||||
{
|
||||
int i, d;
|
||||
int flag = 0;
|
||||
char *ptr = string;
|
||||
|
||||
/* This implementation only works for decimal numbers. */
|
||||
if (radix != 10)
|
||||
{
|
||||
*ptr = 0;
|
||||
return string;
|
||||
}
|
||||
|
||||
if (!value)
|
||||
{
|
||||
*ptr++ = 0x30;
|
||||
*ptr = 0;
|
||||
return string;
|
||||
}
|
||||
|
||||
/* if this is a negative value insert the minus sign. */
|
||||
if (value < 0)
|
||||
{
|
||||
*ptr++ = '-';
|
||||
|
||||
/* Make the value positive. */
|
||||
value *= -1;
|
||||
}
|
||||
|
||||
for (i = 10000; i > 0; i /= 10)
|
||||
{
|
||||
d = value / i;
|
||||
|
||||
if (d || flag)
|
||||
{
|
||||
*ptr++ = (char)(d + 0x30);
|
||||
value -= (d * i);
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Null terminate the string. */
|
||||
*ptr = 0;
|
||||
|
||||
return string;
|
||||
|
||||
} /* NCL_Itoa */
|
||||
|
||||
void PB_USART_printf(USART_TypeDef* USARTx, uint8_t *Data,...)
|
||||
{
|
||||
const char *s;
|
||||
int d;
|
||||
char buf[18];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, Data);
|
||||
|
||||
USART_ClearFlag(USART2, USART_FLAG_TC);
|
||||
USART_ClearITPendingBit(USART2, USART_FLAG_TXE);
|
||||
|
||||
while ( *Data != 0)
|
||||
{
|
||||
if ( *Data == 0x5c ) //'\'
|
||||
{
|
||||
switch ( *++Data )
|
||||
{
|
||||
case 'r':
|
||||
USART_SendData(USARTx, 0x0d);
|
||||
Data ++;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
USART_SendData(USARTx, 0x0a);
|
||||
Data ++;
|
||||
break;
|
||||
|
||||
default:
|
||||
Data ++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ( *Data == '%')
|
||||
{
|
||||
switch ( *++Data )
|
||||
{
|
||||
case 's':
|
||||
s = va_arg(ap, const char *);
|
||||
for ( ; *s; s++)
|
||||
{
|
||||
USART_SendData(USARTx,*s);
|
||||
while( USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET );
|
||||
}
|
||||
Data++;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
d = va_arg(ap, int);
|
||||
itoa(d, buf, 10);
|
||||
for (s = buf; *s; s++)
|
||||
{
|
||||
USART_SendData(USARTx,*s);
|
||||
while( USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET );
|
||||
}
|
||||
Data++;
|
||||
break;
|
||||
default:
|
||||
Data++;
|
||||
break;
|
||||
}
|
||||
} /* end of else if */
|
||||
else
|
||||
{
|
||||
USART_SendData(USARTx, *Data++);
|
||||
}
|
||||
while(USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET );
|
||||
USART_ClearFlag(USART2, USART_FLAG_TC);
|
||||
USART_ClearITPendingBit(USART2, USART_FLAG_TXE);
|
||||
}
|
||||
}
|
||||
|
||||
/**----------------------------------------------------------------------
|
||||
* Function : USART2_Receive
|
||||
* Description : 蓝牙接受,从手机接收
|
||||
|
|
|
@ -28,4 +28,8 @@ void USART2_Send(unsigned char *tx_buf, int len);
|
|||
*---------------------------------------------------------------------**/
|
||||
void USART2_Receive(unsigned char *rx_buf, int len);
|
||||
|
||||
void USART2_SendStr(unsigned char *tx_buf);
|
||||
|
||||
void PB_USART_printf(USART_TypeDef* USARTx, uint8_t *Data,...);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -47,7 +47,7 @@ void TIM6_IRQHandler(void)
|
|||
//计算车速,左轮和右轮速度和除以2 单位 m/min
|
||||
temp3 = (Encoder_Right + Encoder_Left) / 2*600/2496 *0.065*3.1415;
|
||||
sprintf(speed,"%2.2f",temp3);
|
||||
OLED_ShowString(48,0, (u8*)speed,16); //OLED显示车速
|
||||
//OLED_ShowString(48,0, (u8*)speed,16); //OLED显示车速
|
||||
|
||||
if(Encoder_Left < 0)//如果电机反转了
|
||||
{
|
||||
|
@ -81,12 +81,12 @@ void TIM6_IRQHandler(void)
|
|||
showPID();
|
||||
//显示左轮和右轮的输出转速 单位RPM
|
||||
temp1 = Encoder_Left*600/2496;
|
||||
OLED_ShowNum(56,2,temp1,3,12); //左轮实际减速箱输出转速 单位RPM
|
||||
//OLED_ShowNum(56,2,temp1,3,12); //左轮实际减速箱输出转速 单位RPM
|
||||
temp2 = Encoder_Right*600/2496;
|
||||
OLED_ShowNum(56,3,temp2,3,12); //右轮实际减速箱输出转速 单位RPM
|
||||
//OLED_ShowNum(56,3,temp2,3,12); //右轮实际减速箱输出转速 单位RPM
|
||||
|
||||
//设定值显示
|
||||
OLED_ShowNum(48,6,SetPoint,3,12); //显示设定的车轮转速 单位RPM
|
||||
//OLED_ShowNum(48,6,SetPoint,3,12); //显示设定的车轮转速 单位RPM
|
||||
//temp4 = SetPoint*3.1415*0.065; //计算设定的线速度
|
||||
//sprintf(set_speed,"%2.2f",temp4);
|
||||
//OLED_ShowString(48,7, set_speed,12); //设定的线速度 单位m/min
|
||||
|
|
|
@ -12,7 +12,7 @@ void Motor_Init(void)
|
|||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /*开启GPIO的外设时钟*/
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; /*选择要控制的GPIO引脚*/
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; /*选择要控制的GPIO引脚*/
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*设置引脚模式为通用推挽输出*/
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /*设置引脚速率为50MHz */
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure); /*调用库函数,初始化GPIO*/
|
||||
|
|
|
@ -1,302 +1,302 @@
|
|||
/******************** (C) COPYRIGHT 2023 GeekRebot *****************************
|
||||
* File Name : oled.c
|
||||
* Current Version : V1.0 & ST 3.5.0
|
||||
* Author : zhanli 719901725@qq.com
|
||||
* Date of Issued : 2024.01.09
|
||||
* Comments : oled的iic方式驱动
|
||||
SCL -> PA10,SDA -> PA11
|
||||
********************************************************************************/
|
||||
#include "oled.h"
|
||||
#include "stdlib.h"
|
||||
#include "oledfont.h"
|
||||
#include "delay.h"
|
||||
#include "bsp_iic.h"
|
||||
// OLED的显存
|
||||
// 存放格式如下.
|
||||
//[0]0 1 2 3 ... 127
|
||||
//[1]0 1 2 3 ... 127
|
||||
//[2]0 1 2 3 ... 127
|
||||
//[3]0 1 2 3 ... 127
|
||||
//[4]0 1 2 3 ... 127
|
||||
//[5]0 1 2 3 ... 127
|
||||
//[6]0 1 2 3 ... 127
|
||||
//[7]0 1 2 3 ... 127
|
||||
///******************** (C) COPYRIGHT 2023 GeekRebot *****************************
|
||||
//* File Name : oled.c
|
||||
//* Current Version : V1.0 & ST 3.5.0
|
||||
//* Author : zhanli 719901725@qq.com
|
||||
//* Date of Issued : 2024.01.09
|
||||
//* Comments : oled的iic方式驱动
|
||||
// SCL -> PA10,SDA -> PA11
|
||||
//********************************************************************************/
|
||||
//#include "oled.h"
|
||||
//#include "stdlib.h"
|
||||
//#include "oledfont.h"
|
||||
//#include "delay.h"
|
||||
//#include "bsp_iic.h"
|
||||
//// OLED的显存
|
||||
//// 存放格式如下.
|
||||
////[0]0 1 2 3 ... 127
|
||||
////[1]0 1 2 3 ... 127
|
||||
////[2]0 1 2 3 ... 127
|
||||
////[3]0 1 2 3 ... 127
|
||||
////[4]0 1 2 3 ... 127
|
||||
////[5]0 1 2 3 ... 127
|
||||
////[6]0 1 2 3 ... 127
|
||||
////[7]0 1 2 3 ... 127
|
||||
|
||||
void Write_IIC_Command(unsigned char IIC_Command)
|
||||
{
|
||||
IIC_Start();
|
||||
IIC_Send_Byte(0x78); // Slave address,SA0=0
|
||||
IIC_Wait_Ack();
|
||||
IIC_Send_Byte(0x00); // write command
|
||||
IIC_Wait_Ack();
|
||||
IIC_Send_Byte(IIC_Command);
|
||||
IIC_Wait_Ack();
|
||||
IIC_Stop();
|
||||
}
|
||||
/**********************************************
|
||||
// IIC Write Data
|
||||
**********************************************/
|
||||
void Write_IIC_Data(unsigned char IIC_Data)
|
||||
{
|
||||
IIC_Start();
|
||||
IIC_Send_Byte(0x78); // D/C#=0; R/W#=0
|
||||
IIC_Wait_Ack();
|
||||
IIC_Send_Byte(0x40); // write data
|
||||
IIC_Wait_Ack();
|
||||
IIC_Send_Byte(IIC_Data);
|
||||
IIC_Wait_Ack();
|
||||
IIC_Stop();
|
||||
}
|
||||
//void Write_IIC_Command(unsigned char IIC_Command)
|
||||
//{
|
||||
// IIC_Start();
|
||||
// IIC_Send_Byte(0x78); // Slave address,SA0=0
|
||||
// IIC_Wait_Ack();
|
||||
// IIC_Send_Byte(0x00); // write command
|
||||
// IIC_Wait_Ack();
|
||||
// IIC_Send_Byte(IIC_Command);
|
||||
// IIC_Wait_Ack();
|
||||
// IIC_Stop();
|
||||
//}
|
||||
///**********************************************
|
||||
//// IIC Write Data
|
||||
//**********************************************/
|
||||
//void Write_IIC_Data(unsigned char IIC_Data)
|
||||
//{
|
||||
// IIC_Start();
|
||||
// IIC_Send_Byte(0x78); // D/C#=0; R/W#=0
|
||||
// IIC_Wait_Ack();
|
||||
// IIC_Send_Byte(0x40); // write data
|
||||
// IIC_Wait_Ack();
|
||||
// IIC_Send_Byte(IIC_Data);
|
||||
// IIC_Wait_Ack();
|
||||
// IIC_Stop();
|
||||
//}
|
||||
|
||||
void OLED_WR_Byte(unsigned dat, unsigned cmd)
|
||||
{
|
||||
if (cmd)
|
||||
{
|
||||
Write_IIC_Data(dat);
|
||||
}
|
||||
else
|
||||
{
|
||||
Write_IIC_Command(dat);
|
||||
}
|
||||
}
|
||||
//void OLED_WR_Byte(unsigned dat, unsigned cmd)
|
||||
//{
|
||||
// if (cmd)
|
||||
// {
|
||||
// Write_IIC_Data(dat);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Write_IIC_Command(dat);
|
||||
// }
|
||||
//}
|
||||
|
||||
/********************************************
|
||||
// fill_Picture
|
||||
********************************************/
|
||||
void fill_picture(unsigned char fill_Data)
|
||||
{
|
||||
unsigned char m, n;
|
||||
for (m = 0; m < 8; m++)
|
||||
{
|
||||
OLED_WR_Byte(0xb0 + m, 0); // page0-page1
|
||||
OLED_WR_Byte(0x00, 0); // low column start address
|
||||
OLED_WR_Byte(0x10, 0); // high column start address
|
||||
for (n = 0; n < 128; n++)
|
||||
{
|
||||
OLED_WR_Byte(fill_Data, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
///********************************************
|
||||
//// fill_Picture
|
||||
//********************************************/
|
||||
//void fill_picture(unsigned char fill_Data)
|
||||
//{
|
||||
// unsigned char m, n;
|
||||
// for (m = 0; m < 8; m++)
|
||||
// {
|
||||
// OLED_WR_Byte(0xb0 + m, 0); // page0-page1
|
||||
// OLED_WR_Byte(0x00, 0); // low column start address
|
||||
// OLED_WR_Byte(0x10, 0); // high column start address
|
||||
// for (n = 0; n < 128; n++)
|
||||
// {
|
||||
// OLED_WR_Byte(fill_Data, 1);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
/***********************Delay****************************************/
|
||||
void Delay_50ms(unsigned int Del_50ms)
|
||||
{
|
||||
unsigned int m;
|
||||
for (; Del_50ms > 0; Del_50ms--)
|
||||
for (m = 6245; m > 0; m--);
|
||||
}
|
||||
///***********************Delay****************************************/
|
||||
//void Delay_50ms(unsigned int Del_50ms)
|
||||
//{
|
||||
// unsigned int m;
|
||||
// for (; Del_50ms > 0; Del_50ms--)
|
||||
// for (m = 6245; m > 0; m--);
|
||||
//}
|
||||
|
||||
void Delay_1ms(unsigned int Del_1ms)
|
||||
{
|
||||
unsigned char j;
|
||||
while (Del_1ms--)
|
||||
{
|
||||
for (j = 0; j < 123; j++);
|
||||
}
|
||||
}
|
||||
//void Delay_1ms(unsigned int Del_1ms)
|
||||
//{
|
||||
// unsigned char j;
|
||||
// while (Del_1ms--)
|
||||
// {
|
||||
// for (j = 0; j < 123; j++);
|
||||
// }
|
||||
//}
|
||||
|
||||
// 坐标设置
|
||||
//// 坐标设置
|
||||
|
||||
void OLED_Set_Pos(unsigned char x, unsigned char y)
|
||||
{
|
||||
OLED_WR_Byte(0xb0 + y, OLED_CMD);
|
||||
OLED_WR_Byte(((x & 0xf0) >> 4) | 0x10, OLED_CMD);
|
||||
OLED_WR_Byte((x & 0x0f), OLED_CMD);
|
||||
}
|
||||
// 开启OLED显示
|
||||
void OLED_Display_On(void)
|
||||
{
|
||||
OLED_WR_Byte(0X8D, OLED_CMD); // SET DCDC命令
|
||||
OLED_WR_Byte(0X14, OLED_CMD); // DCDC ON
|
||||
OLED_WR_Byte(0XAF, OLED_CMD); // DISPLAY ON
|
||||
}
|
||||
// 关闭OLED显示
|
||||
void OLED_Display_Off(void)
|
||||
{
|
||||
OLED_WR_Byte(0X8D, OLED_CMD); // SET DCDC命令
|
||||
OLED_WR_Byte(0X10, OLED_CMD); // DCDC OFF
|
||||
OLED_WR_Byte(0XAE, OLED_CMD); // DISPLAY OFF
|
||||
}
|
||||
//void OLED_Set_Pos(unsigned char x, unsigned char y)
|
||||
//{
|
||||
// OLED_WR_Byte(0xb0 + y, OLED_CMD);
|
||||
// OLED_WR_Byte(((x & 0xf0) >> 4) | 0x10, OLED_CMD);
|
||||
// OLED_WR_Byte((x & 0x0f), OLED_CMD);
|
||||
//}
|
||||
//// 开启OLED显示
|
||||
//void OLED_Display_On(void)
|
||||
//{
|
||||
// OLED_WR_Byte(0X8D, OLED_CMD); // SET DCDC命令
|
||||
// OLED_WR_Byte(0X14, OLED_CMD); // DCDC ON
|
||||
// OLED_WR_Byte(0XAF, OLED_CMD); // DISPLAY ON
|
||||
//}
|
||||
//// 关闭OLED显示
|
||||
//void OLED_Display_Off(void)
|
||||
//{
|
||||
// OLED_WR_Byte(0X8D, OLED_CMD); // SET DCDC命令
|
||||
// OLED_WR_Byte(0X10, OLED_CMD); // DCDC OFF
|
||||
// OLED_WR_Byte(0XAE, OLED_CMD); // DISPLAY OFF
|
||||
//}
|
||||
|
||||
// 清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!
|
||||
void OLED_Clear(void)
|
||||
{
|
||||
u8 i, n;
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
OLED_WR_Byte(0xb0 + i, OLED_CMD); // 设置页地址(0~7)
|
||||
OLED_WR_Byte(0x00, OLED_CMD); // 设置显示位置—列低地址
|
||||
OLED_WR_Byte(0x10, OLED_CMD); // 设置显示位置—列高地址
|
||||
for (n = 0; n < 128; n++)
|
||||
OLED_WR_Byte(0, OLED_DATA);
|
||||
} // 更新显示
|
||||
}
|
||||
//// 清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!
|
||||
//void OLED_Clear(void)
|
||||
//{
|
||||
// u8 i, n;
|
||||
// for (i = 0; i < 8; i++)
|
||||
// {
|
||||
// OLED_WR_Byte(0xb0 + i, OLED_CMD); // 设置页地址(0~7)
|
||||
// OLED_WR_Byte(0x00, OLED_CMD); // 设置显示位置—列低地址
|
||||
// OLED_WR_Byte(0x10, OLED_CMD); // 设置显示位置—列高地址
|
||||
// for (n = 0; n < 128; n++)
|
||||
// OLED_WR_Byte(0, OLED_DATA);
|
||||
// } // 更新显示
|
||||
//}
|
||||
|
||||
void OLED_On(void)
|
||||
{
|
||||
u8 i, n;
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
OLED_WR_Byte(0xb0 + i, OLED_CMD); // 设置页地址(0~7)
|
||||
OLED_WR_Byte(0x00, OLED_CMD); // 设置显示位置—列低地址
|
||||
OLED_WR_Byte(0x10, OLED_CMD); // 设置显示位置—列高地址
|
||||
for (n = 0; n < 128; n++)
|
||||
OLED_WR_Byte(1, OLED_DATA);
|
||||
} // 更新显示
|
||||
}
|
||||
// 在指定位置显示一个字符,包括部分字符
|
||||
// x:0~127
|
||||
// y:0~63
|
||||
// mode:0,反白显示;1,正常显示
|
||||
// size:选择字体 16/12
|
||||
void OLED_ShowChar(u8 x, u8 y, u8 chr, u8 Char_Size)
|
||||
{
|
||||
unsigned char c = 0, i = 0;
|
||||
c = chr - ' '; // 得到偏移后的值
|
||||
if (x > Max_Column - 1)
|
||||
{
|
||||
x = 0;
|
||||
y = y + 2;
|
||||
}
|
||||
if (Char_Size == 16)
|
||||
{
|
||||
OLED_Set_Pos(x, y);
|
||||
for (i = 0; i < 8; i++)
|
||||
OLED_WR_Byte(F8X16[c * 16 + i], OLED_DATA);
|
||||
OLED_Set_Pos(x, y + 1);
|
||||
for (i = 0; i < 8; i++)
|
||||
OLED_WR_Byte(F8X16[c * 16 + i + 8], OLED_DATA);
|
||||
}
|
||||
else
|
||||
{
|
||||
OLED_Set_Pos(x, y);
|
||||
for (i = 0; i < 6; i++)
|
||||
OLED_WR_Byte(F6x8[c][i], OLED_DATA);
|
||||
}
|
||||
}
|
||||
// m^n函数
|
||||
u32 oled_pow(u8 m, u8 n)
|
||||
{
|
||||
u32 result = 1;
|
||||
while (n--)
|
||||
result *= m;
|
||||
return result;
|
||||
}
|
||||
// 显示2个数字
|
||||
// x,y :起点坐标
|
||||
// len :数字的位数
|
||||
// size:字体大小
|
||||
// mode:模式 0,填充模式;1,叠加模式
|
||||
// num:数值(0~4294967295);
|
||||
void OLED_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 size2)
|
||||
{
|
||||
u8 t, temp;
|
||||
u8 enshow = 0;
|
||||
for (t = 0; t < len; t++)
|
||||
{
|
||||
temp = (num / oled_pow(10, len - t - 1)) % 10;
|
||||
if (enshow == 0 && t < (len - 1))
|
||||
{
|
||||
if (temp == 0)
|
||||
{
|
||||
OLED_ShowChar(x + (size2 / 2) * t, y, ' ', size2);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
enshow = 1;
|
||||
}
|
||||
OLED_ShowChar(x + (size2 / 2) * t, y, temp + '0', size2);
|
||||
}
|
||||
}
|
||||
// 显示一个字符号串
|
||||
void OLED_ShowString(u8 x, u8 y, u8 *chr, u8 Char_Size)
|
||||
{
|
||||
unsigned char j = 0;
|
||||
while (chr[j] != '\0')
|
||||
{
|
||||
OLED_ShowChar(x, y, chr[j], Char_Size);
|
||||
x += 8;
|
||||
if (x > 120)
|
||||
{
|
||||
x = 0;
|
||||
y += 2;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
// 显示汉字
|
||||
void OLED_ShowCHinese(u8 x, u8 y, u8 no)
|
||||
{
|
||||
u8 t, adder = 0;
|
||||
OLED_Set_Pos(x, y);
|
||||
for (t = 0; t < 16; t++)
|
||||
{
|
||||
OLED_WR_Byte(Hzk[2 * no][t], OLED_DATA);
|
||||
adder += 1;
|
||||
}
|
||||
OLED_Set_Pos(x, y + 1);
|
||||
for (t = 0; t < 16; t++)
|
||||
{
|
||||
OLED_WR_Byte(Hzk[2 * no + 1][t], OLED_DATA);
|
||||
adder += 1;
|
||||
}
|
||||
}
|
||||
/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
|
||||
void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[])
|
||||
{
|
||||
unsigned int j = 0;
|
||||
unsigned char x, y;
|
||||
if (y1 % 8 == 0)
|
||||
y = y1 / 8;
|
||||
else
|
||||
y = y1 / 8 + 1;
|
||||
for (y = y0; y < y1; y++)
|
||||
{
|
||||
OLED_Set_Pos(x0, y);
|
||||
for (x = x0; x < x1; x++)
|
||||
{
|
||||
OLED_WR_Byte(BMP[j++], OLED_DATA);
|
||||
}
|
||||
}
|
||||
}
|
||||
//void OLED_On(void)
|
||||
//{
|
||||
// u8 i, n;
|
||||
// for (i = 0; i < 8; i++)
|
||||
// {
|
||||
// OLED_WR_Byte(0xb0 + i, OLED_CMD); // 设置页地址(0~7)
|
||||
// OLED_WR_Byte(0x00, OLED_CMD); // 设置显示位置—列低地址
|
||||
// OLED_WR_Byte(0x10, OLED_CMD); // 设置显示位置—列高地址
|
||||
// for (n = 0; n < 128; n++)
|
||||
// OLED_WR_Byte(1, OLED_DATA);
|
||||
// } // 更新显示
|
||||
//}
|
||||
//// 在指定位置显示一个字符,包括部分字符
|
||||
//// x:0~127
|
||||
//// y:0~63
|
||||
//// mode:0,反白显示;1,正常显示
|
||||
//// size:选择字体 16/12
|
||||
//void OLED_ShowChar(u8 x, u8 y, u8 chr, u8 Char_Size)
|
||||
//{
|
||||
// unsigned char c = 0, i = 0;
|
||||
// c = chr - ' '; // 得到偏移后的值
|
||||
// if (x > Max_Column - 1)
|
||||
// {
|
||||
// x = 0;
|
||||
// y = y + 2;
|
||||
// }
|
||||
// if (Char_Size == 16)
|
||||
// {
|
||||
// OLED_Set_Pos(x, y);
|
||||
// for (i = 0; i < 8; i++)
|
||||
// OLED_WR_Byte(F8X16[c * 16 + i], OLED_DATA);
|
||||
// OLED_Set_Pos(x, y + 1);
|
||||
// for (i = 0; i < 8; i++)
|
||||
// OLED_WR_Byte(F8X16[c * 16 + i + 8], OLED_DATA);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// OLED_Set_Pos(x, y);
|
||||
// for (i = 0; i < 6; i++)
|
||||
// OLED_WR_Byte(F6x8[c][i], OLED_DATA);
|
||||
// }
|
||||
//}
|
||||
//// m^n函数
|
||||
//u32 oled_pow(u8 m, u8 n)
|
||||
//{
|
||||
// u32 result = 1;
|
||||
// while (n--)
|
||||
// result *= m;
|
||||
// return result;
|
||||
//}
|
||||
//// 显示2个数字
|
||||
//// x,y :起点坐标
|
||||
//// len :数字的位数
|
||||
//// size:字体大小
|
||||
//// mode:模式 0,填充模式;1,叠加模式
|
||||
//// num:数值(0~4294967295);
|
||||
//void OLED_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 size2)
|
||||
//{
|
||||
// u8 t, temp;
|
||||
// u8 enshow = 0;
|
||||
// for (t = 0; t < len; t++)
|
||||
// {
|
||||
// temp = (num / oled_pow(10, len - t - 1)) % 10;
|
||||
// if (enshow == 0 && t < (len - 1))
|
||||
// {
|
||||
// if (temp == 0)
|
||||
// {
|
||||
// OLED_ShowChar(x + (size2 / 2) * t, y, ' ', size2);
|
||||
// continue;
|
||||
// }
|
||||
// else
|
||||
// enshow = 1;
|
||||
// }
|
||||
// OLED_ShowChar(x + (size2 / 2) * t, y, temp + '0', size2);
|
||||
// }
|
||||
//}
|
||||
//// 显示一个字符号串
|
||||
//void OLED_ShowString(u8 x, u8 y, u8 *chr, u8 Char_Size)
|
||||
//{
|
||||
// unsigned char j = 0;
|
||||
// while (chr[j] != '\0')
|
||||
// {
|
||||
// OLED_ShowChar(x, y, chr[j], Char_Size);
|
||||
// x += 8;
|
||||
// if (x > 120)
|
||||
// {
|
||||
// x = 0;
|
||||
// y += 2;
|
||||
// }
|
||||
// j++;
|
||||
// }
|
||||
//}
|
||||
//// 显示汉字
|
||||
//void OLED_ShowCHinese(u8 x, u8 y, u8 no)
|
||||
//{
|
||||
// u8 t, adder = 0;
|
||||
// OLED_Set_Pos(x, y);
|
||||
// for (t = 0; t < 16; t++)
|
||||
// {
|
||||
// OLED_WR_Byte(Hzk[2 * no][t], OLED_DATA);
|
||||
// adder += 1;
|
||||
// }
|
||||
// OLED_Set_Pos(x, y + 1);
|
||||
// for (t = 0; t < 16; t++)
|
||||
// {
|
||||
// OLED_WR_Byte(Hzk[2 * no + 1][t], OLED_DATA);
|
||||
// adder += 1;
|
||||
// }
|
||||
//}
|
||||
///***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
|
||||
//void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[])
|
||||
//{
|
||||
// unsigned int j = 0;
|
||||
// unsigned char x, y;
|
||||
// if (y1 % 8 == 0)
|
||||
// y = y1 / 8;
|
||||
// else
|
||||
// y = y1 / 8 + 1;
|
||||
// for (y = y0; y < y1; y++)
|
||||
// {
|
||||
// OLED_Set_Pos(x0, y);
|
||||
// for (x = x0; x < x1; x++)
|
||||
// {
|
||||
// OLED_WR_Byte(BMP[j++], OLED_DATA);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// 初始化SSD1306
|
||||
void OLED_Init(void)
|
||||
{
|
||||
IIC_Init();
|
||||
Delay_ms(800);
|
||||
OLED_WR_Byte(0xAE, OLED_CMD); // Display off
|
||||
OLED_WR_Byte(0x00, OLED_CMD); // set low column address
|
||||
OLED_WR_Byte(0x10, OLED_CMD); // set high column address
|
||||
OLED_WR_Byte(0x40, OLED_CMD); // set start line address
|
||||
OLED_WR_Byte(0xB0, OLED_CMD); // set page address
|
||||
OLED_WR_Byte(0x81, OLED_CMD); // contract control
|
||||
OLED_WR_Byte(0xFF, OLED_CMD); // 128
|
||||
OLED_WR_Byte(0xA1, OLED_CMD); // set segment remap
|
||||
OLED_WR_Byte(0xA6, OLED_CMD); // normal / reverse
|
||||
OLED_WR_Byte(0xA8, OLED_CMD); // set multiplex ratio(1 to 64)
|
||||
OLED_WR_Byte(0x3F, OLED_CMD); // 1/32 duty
|
||||
OLED_WR_Byte(0xC8, OLED_CMD); // Com scan direction
|
||||
OLED_WR_Byte(0xD3, OLED_CMD); // Set display offset
|
||||
OLED_WR_Byte(0x00, OLED_CMD);
|
||||
//// 初始化SSD1306
|
||||
//void OLED_Init(void)
|
||||
//{
|
||||
// IIC_Init();
|
||||
// Delay_ms(800);
|
||||
// OLED_WR_Byte(0xAE, OLED_CMD); // Display off
|
||||
// OLED_WR_Byte(0x00, OLED_CMD); // set low column address
|
||||
// OLED_WR_Byte(0x10, OLED_CMD); // set high column address
|
||||
// OLED_WR_Byte(0x40, OLED_CMD); // set start line address
|
||||
// OLED_WR_Byte(0xB0, OLED_CMD); // set page address
|
||||
// OLED_WR_Byte(0x81, OLED_CMD); // contract control
|
||||
// OLED_WR_Byte(0xFF, OLED_CMD); // 128
|
||||
// OLED_WR_Byte(0xA1, OLED_CMD); // set segment remap
|
||||
// OLED_WR_Byte(0xA6, OLED_CMD); // normal / reverse
|
||||
// OLED_WR_Byte(0xA8, OLED_CMD); // set multiplex ratio(1 to 64)
|
||||
// OLED_WR_Byte(0x3F, OLED_CMD); // 1/32 duty
|
||||
// OLED_WR_Byte(0xC8, OLED_CMD); // Com scan direction
|
||||
// OLED_WR_Byte(0xD3, OLED_CMD); // Set display offset
|
||||
// OLED_WR_Byte(0x00, OLED_CMD);
|
||||
|
||||
OLED_WR_Byte(0xD5, OLED_CMD); // set osc division
|
||||
OLED_WR_Byte(0x80, OLED_CMD); //
|
||||
// OLED_WR_Byte(0xD5, OLED_CMD); // set osc division
|
||||
// OLED_WR_Byte(0x80, OLED_CMD); //
|
||||
|
||||
OLED_WR_Byte(0xD8, OLED_CMD); // set area color mode off
|
||||
OLED_WR_Byte(0x05, OLED_CMD); //
|
||||
// OLED_WR_Byte(0xD8, OLED_CMD); // set area color mode off
|
||||
// OLED_WR_Byte(0x05, OLED_CMD); //
|
||||
|
||||
OLED_WR_Byte(0xD9, OLED_CMD); // Set Pre-Charge Period
|
||||
OLED_WR_Byte(0xF1, OLED_CMD); //
|
||||
// OLED_WR_Byte(0xD9, OLED_CMD); // Set Pre-Charge Period
|
||||
// OLED_WR_Byte(0xF1, OLED_CMD); //
|
||||
|
||||
OLED_WR_Byte(0xDA, OLED_CMD); // set com pin configuartion
|
||||
OLED_WR_Byte(0x12, OLED_CMD); //
|
||||
// OLED_WR_Byte(0xDA, OLED_CMD); // set com pin configuartion
|
||||
// OLED_WR_Byte(0x12, OLED_CMD); //
|
||||
|
||||
OLED_WR_Byte(0xDB, OLED_CMD); // set Vcomh
|
||||
OLED_WR_Byte(0x30, OLED_CMD); //
|
||||
// OLED_WR_Byte(0xDB, OLED_CMD); // set Vcomh
|
||||
// OLED_WR_Byte(0x30, OLED_CMD); //
|
||||
|
||||
OLED_WR_Byte(0x8D, OLED_CMD); // set charge pump enable
|
||||
OLED_WR_Byte(0x14, OLED_CMD);
|
||||
// OLED_WR_Byte(0x8D, OLED_CMD); // set charge pump enable
|
||||
// OLED_WR_Byte(0x14, OLED_CMD);
|
||||
|
||||
OLED_WR_Byte(0xAF, OLED_CMD); // turn on oled panel
|
||||
}
|
||||
// OLED_WR_Byte(0xAF, OLED_CMD); // turn on oled panel
|
||||
//}
|
||||
|
|
|
@ -15,19 +15,19 @@ float Derivative = 0; //
|
|||
//显示pid参数到OLED上
|
||||
void showPID(void)
|
||||
{
|
||||
float temp1,temp2,temp3;
|
||||
char PID_P[3],PID_I[3],PID_D[3];
|
||||
temp1 = Proportion;
|
||||
sprintf(PID_P,"%1.1f",temp1);
|
||||
OLED_ShowString(16,4, (u8*)PID_P,16);
|
||||
// float temp1,temp2,temp3;
|
||||
// char PID_P[3],PID_I[3],PID_D[3];
|
||||
// temp1 = Proportion;
|
||||
// sprintf(PID_P,"%1.1f",temp1);
|
||||
// OLED_ShowString(16,4, (u8*)PID_P,16);
|
||||
|
||||
temp2 = Integral;
|
||||
sprintf(PID_I,"%1.1f",temp2);
|
||||
OLED_ShowString(56,4, (u8*)PID_I,16);
|
||||
// temp2 = Integral;
|
||||
// sprintf(PID_I,"%1.1f",temp2);
|
||||
// OLED_ShowString(56,4, (u8*)PID_I,16);
|
||||
|
||||
temp3 = Derivative;
|
||||
sprintf(PID_D,"%1.1f",temp3);
|
||||
OLED_ShowString(104,4, (u8*)PID_D,16);
|
||||
// temp3 = Derivative;
|
||||
// sprintf(PID_D,"%1.1f",temp3);
|
||||
// OLED_ShowString(104,4, (u8*)PID_D,16);
|
||||
}
|
||||
|
||||
/********************增量式PID控制设计************************************/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -565,11 +565,11 @@ ARM Macro Assembler Page 9
|
|||
00000000
|
||||
Command Line: --debug --xref --diag_suppress=9931 --cpu=Cortex-M3 --apcs=interw
|
||||
ork --depend=..\output\startup_stm32f10x_hd.d -o..\output\startup_stm32f10x_hd.
|
||||
o -I"D:\Hardware Project\GeBalanceBot\GeBalanceBot_Firmware v1.0\Project\RTE" -
|
||||
I"D:\Program Files\Keilv5\ARM\PACK\Keil\STM32F1xx_DFP\1.1.0\Device\Include" -I"
|
||||
D:\Program Files\Keilv5\ARM\CMSIS\Include" --predefine="__UVISION_VERSION SETA
|
||||
521" --predefine="STM32F10X_HD SETA 1" --list=..\listing\startup_stm32f10x_hd.l
|
||||
st ..\Libraries\CMSIS\startup\startup_stm32f10x_hd.s
|
||||
o -I"E:\HardwareProject\GeBalanceBot\GeBalanceBot_Firmware v1.0\Project\RTE" -I
|
||||
"D:\Program Files\Keilv5\ARM\PACK\Keil\STM32F1xx_DFP\1.1.0\Device\Include" -I"D
|
||||
:\Program Files\Keilv5\ARM\CMSIS\Include" --predefine="__UVISION_VERSION SETA 5
|
||||
21" --predefine="STM32F10X_HD SETA 1" --list=..\listing\startup_stm32f10x_hd.ls
|
||||
t ..\Libraries\CMSIS\startup\startup_stm32f10x_hd.s
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "MPU6050.h"
|
||||
#include "bluetooth.h"
|
||||
#include "IOI2C.h"
|
||||
#include "oled.h"
|
||||
#define PRINT_ACCEL (0x01)
|
||||
#define PRINT_GYRO (0x02)
|
||||
#define PRINT_QUAT (0x04)
|
||||
|
@ -73,7 +75,10 @@ static void run_self_test(void)
|
|||
accel[1] *= accel_sens;
|
||||
accel[2] *= accel_sens;
|
||||
dmp_set_accel_bias(accel);
|
||||
printf("setting bias succesfully ......\r\n");
|
||||
//printf("setting bias succesfully ......\r\n");
|
||||
PB_USART_printf(USART2, (u8*)"setting bias succesfully ......\r\n");
|
||||
}else{
|
||||
PB_USART_printf(USART2, (u8*)"Fail..\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,12 +292,15 @@ Output : none
|
|||
**************************************************************************/
|
||||
void MPU6050_initialize(void)
|
||||
{
|
||||
PB_USART_printf(USART2, (u8*)"run_self_test..\r\n");
|
||||
run_self_test();
|
||||
MPU6050_setClockSource(MPU6050_CLOCK_PLL_YGYRO); // 设置时钟
|
||||
MPU6050_setFullScaleGyroRange(MPU6050_GYRO_FS_2000); // 陀螺仪量程设置
|
||||
MPU6050_setFullScaleAccelRange(MPU6050_ACCEL_FS_2); // 加速度度最大量程 +-2G
|
||||
MPU6050_setSleepEnabled(0); // 进入工作状态
|
||||
MPU6050_setI2CMasterModeEnabled(0); // 不让MPU6050 控制AUXI2C
|
||||
MPU6050_setI2CBypassEnabled(0); // 主控制器的I2C与 MPU6050的AUXI2C 直通关闭
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -307,8 +315,13 @@ void DMP_Init(void)
|
|||
{
|
||||
u8 temp[1] = {0};
|
||||
i2cRead(0x68, 0x75, 1, temp);
|
||||
if (temp[0] != 0x68)
|
||||
NVIC_SystemReset();
|
||||
if (temp[0] != 0x68){
|
||||
//NVIC_SystemReset();
|
||||
PB_USART_printf(USART2, (u8*)"who am i %d\r\n", (int)temp[0]);
|
||||
}else{
|
||||
|
||||
}
|
||||
|
||||
if (!mpu_init())
|
||||
{
|
||||
if (!mpu_set_sensors(INV_XYZ_GYRO | INV_XYZ_ACCEL))
|
||||
|
|
|
@ -353,19 +353,25 @@
|
|||
|
||||
#define MPU6050_WHO_AM_I_BIT 6
|
||||
#define MPU6050_WHO_AM_I_LENGTH 6
|
||||
|
||||
extern short gyro[3], accel[3];
|
||||
extern int16_t Gx_offset,Gy_offset,Gz_offset;
|
||||
extern float Acc1G_Values;
|
||||
extern float Roll,Pitch;
|
||||
|
||||
//供外部调用的API
|
||||
void MPU6050_initialize(void); //初始化
|
||||
uint8_t MPU6050_testConnection(void); //检测MPU6050是否存在
|
||||
void MPU6050_initialize(void);
|
||||
// 检测MPU6050是否存在
|
||||
uint8_t MPU6050_testConnection(void);
|
||||
//读取ADC值
|
||||
void MPU6050_getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz);
|
||||
|
||||
void MPU6050_getlastMotion6(int16_t* ax, int16_t* ay,
|
||||
int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz);
|
||||
|
||||
uint8_t MPU6050_getDeviceID(void); //读取MPU6050的ID
|
||||
void MPU6050_InitGyro_Offset(void);//初始化陀螺仪偏置
|
||||
|
||||
void MPU6050_InitGyro_Offset(void);// 初始化陀螺仪偏置
|
||||
void DMP_Init(void);
|
||||
void Read_DMP(void);
|
||||
#endif
|
||||
|
|
|
@ -15,33 +15,33 @@
|
|||
*---------------------------------------------------------------------**/
|
||||
void oled_show(void)
|
||||
{
|
||||
// 显示屏打开
|
||||
OLED_Display_On();
|
||||
// 第一行显示小车模式
|
||||
OLED_ShowString(0,0,"DMP",12);
|
||||
OLED_ShowString(60,0,"Normal",12);
|
||||
// 第三行显示编码器1
|
||||
OLED_ShowString(00,20,"EncoLEFT",12);
|
||||
if( Encoder_Left<0){
|
||||
OLED_ShowString(80,20,"-",12);
|
||||
OLED_ShowNum(95,20,-Encoder_Left,3,12);
|
||||
}else{
|
||||
OLED_ShowString(80,20,"+",12);
|
||||
OLED_ShowNum(95,20, Encoder_Left,3,12);
|
||||
}
|
||||
|
||||
// 第四行显示编码器2
|
||||
OLED_ShowString(00,30,"EncoRIGHT",12);
|
||||
if(Encoder_Right<0){
|
||||
OLED_ShowString(80,30,"-",12);
|
||||
OLED_ShowNum(95,30,-Encoder_Right,3,12);
|
||||
}else{
|
||||
OLED_ShowString(80,30,"+",12);
|
||||
OLED_ShowNum(95,30, Encoder_Right,3,12);
|
||||
}
|
||||
|
||||
// 第六行显示角度
|
||||
OLED_ShowString(0,50,"Angle",12);
|
||||
// // 显示屏打开
|
||||
// OLED_Display_On();
|
||||
// // 第一行显示小车模式
|
||||
// OLED_ShowString(0,0,"DMP",12);
|
||||
// OLED_ShowString(60,0,"Normal",12);
|
||||
// // 第三行显示编码器1
|
||||
// OLED_ShowString(00,20,"EncoLEFT",12);
|
||||
// if( Encoder_Left<0){
|
||||
// OLED_ShowString(80,20,"-",12);
|
||||
// OLED_ShowNum(95,20,-Encoder_Left,3,12);
|
||||
// }else{
|
||||
// OLED_ShowString(80,20,"+",12);
|
||||
// OLED_ShowNum(95,20, Encoder_Left,3,12);
|
||||
// }
|
||||
//
|
||||
// // 第四行显示编码器2
|
||||
// OLED_ShowString(00,30,"EncoRIGHT",12);
|
||||
// if(Encoder_Right<0){
|
||||
// OLED_ShowString(80,30,"-",12);
|
||||
// OLED_ShowNum(95,30,-Encoder_Right,3,12);
|
||||
// }else{
|
||||
// OLED_ShowString(80,30,"+",12);
|
||||
// OLED_ShowNum(95,30, Encoder_Right,3,12);
|
||||
// }
|
||||
//
|
||||
// // 第六行显示角度
|
||||
// OLED_ShowString(0,50,"Angle",12);
|
||||
// if(Angle_Balance < 0){
|
||||
// OLED_ShowString(48,50,"-",12);
|
||||
// }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,7 +8,7 @@
|
|||
#include "bsp_sys.h"
|
||||
#include "stdio.h"
|
||||
#include "bluetooth.h"
|
||||
|
||||
#include "MPU6050.h"
|
||||
unsigned char BLE_RX[64];
|
||||
/**----------------------------------------------------------------------
|
||||
* Function : main
|
||||
|
@ -20,14 +20,17 @@ int main(void)
|
|||
{
|
||||
System_Init();
|
||||
Bluetooth_Init(9600);
|
||||
PB_USART_printf(USART2, (u8*)"Init Blue tooth..\r\n");
|
||||
Car_Stop();
|
||||
IIC_Init();
|
||||
PB_USART_printf(USART2, (u8*)"MPU6050_initialize..\r\n");
|
||||
MPU6050_initialize();
|
||||
DMP_Init();
|
||||
while (1)
|
||||
{
|
||||
Delay_ms(20);
|
||||
Delay_ms(10);
|
||||
USART2_Receive(BLE_RX, 6);
|
||||
|
||||
USART2_Send(BLE_RX, 6);
|
||||
//Delay_ms(500);
|
||||
|
||||
if((BLE_RX[3] == 0xB1)&&(BLE_RX[4]==0xB5))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue