|
單片機(jī)源程序如下:
- # include "stm32f10x.h"
- # include "pwm.h"
- # include "motor.h"
- # include "csb.h"
- # include "delay.h"
- void NVIC_Configuration(void);
- vu32 Onward_flag=0; //前進(jìn)
- vu32 Left_flag=0; //左轉(zhuǎn)
- vu32 Right_flag=0; //右轉(zhuǎn)
- 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(); //前進(jìn)
- }
- else if(Backward_flag==1)
- {
- delay_us(30);
- Go_Backward(); //后退
- }
- else if(Left_flag==1)
- {
- delay_us(30);
- Go_Left(); //左轉(zhuǎn)
- }
- else if(Right_flag==1)
- {
- delay_us(30);
- Go_Right(); // 右轉(zhuǎn)
- }
- else
- {
- Stop(); //暫停
- }
- }
- }
-
- /*******************************************************************************
- * 函數(shù)名 : 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);
- }
復(fù)制代碼
所有資料51hei提供下載:
小車.rar
(280.83 KB, 下載次數(shù): 118)
2018-7-19 19:45 上傳
點(diǎn)擊文件名下載附件
小車
|
評(píng)分
-
查看全部評(píng)分
|