单片机源程序如下:
- # include "stm32f10x.h"
- # include "pwm.h"
- # include "motor.h"
- # include "csb.h"
- # include "delay.h"
- void NVIC_Configuration(void);
- vu32 Onward_flag=0; //前进
- vu32 Left_flag=0; //左转
- vu32 Right_flag=0; //右转
- vu32 Backward_flag=0; // 后退
- vu32 Stop_flag=0; //停止
- int main(void)
- {
- NVIC_Configuration();
- GPIO_Configuration();
- TIM2_Configuration(700,700);
- delay_us(50);
- while(1)
- {
- if(Onward_flag==1)
- {
- Go_Forward(); //前进
- }
- else if(Backward_flag==1)
- {
- delay_us(30);
- Go_Backward(); //后退
- }
- else if(Left_flag==1)
- {
- delay_us(30);
- Go_Left(); //左转
- }
- else if(Right_flag==1)
- {
- delay_us(30);
- Go_Right(); // 右转
- }
- else
- {
- Stop(); //暂停
- }
- }
- }
-
- /*******************************************************************************
- * 函数名 : NVIC_Configuration
- * 描述 : 初始化NVIC
- * 输入 : 无
- * 输出 : 无
- * 返回 : 无
- *******************************************************************************/
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- /* Configure the Priority Group to 2 bits */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
-
- NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn ; // Enable the DMA_Channel5 Interrupt
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
复制代码
所有资料51hei提供下载:
小车.rar
(280.83 KB, 下载次数: 118)
|