|
stm32驅(qū)動麥克娜姆輪小車底層驅(qū)動原理圖和代碼
51hei.png (77.17 KB, 下載次數(shù): 50)
下載附件
2021-8-8 04:51 上傳
單片機(jī)源程序如下:
- #include "stm32f10x.h"
- #include "systick.h"
- #include "time3_out_pwm.h"
- #include "gear_motor.h"
- #include "usart1.h"
- #include "ADC.H"
- #include "speed_exit.h"
- #include "pid.h"
- #define DSwitch_B2 GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)
- #define DSwitch_B3 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_3)
- #define DSwitch_B4 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_4)
- #define DSwitch_B5 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)
- #define RunLED_0 GPIO_ResetBits(GPIOB,GPIO_Pin_9)
- #define RunLED_1 GPIO_SetBits(GPIOB,GPIO_Pin_9)
- #define LowLED_0 GPIO_ResetBits(GPIOB,GPIO_Pin_8)
- #define LowLED_1 GPIO_SetBits(GPIOB,GPIO_Pin_8)
- u32 BPS=9600;
- u8 DisSwitchNum=0;
- u8 CheckBetrry=0;
- extern unsigned int M1_Num;
- extern unsigned int M2_Num;
- extern unsigned int M3_Num;
- extern unsigned int M4_Num;
- void LED_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- RunLED_0;
- LowLED_1;
- }
- void RunLED_Flash(void)
- {
- static u8 sta=0;
- if (sta==1)
- {
- RunLED_1;
- sta=0;
- }
- else
- {
- RunLED_0;
- sta=1;
- CheckBetrry++;
- }
- }
- void LowPower(void)
- {
- static u8 num=0;
- u16 value=0;
- if (CheckBetrry>=50)
- {
- CheckBetrry=0;
- value=GetVolt();
-
- if (value<102)
- {
- num++;
- }
- else
- {
- num=0;
- }
-
- if (num>5)
- {
- LowLED_0;
- TIM_SetCompare1(TIM3,0);
- TIM_SetCompare2(TIM3,0);
- TIM_SetCompare3(TIM3,0);
- TIM_SetCompare4(TIM3,0);
- while(1);
- }
- }
- }
- void DIP_Switch_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- DisSwitchNum=DSwitch_B2;
- DisSwitchNum<<=1;
- DisSwitchNum+=DSwitch_B3;
- DisSwitchNum<<=1;
- DisSwitchNum+=DSwitch_B4;
- DisSwitchNum<<=1;
- DisSwitchNum+=DSwitch_B5;
- }
- void Selcet_CtrlMode(void)
- {
- switch (DisSwitchNum&0x03)
- {
- case 0:
- {
- BPS=4800;
- }break;
- case 1:
- {
- BPS=9600;
- }break;
- case 2:
- {
- BPS=38400;
- }break;
- case 3:
- {
- BPS=115200;
- }break;
- default:break;
- }
- Uart1_Configuration(BPS);
- }
- int main(void)
- {
- SystemInit();
- SysTick_Configuration();
- LED_GPIO_Init();
- DIP_Switch_GPIO_Init();
- Selcet_CtrlMode();
- PID_Init();
- Exit_Init();
- TIM3_PWM_Init();
- GearMotor_GPIO_init();
- Uart1_Configuration(BPS);
- ADC_InitConfiguration();
- if ((DisSwitchNum&0x0C)==0x04)
- {
- while(1)
- {
- UART1_Alone_HEX_Analysis();
- GearMotor_Analysis();
- LowPower();
- PID_Process();
- }
- }
- else if ((DisSwitchNum&0x0C)==0x00)
- {
- while(1)
- {
- UART1_Alone_ASC_Analysis();
- GearMotor_Analysis();
- LowPower();
- PID_Process();
- }
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有代碼51hei附件下載:
STM32代碼和原理圖.rar
(482.39 KB, 下載次數(shù): 84)
2021-8-7 22:00 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|