新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 移植ucosII到STM32F103ZE(六)

移植ucosII到STM32F103ZE(六)

作者: 時間:2016-11-25 來源:網(wǎng)絡(luò) 收藏
一、 例程測試:
1. 編寫includes.h文件
#ifndef __INCLUDES_H__
#define __INCLUDES_H__

//#include
//#include
//#include
//#include
//#include

#include
#include

#include "ucos_ii.h"

#include
#include

//#include

#endif

2. 編寫B(tài)sp.h和Bsp.c文件
Bsp.h文件,板級驅(qū)動文件。
#ifndef __BSP_H
#define __BSP_H

#define GPIO_PORT_LED GPIOF //根據(jù)自己板子情況修改
#define RCC_GPIO_PORT_LED RCC_APB2Periph_GPIOF //根據(jù)自己板子情況修改
#define GPIO_Pin_led1 GPIO_Pin_6 //根據(jù)自己板子情況修改
#define GPIO_Pin_led2 GPIO_Pin_7 //根據(jù)自己板子情況修改

#define LED1 0
#define LED2 1

void BSP_Init(void);
void led_on(uint32_t n);
void led_off(uint32_t n);

#endif
Bsp.c文件
#include

static void BSP_LED_Init(void);
// static void BSP_KEY_Init (void);

void BSP_Init (void)
{
SystemInit();
BSP_LED_Init();
// Init_Uart_on_Chip(9600);
// BSP_KEY_Init();
}

static void BSP_LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_GPIO_PORT_LED, ENABLE) ; //使能時鐘 //根據(jù)自己板子情況修改

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_led1|GPIO_Pin_led2; //根據(jù)自己板子情況修改
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIO_PORT_LED, &GPIO_InitStructure); //根據(jù)自己板子情況修改
}

void led_on(uint32_t n)
{
switch (n)
{
case LED1: GPIO_SetBits(GPIO_PORT_LED, GPIO_Pin_led1);
break;
case LED2: GPIO_SetBits(GPIO_PORT_LED, GPIO_Pin_led2);
break;
default:
break;
}
}
void led_off(uint32_t n)
{
switch (n)
{
case LED1: GPIO_ResetBits(GPIO_PORT_LED, GPIO_Pin_led1); break;
case LED2: GPIO_ResetBits(GPIO_PORT_LED, GPIO_Pin_led2); break;
default: break;
}
}
3. 編寫app_cfg.h和app.c文件
app_cfg.h

#define STARTUP_TASK_PRIO 4
#define LED1_TASK_PRIO 6


#define STARTUP_TASK_STK_SIZE 80

#define LED1_TASK_STK_SIZE 80
app.c文件
#include
static OS_STK startup_task_stk[STARTUP_TASK_STK_SIZE]; //開開辟任務(wù)堆棧
static OS_STK led1_task_stk[LED1_TASK_STK_SIZE ]; //開辟任務(wù)堆棧
static void systick_init(void); //函數(shù)聲明

static void systick_init(void)
{
RCC_ClocksTypeDef rcc_clocks;
RCC_GetClocksFreq(&rcc_clocks); //調(diào)用標(biāo)準(zhǔn)庫函數(shù),獲獲取系統(tǒng)時鐘。
SysTick_Config(rcc_clocks.HCLK_Frequency / OS_TICKS_PER_SEC); //初始化并使能 SysTick
//OS_TICKS_PPER_SEC 是在 os_cfg.h 中定義的
}

static void led1_task (void *p_arg)
{
p_arg=p_arg; //防止編譯器產(chǎn)生警告
while(1)
{

led_on(LED1);
OSTimeDlyHMSM(0,0,1,0); //1s 延時,釋放 CPU 控制權(quán)
led_off(LED1);
OSTimeDlyHMSM(0,0,1,0); //1s 延時,釋放 CPU 控制權(quán)
}
}

上一頁 1 2 下一頁

關(guān)鍵詞: 移植ucosIISTM32F103Z

評論


技術(shù)專區(qū)

關(guān)閉