first commit
这个提交包含在:
113
hardware/I2IC.c
普通文件
113
hardware/I2IC.c
普通文件
@ -0,0 +1,113 @@
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "Delay.h"
|
||||
void IIc_w_scl(uint8_t BitValue)
|
||||
{
|
||||
|
||||
GPIO_WriteBit(GPIOB,GPIO_Pin_10,(BitAction)BitValue);
|
||||
Delay_us(10);
|
||||
}
|
||||
|
||||
|
||||
void IIc_w_sda(uint8_t BitValue)
|
||||
{
|
||||
GPIO_WriteBit(GPIOB,GPIO_Pin_11,(BitAction)BitValue);
|
||||
Delay_us(10);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t IIc_r_sda(void)
|
||||
{
|
||||
|
||||
uint8_t BitValue;
|
||||
BitValue=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_11);
|
||||
Delay_us(10);
|
||||
|
||||
return BitValue;
|
||||
|
||||
}
|
||||
|
||||
void IIc_init(void)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
|
||||
|
||||
GPIO_InitTypeDef GPIO_INITstructure;
|
||||
GPIO_INITstructure.GPIO_Mode=GPIO_Mode_Out_OD;
|
||||
GPIO_INITstructure.GPIO_Pin=GPIO_Pin_10|GPIO_Pin_11;
|
||||
GPIO_INITstructure.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOB,&GPIO_INITstructure);
|
||||
|
||||
GPIO_SetBits(GPIOB,GPIO_Pin_10|GPIO_Pin_11);
|
||||
}
|
||||
|
||||
void IIc_Start(void)
|
||||
{
|
||||
IIc_w_sda(1);
|
||||
IIc_w_scl(1);
|
||||
IIc_w_sda(0);
|
||||
IIc_w_scl(0);
|
||||
}
|
||||
void IIc_stop(void)
|
||||
{
|
||||
IIc_w_sda(0);
|
||||
IIc_w_scl(1);
|
||||
IIc_w_sda(1);
|
||||
}
|
||||
|
||||
|
||||
void IIc_sendByte(uint8_t Byte)
|
||||
{
|
||||
uint8_t i;
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
IIc_w_sda(!!(Byte&(0x80>>i)));
|
||||
IIc_w_scl(1);
|
||||
IIc_w_scl(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t IIc_receivebyte(void)
|
||||
{
|
||||
uint8_t i,Byte=0x00;
|
||||
|
||||
IIc_w_sda(1);
|
||||
|
||||
for (i=0;i<8;i++)
|
||||
{
|
||||
IIc_w_scl(1);
|
||||
|
||||
if(IIc_r_sda()){Byte|=(0x80>>i);}
|
||||
|
||||
IIc_w_scl(0);
|
||||
|
||||
}
|
||||
return Byte;
|
||||
|
||||
}
|
||||
|
||||
void IIc_sendack(uint8_t Ackbit)
|
||||
{
|
||||
IIc_w_sda(Ackbit);
|
||||
IIc_w_scl(1);
|
||||
IIc_w_scl(0);
|
||||
}
|
||||
|
||||
uint8_t IIc_receiceAck(void)
|
||||
{
|
||||
uint8_t Ackbit;
|
||||
|
||||
IIc_w_sda(1);
|
||||
IIc_w_scl(1);
|
||||
Ackbit=IIc_r_sda();
|
||||
IIc_w_scl(0);
|
||||
return Ackbit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
15
hardware/I2IC.h
普通文件
15
hardware/I2IC.h
普通文件
@ -0,0 +1,15 @@
|
||||
#ifndef __IIC_H
|
||||
#define __IIC_H
|
||||
|
||||
uint8_t IIc_receiceAck(void);
|
||||
void IIc_sendack(uint8_t Ackbit);
|
||||
uint8_t IIc_receivebyte(void);
|
||||
void IIc_sendByte(uint8_t Byte);
|
||||
void IIc_Start(void);
|
||||
void IIc_init(void);
|
||||
uint8_t IIc_r_sda(void);
|
||||
void IIc_w_sda(uint8_t BitValue);
|
||||
void IIc_w_scl(uint8_t BitValue);
|
||||
void IIc_stop(void);
|
||||
|
||||
#endif
|
||||
107
hardware/MPU6050.c
普通文件
107
hardware/MPU6050.c
普通文件
@ -0,0 +1,107 @@
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "Delay.h"
|
||||
#include "I2IC.h"
|
||||
#include "MPU6050_reg.h"
|
||||
#define MPU6050_ADDRESS 0xD0
|
||||
|
||||
void MPU6050_BASe(uint8_t Regaddress)
|
||||
{
|
||||
IIc_Start();
|
||||
IIc_sendByte(MPU6050_ADDRESS);
|
||||
IIc_receiceAck();
|
||||
IIc_sendByte(Regaddress);
|
||||
IIc_receiceAck();
|
||||
|
||||
}
|
||||
|
||||
void MPU6050_writeReg(uint8_t Regaddress,uint8_t Data)
|
||||
{
|
||||
MPU6050_BASe( Regaddress);
|
||||
IIc_sendByte(Data);
|
||||
IIc_receiceAck();
|
||||
IIc_stop();
|
||||
}
|
||||
uint8_t MPU6050_readrag(uint8_t Regaddress)
|
||||
{
|
||||
uint8_t Data;
|
||||
MPU6050_BASe( Regaddress);
|
||||
IIc_Start();
|
||||
IIc_sendByte(MPU6050_ADDRESS|0x01);//最后的一位是读写位 现在写1 表示即将读取(默认是0)
|
||||
IIc_receiceAck();
|
||||
Data=IIc_receivebyte();//接受数据
|
||||
IIc_sendack(1);//写1表示非应答 表示停止进程 0是继续
|
||||
IIc_stop();
|
||||
|
||||
return Data;
|
||||
}
|
||||
|
||||
void MPU6050_INIT(void)
|
||||
{
|
||||
IIc_init();
|
||||
MPU6050_writeReg(MPU6050_PWR_MGMT_1 ,0x01);
|
||||
MPU6050_writeReg(MPU6050_PWR_MGMT_2 ,0x00);
|
||||
MPU6050_writeReg(MPU6050_SMPLRT_DIV ,0x09);
|
||||
MPU6050_writeReg(MPU6050_CONFIG , 0x06);
|
||||
MPU6050_writeReg(MPU6050_GYRO_CONFIG,0x18 );
|
||||
MPU6050_writeReg(MPU6050_ACCEL_CONFIG ,0x18);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t MPU6050_Getid(void)
|
||||
{
|
||||
|
||||
return MPU6050_readrag(MPU6050_WHO_AM_I);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MPU6050_getdata(int16_t *Accx,int16_t *Accy,int16_t *Accz
|
||||
,int16_t *gyrox,int16_t *gyroy,int16_t *gyroz)
|
||||
{
|
||||
uint8_t DAtaH,DataL;
|
||||
|
||||
DAtaH=MPU6050_readrag(MPU6050_ACCEL_XOUT_H);
|
||||
DataL=MPU6050_readrag(MPU6050_ACCEL_XOUT_L);
|
||||
*Accx=(DAtaH<<8)|DataL;
|
||||
|
||||
DAtaH=MPU6050_readrag(MPU6050_ACCEL_YOUT_H);
|
||||
DataL=MPU6050_readrag(MPU6050_ACCEL_YOUT_L);
|
||||
*Accy=(DAtaH<<8)|DataL;
|
||||
|
||||
DAtaH=MPU6050_readrag(MPU6050_ACCEL_ZOUT_H);
|
||||
DataL=MPU6050_readrag(MPU6050_ACCEL_ZOUT_L);
|
||||
*Accz=(DAtaH<<8)|DataL;
|
||||
|
||||
DAtaH=MPU6050_readrag(MPU6050_GYRO_XOUT_H);
|
||||
DataL=MPU6050_readrag(MPU6050_GYRO_XOUT_L);
|
||||
*gyrox=(DAtaH<<8)|DataL;
|
||||
|
||||
DAtaH=MPU6050_readrag(MPU6050_GYRO_YOUT_H);
|
||||
DataL=MPU6050_readrag(MPU6050_GYRO_YOUT_L);
|
||||
*gyroy=(DAtaH<<8)|DataL;
|
||||
|
||||
DAtaH=MPU6050_readrag(MPU6050_GYRO_ZOUT_H);
|
||||
DataL=MPU6050_readrag(MPU6050_GYRO_ZOUT_L);
|
||||
*gyroz=(DAtaH<<8)|DataL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
10
hardware/MPU6050.h
普通文件
10
hardware/MPU6050.h
普通文件
@ -0,0 +1,10 @@
|
||||
#ifndef __MPU6050_H
|
||||
#define __MPU6050_H
|
||||
|
||||
void MPU6050_INIT(void);
|
||||
uint8_t MPU6050_readrag(uint8_t Regaddress);
|
||||
void MPU6050_writeReg(uint8_t Regaddress,uint8_t Data);
|
||||
void MPU6050_BASe(uint8_t Regaddress);
|
||||
void MPU6050_getdata(int16_t *Accx,int16_t *Accy,int16_t *Accz
|
||||
,int16_t *gyrox,int16_t *gyroy,int16_t *gyroz);
|
||||
#endif
|
||||
28
hardware/MPU6050_reg.h
普通文件
28
hardware/MPU6050_reg.h
普通文件
@ -0,0 +1,28 @@
|
||||
#ifndef __MPU6050_REG_H
|
||||
#define __MPU6050_REG_H
|
||||
|
||||
#define MPU6050_SMPLRT_DIV 0x19
|
||||
#define MPU6050_CONFIG 0x1A
|
||||
#define MPU6050_GYRO_CONFIG 0x1B
|
||||
#define MPU6050_ACCEL_CONFIG 0x1C
|
||||
|
||||
#define MPU6050_ACCEL_XOUT_H 0x3B
|
||||
#define MPU6050_ACCEL_XOUT_L 0x3C
|
||||
#define MPU6050_ACCEL_YOUT_H 0x3D
|
||||
#define MPU6050_ACCEL_YOUT_L 0x3E
|
||||
#define MPU6050_ACCEL_ZOUT_H 0x3F
|
||||
#define MPU6050_ACCEL_ZOUT_L 0x40
|
||||
#define MPU6050_TEMP_OUT_H 0x41
|
||||
#define MPU6050_TEMP_OUT_L 0x42
|
||||
#define MPU6050_GYRO_XOUT_H 0x43
|
||||
#define MPU6050_GYRO_XOUT_L 0x44
|
||||
#define MPU6050_GYRO_YOUT_H 0x45
|
||||
#define MPU6050_GYRO_YOUT_L 0x46
|
||||
#define MPU6050_GYRO_ZOUT_H 0x47
|
||||
#define MPU6050_GYRO_ZOUT_L 0x48
|
||||
|
||||
#define MPU6050_PWR_MGMT_1 0x6B
|
||||
#define MPU6050_PWR_MGMT_2 0x6C
|
||||
#define MPU6050_WHO_AM_I 0x75
|
||||
|
||||
#endif
|
||||
60
hardware/PWM.c
普通文件
60
hardware/PWM.c
普通文件
@ -0,0 +1,60 @@
|
||||
#include "stm32f10x.h" // Device header
|
||||
// Device header
|
||||
void PWM_Init(void)
|
||||
{
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
|
||||
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_0|GPIO_Pin_1;
|
||||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOA,&GPIO_InitStructure);
|
||||
GPIO_Init(GPIOB,&GPIO_InitStructure);
|
||||
|
||||
TIM_InternalClockConfig(TIM3);
|
||||
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
|
||||
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
|
||||
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInitStructure.TIM_Period=20000-1;
|
||||
TIM_TimeBaseInitStructure.TIM_Prescaler=72-1;
|
||||
TIM_TimeBaseInitStructure.TIM_RepetitionCounter=0;
|
||||
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
|
||||
|
||||
TIM_OCInitTypeDef TIM_OCInitStructure;
|
||||
TIM_OCStructInit(&TIM_OCInitStructure);
|
||||
|
||||
TIM_OCInitStructure.TIM_OCMode= TIM_OCMode_PWM1;
|
||||
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
|
||||
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
|
||||
TIM_OCInitStructure.TIM_Pulse=0;
|
||||
|
||||
TIM_OC1Init(TIM3,&TIM_OCInitStructure);
|
||||
TIM_OC2Init(TIM3,&TIM_OCInitStructure);
|
||||
TIM_OC3Init(TIM3,&TIM_OCInitStructure);
|
||||
TIM_OC4Init(TIM3,&TIM_OCInitStructure);
|
||||
|
||||
|
||||
TIM_Cmd(TIM3,ENABLE);
|
||||
|
||||
}
|
||||
|
||||
void PWM_SetCompare1(uint16_t Compare)
|
||||
{
|
||||
|
||||
TIM_SetCompare1(TIM3,Compare);
|
||||
|
||||
}
|
||||
void PWM_SetCompare2(uint16_t Compare)
|
||||
{
|
||||
|
||||
TIM_SetCompare2(TIM3,Compare);
|
||||
|
||||
}
|
||||
void PWM_SetCompare3(uint16_t Compare)
|
||||
{
|
||||
|
||||
TIM_SetCompare3(TIM3,Compare);
|
||||
|
||||
}
|
||||
12
hardware/PWM.h
普通文件
12
hardware/PWM.h
普通文件
@ -0,0 +1,12 @@
|
||||
#ifndef __PWM_H
|
||||
#define __PWM_H
|
||||
|
||||
void PWM_Init(void);
|
||||
|
||||
void PWM_SetCompare1(uint16_t Compare);
|
||||
|
||||
void PWM_SetCompare2(uint16_t Compare);
|
||||
|
||||
void PWM_SetCompare3(uint16_t Compare);
|
||||
|
||||
#endif
|
||||
42
hardware/TimerInterrupt.c
普通文件
42
hardware/TimerInterrupt.c
普通文件
@ -0,0 +1,42 @@
|
||||
#include "stm32f10x.h" // Device header
|
||||
|
||||
void Timer_Init(void)
|
||||
{
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
|
||||
|
||||
TIM_InternalClockConfig(TIM2);
|
||||
|
||||
TIM_TimeBaseInitTypeDef TIMBaseInitStruct;
|
||||
TIMBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;
|
||||
TIMBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
|
||||
TIMBaseInitStruct.TIM_Period=10000-1;
|
||||
TIMBaseInitStruct.TIM_Prescaler=7200-1;
|
||||
TIMBaseInitStruct.TIM_RepetitionCounter=0;
|
||||
TIM_TimeBaseInit(TIM2,&TIMBaseInitStruct);
|
||||
|
||||
TIM_ClearFlag(TIM2,TIM_FLAG_Update);
|
||||
TIM_ITConfig(TIM2,TIM_FLAG_Update,ENABLE);
|
||||
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||||
|
||||
NVIC_InitTypeDef NVICtypedefStructure;
|
||||
NVICtypedefStructure.NVIC_IRQChannel=TIM2_IRQn;
|
||||
NVICtypedefStructure.NVIC_IRQChannelCmd=ENABLE;
|
||||
NVICtypedefStructure.NVIC_IRQChannelPreemptionPriority=1;
|
||||
NVICtypedefStructure.NVIC_IRQChannelSubPriority=1;
|
||||
NVIC_Init(&NVICtypedefStructure);
|
||||
|
||||
TIM_Cmd(TIM2,ENABLE);
|
||||
}
|
||||
|
||||
//void TIM2_IRQHander(void)
|
||||
//{
|
||||
//if(TIM_GetITStatus(TIM2,TIM_IT_Update)==SET)
|
||||
//{
|
||||
//Num++;
|
||||
//TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
|
||||
//}
|
||||
|
||||
|
||||
//}
|
||||
4
hardware/TimerInterrupt.h
普通文件
4
hardware/TimerInterrupt.h
普通文件
@ -0,0 +1,4 @@
|
||||
#ifndef __TimerInterrupt_H
|
||||
#define __TimerInterrupt_H
|
||||
void Timer_Init(void);
|
||||
#endif
|
||||
112
hardware/UTRANS.c
普通文件
112
hardware/UTRANS.c
普通文件
@ -0,0 +1,112 @@
|
||||
#include "stm32f10x.h" // Device header
|
||||
|
||||
uint8_t Serial_RxData;
|
||||
uint8_t Serial_RxFlag;
|
||||
|
||||
void Serial_Init(void)
|
||||
{
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
|
||||
|
||||
GPIO_InitTypeDef USARTGPIO1;
|
||||
USARTGPIO1.GPIO_Mode=GPIO_Mode_AF_PP;
|
||||
USARTGPIO1.GPIO_Pin=GPIO_Pin_10;
|
||||
USARTGPIO1.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
|
||||
GPIO_Init(GPIOB,&USARTGPIO1);
|
||||
|
||||
GPIO_InitTypeDef USARTGPIO2;
|
||||
USARTGPIO2.GPIO_Mode=GPIO_Mode_IPU;
|
||||
USARTGPIO2.GPIO_Pin=GPIO_Pin_11;
|
||||
USARTGPIO2.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
|
||||
GPIO_Init(GPIOB,&USARTGPIO2);
|
||||
|
||||
USART_InitTypeDef usartype;
|
||||
usartype.USART_BaudRate=9600;
|
||||
usartype.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
|
||||
usartype.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
|
||||
usartype.USART_Parity=USART_Parity_No;
|
||||
usartype.USART_StopBits=USART_StopBits_1;
|
||||
usartype.USART_WordLength=USART_WordLength_8b;
|
||||
USART_Init(USART3,&usartype);
|
||||
|
||||
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
|
||||
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||||
|
||||
NVIC_InitTypeDef NVICYTPE;
|
||||
NVICYTPE.NVIC_IRQChannel=USART3_IRQn;
|
||||
NVICYTPE.NVIC_IRQChannelCmd=ENABLE;
|
||||
NVICYTPE.NVIC_IRQChannelPreemptionPriority=2;
|
||||
NVICYTPE.NVIC_IRQChannelSubPriority=1;
|
||||
NVIC_Init(&NVICYTPE);
|
||||
|
||||
USART_Cmd(USART3,ENABLE);
|
||||
|
||||
}
|
||||
|
||||
void serial_sendByte(uint8_t Byte)
|
||||
{
|
||||
|
||||
USART_SendData(USART3,Byte);
|
||||
while(USART_GetFlagStatus(USART3,USART_FLAG_TXE)==RESET);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void serial_senstring(char* String)
|
||||
{
|
||||
uint8_t i;
|
||||
for(i=0;String[i];i++)
|
||||
{
|
||||
serial_sendByte(String[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// <20>ֶ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
void int_to_char_array(int num, char* buffer) {
|
||||
char temp[12]; // <20><>ʱ<EFBFBD><CAB1><EFBFBD>飬int<6E><74><EFBFBD><EFBFBD>11λ+<2B><><EFBFBD><EFBFBD>
|
||||
int i = 0, j = 0;
|
||||
int is_negative = 0;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (num < 0) {
|
||||
is_negative = 1;
|
||||
num = -num;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (num == 0) {
|
||||
temp[i++] = '0';
|
||||
} else {
|
||||
// <20>ӵ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
while (num > 0) {
|
||||
temp[i++] = '0' + (num % 10); // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>һλ<D2BB><CEBB><EFBFBD><EFBFBD>
|
||||
num = num / 10; // ȥ<><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һλ
|
||||
}
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD>
|
||||
if (is_negative) {
|
||||
temp[i++] = '-';
|
||||
}
|
||||
|
||||
// <20><>ת<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ģ<EFBFBD>
|
||||
for (j = 0; j < i; j++) {
|
||||
buffer[j] = temp[i - j - 1];
|
||||
}
|
||||
buffer[j] = '\0'; // <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetITStatus(USART3, USART_IT_RXNE) == SET)
|
||||
{
|
||||
Serial_RxData = USART_ReceiveData(USART3);
|
||||
Serial_RxFlag = 1;
|
||||
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
|
||||
}
|
||||
}
|
||||
|
||||
10
hardware/UTRANS.h
普通文件
10
hardware/UTRANS.h
普通文件
@ -0,0 +1,10 @@
|
||||
#ifndef __UTRANS_H
|
||||
#define __UTRANS_H
|
||||
|
||||
void Serial_Init(void);
|
||||
void serial_sendByte(uint8_t Byte);
|
||||
void serial_senstring(char* String);
|
||||
void int_to_char_array(int num, char* buffer);
|
||||
|
||||
#endif
|
||||
|
||||
303
hardware/jointpos.c
普通文件
303
hardware/jointpos.c
普通文件
@ -0,0 +1,303 @@
|
||||
#include "stm32f10x.h" // Device header
|
||||
|
||||
int16_t datlaAction0;
|
||||
int16_t datlaAction1;
|
||||
int16_t datlaAction2;
|
||||
int16_t datlaAction3;
|
||||
int16_t datlaAction4;
|
||||
int16_t datlaAction5;
|
||||
|
||||
void jOINT_INIT(void)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
|
||||
|
||||
GPIO_InitTypeDef JOINt_init;
|
||||
JOINt_init.GPIO_Mode=GPIO_Mode_IPU;
|
||||
JOINt_init.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13;
|
||||
JOINt_init.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
|
||||
GPIO_Init(GPIOA,&JOINt_init);
|
||||
|
||||
|
||||
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource1 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource2 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource3 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource4 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource5 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource6 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource7 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource10 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource11 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource12 );
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource13 );
|
||||
|
||||
EXTI_InitTypeDef JOintP;
|
||||
JOintP.EXTI_Line=EXTI_Line0|EXTI_Line1|EXTI_Line2|EXTI_Line3|EXTI_Line4|EXTI_Line5|EXTI_Line6|EXTI_Line7|EXTI_Line10|EXTI_Line11|EXTI_Line12|EXTI_Line13;
|
||||
JOintP.EXTI_LineCmd=ENABLE;
|
||||
JOintP.EXTI_Mode=EXTI_Mode_Interrupt;
|
||||
JOintP.EXTI_Trigger=EXTI_Trigger_Falling;
|
||||
EXTI_Init(&JOintP);
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||||
|
||||
NVIC_InitTypeDef JOintPro0;
|
||||
JOintPro0.NVIC_IRQChannel=EXTI0_IRQn;
|
||||
JOintPro0.NVIC_IRQChannelCmd=ENABLE;
|
||||
JOintPro0.NVIC_IRQChannelPreemptionPriority=1;
|
||||
JOintPro0.NVIC_IRQChannelSubPriority=1;
|
||||
NVIC_Init(&JOintPro0);
|
||||
|
||||
NVIC_InitTypeDef JOintPro1;
|
||||
JOintPro1.NVIC_IRQChannel=EXTI1_IRQn;
|
||||
JOintPro1.NVIC_IRQChannelCmd=ENABLE;
|
||||
JOintPro1.NVIC_IRQChannelPreemptionPriority=1;
|
||||
JOintPro1.NVIC_IRQChannelSubPriority=2;
|
||||
NVIC_Init(&JOintPro1);
|
||||
|
||||
NVIC_InitTypeDef JOintPro2;
|
||||
JOintPro2.NVIC_IRQChannel=EXTI2_IRQn;
|
||||
JOintPro2.NVIC_IRQChannelCmd=ENABLE;
|
||||
JOintPro2.NVIC_IRQChannelPreemptionPriority=1;
|
||||
JOintPro2.NVIC_IRQChannelSubPriority=1;
|
||||
NVIC_Init(&JOintPro2);
|
||||
|
||||
NVIC_InitTypeDef JOintPro3;
|
||||
JOintPro3.NVIC_IRQChannel=EXTI3_IRQn;
|
||||
JOintPro3.NVIC_IRQChannelCmd=ENABLE;
|
||||
JOintPro3.NVIC_IRQChannelPreemptionPriority=1;
|
||||
JOintPro3.NVIC_IRQChannelSubPriority=2;
|
||||
NVIC_Init(&JOintPro3);
|
||||
|
||||
NVIC_InitTypeDef JOintPro4;
|
||||
JOintPro4.NVIC_IRQChannel=EXTI4_IRQn;
|
||||
JOintPro4.NVIC_IRQChannelCmd=ENABLE;
|
||||
JOintPro4.NVIC_IRQChannelPreemptionPriority=1;
|
||||
JOintPro4.NVIC_IRQChannelSubPriority=1;
|
||||
NVIC_Init(&JOintPro4);
|
||||
|
||||
NVIC_InitTypeDef JOintPro5;
|
||||
JOintPro5.NVIC_IRQChannel=EXTI9_5_IRQn;
|
||||
JOintPro5.NVIC_IRQChannelCmd=ENABLE;
|
||||
JOintPro5.NVIC_IRQChannelPreemptionPriority=1;
|
||||
JOintPro5.NVIC_IRQChannelSubPriority=2;
|
||||
NVIC_Init(&JOintPro5);
|
||||
|
||||
NVIC_InitTypeDef JOintPro6;
|
||||
JOintPro6.NVIC_IRQChannel=EXTI15_10_IRQn;
|
||||
JOintPro6.NVIC_IRQChannelCmd=ENABLE;
|
||||
JOintPro6.NVIC_IRQChannelPreemptionPriority=1;
|
||||
JOintPro6.NVIC_IRQChannelSubPriority=2;
|
||||
NVIC_Init(&JOintPro6);
|
||||
|
||||
}
|
||||
|
||||
int16_t Joint_delta0(void)
|
||||
{
|
||||
|
||||
int16_t temp0;
|
||||
temp0=datlaAction0;
|
||||
datlaAction0=0;
|
||||
|
||||
return temp0;
|
||||
|
||||
}
|
||||
|
||||
int16_t Joint_delta1(void)
|
||||
{
|
||||
|
||||
int16_t temp1;
|
||||
temp1=datlaAction1;
|
||||
datlaAction1=0;
|
||||
|
||||
return temp1;
|
||||
|
||||
}
|
||||
|
||||
int16_t Joint_delta2(void)
|
||||
{
|
||||
|
||||
int16_t temp2;
|
||||
temp2=datlaAction2;
|
||||
datlaAction2=0;
|
||||
|
||||
return temp2;
|
||||
|
||||
}
|
||||
|
||||
int16_t Joint_delta3(void)
|
||||
{
|
||||
|
||||
int16_t temp3;
|
||||
temp3=datlaAction3;
|
||||
datlaAction3=0;
|
||||
|
||||
return temp3;
|
||||
|
||||
}
|
||||
|
||||
int16_t Joint_delta4(void)
|
||||
{
|
||||
|
||||
int16_t temp4;
|
||||
temp4=datlaAction4;
|
||||
datlaAction4=0;
|
||||
|
||||
return temp4;
|
||||
|
||||
}
|
||||
|
||||
int16_t Joint_delta5(void)
|
||||
{
|
||||
|
||||
int16_t temp5;
|
||||
temp5=datlaAction5;
|
||||
datlaAction5=0;
|
||||
|
||||
return temp5;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EXTI0_IRQHandler(void)
|
||||
{
|
||||
if(EXTI_GetITStatus(EXTI_Line0)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1) == 0){datlaAction0--;}}
|
||||
|
||||
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void EXTI1_IRQHandler(void)
|
||||
{
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line1)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0){datlaAction0++;}}
|
||||
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void EXTI2_IRQHandler(void)
|
||||
{
|
||||
if(EXTI_GetITStatus(EXTI_Line2)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_2) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_3) == 0){datlaAction1--;}}
|
||||
|
||||
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void EXTI3_IRQHandler(void)
|
||||
{
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line3)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_3) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_2) == 0){datlaAction1++;}}
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void EXTI4_IRQHandler(void)
|
||||
{
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line4)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5) == 0){datlaAction2--;}}
|
||||
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line4);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void EXTI9_5_IRQHandler(void)
|
||||
{
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line5)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4) == 0){datlaAction2++;}}
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line5);
|
||||
}
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line6)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_7) == 0){datlaAction3--;}}
|
||||
EXTI_ClearITPendingBit(EXTI_Line6);
|
||||
}
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line7)==SET)
|
||||
{
|
||||
|
||||
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_7) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6) == 0){datlaAction3++;}}
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line7);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line10)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_10) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11) == 0){datlaAction4--;}}
|
||||
EXTI_ClearITPendingBit(EXTI_Line10);
|
||||
}
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line11)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_10) == 0){datlaAction4++;}}
|
||||
EXTI_ClearITPendingBit(EXTI_Line11);
|
||||
}
|
||||
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line12)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_12) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_13) == 0){datlaAction5--;}}
|
||||
EXTI_ClearITPendingBit(EXTI_Line12);
|
||||
}
|
||||
|
||||
if(EXTI_GetITStatus(EXTI_Line13)==SET)
|
||||
{
|
||||
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_13) == 0)
|
||||
{if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_12) == 0){datlaAction5++;}}
|
||||
EXTI_ClearITPendingBit(EXTI_Line13);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
30
hardware/jointpos.h
普通文件
30
hardware/jointpos.h
普通文件
@ -0,0 +1,30 @@
|
||||
#ifndef __JOINTPOS_H
|
||||
#define __JOINTPOS_H
|
||||
|
||||
extern int16_t datlaAction0;
|
||||
|
||||
extern int16_t datlaAction1;
|
||||
|
||||
extern int16_t datlaAction2;
|
||||
|
||||
extern int16_t datlaAction3;
|
||||
|
||||
extern int16_t datlaAction4;
|
||||
|
||||
extern int16_t datlaAction5;
|
||||
|
||||
void jOINT_INIT(void);
|
||||
|
||||
int16_t Joint_delta0(void);
|
||||
|
||||
int16_t Joint_delta1(void);
|
||||
|
||||
int16_t Joint_delta2(void);
|
||||
|
||||
int16_t Joint_delta3(void);
|
||||
|
||||
int16_t Joint_delta4(void);
|
||||
|
||||
int16_t Joint_delta5(void);
|
||||
|
||||
#endif
|
||||
17
hardware/servo.c
普通文件
17
hardware/servo.c
普通文件
@ -0,0 +1,17 @@
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "PWM.h"
|
||||
|
||||
void Servo_Init(void)
|
||||
{
|
||||
|
||||
PWM_Init();
|
||||
|
||||
}
|
||||
|
||||
void Servo_SetAngle(float Angle)
|
||||
{
|
||||
|
||||
PWM_SetCompare1(Angle/180*2000+500);
|
||||
|
||||
}
|
||||
|
||||
7
hardware/servo.h
普通文件
7
hardware/servo.h
普通文件
@ -0,0 +1,7 @@
|
||||
#ifndef __SERVO_H
|
||||
#define __SERVO_H
|
||||
|
||||
void Servo_Init(void);
|
||||
void Servo_SetAngle(float Angle);
|
||||
|
||||
#endif
|
||||
在新工单中引用
屏蔽一个用户