stm32f103rc主控,具体看程序吧。这是初始程序,想要完整的私聊。
单片机源程序如下:
- #include "delay.h"
- #include "uart.h"
- #include "LobotServoController.h"
- #include "bool.h"
- #include "work.h"
- #include "lcd1602.h"
- #include "timer.h"
- #include "wave.h"
- #include "FreeRTOS.h"
- #include "task.h"
- #include "queue.h"
-
- //外设引脚
- /*
- 1602: -、+、-、pb15/pb14/pb13、pc0-pc7、+/-
- 超声波:trig pb5/echo pb6
- */
- extern u16 Distance;
- void vTask0_length( void *pvParameters) //测距任务
- {
- u8 i=0;
- while(1)
- {
- if(i==0)
- {
- GPIO_SetBits(GPIOB,GPIO_Pin_10); i=1;
- }
- else
- {
- GPIO_ResetBits(GPIOB,GPIO_Pin_10); i=0;
- }
- Wave_SRD_Strat();
- if(Distance>=200) Distance=200;
- //LCD1602_Show_Str(0,0,"Distance");
- //LCD1602_Show_num(0,9,Distance);
- vTaskDelay(300 / portTICK_RATE_MS);
- }
- }
- void vTask0_work( void *pvParameters) //机器人动作任务
- {
- u8 head=2;
- stop();
- hold();
- while(1)
- {
- if(Distance<=40) //先左边再右边测距,若都小于阈值,后退
- {
- if(head==2)
- {
- head_left(); head=1;
- }
- else if(head==1)
- {
- head_right(); head=3;
- }
- else
- {
- turn_back(); head_centre(); head=2;
- }
- }
- else
- {
- if(head==1)
- {
- turn_left(); head_centre(); head=2;
- }
- else if(head==2) ahead();
- else
- {
- turn_right(); head_centre(); head=2;
- }
- }
- vTaskDelay(300 / portTICK_RATE_MS);
- }
- }
- int main(void)
- {
- SystemInit();//系统时钟等初始化
- delay_init(); //延时初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uartInit(9600);//串口初始化为9600
- GPIO_Configuration();
- LCD1602_Init();
- Timer_SRD_Init(5000,7199);
- Wave_SRD_Init();
- xTaskCreate(vTask0_length,"length",200,NULL,1,NULL);
- xTaskCreate(vTask0_work,"work",200,NULL,2,NULL);
-
- vTaskStartScheduler(); //开启任务调度
- }
-
复制代码
初始化部分分享给大家,请多多指教:
sixfeet-robot初始.rar
(599.4 KB, 下载次数: 29)
|