新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 移植ucosII到STM32F103ZE(六)

        移植ucosII到STM32F103ZE(六)

        作者: 時間:2016-11-25 來源:網絡 收藏
        一、 例程測試:
        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. 編寫Bsp.h和Bsp.c文件
        Bsp.h文件,板級驅動文件。
        #ifndef __BSP_H
        #define __BSP_H

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

        #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) ; //使能時鐘 //根據自己板子情況修改

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

        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]; //開開辟任務堆棧
        static OS_STK led1_task_stk[LED1_TASK_STK_SIZE ]; //開辟任務堆棧
        static void systick_init(void); //函數聲明

        static void systick_init(void)
        {
        RCC_ClocksTypeDef rcc_clocks;
        RCC_GetClocksFreq(&rcc_clocks); //調用標準庫函數,獲獲取系統時鐘。
        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; //防止編譯器產生警告
        while(1)
        {

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

        上一頁 1 2 下一頁

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 南昌县| 乡宁县| 武义县| 闽清县| 新丰县| 融水| 佳木斯市| 临颍县| 崇州市| 彭州市| 正宁县| 科技| 高邑县| 昆山市| 丹阳市| 徐水县| 甘德县| 龙里县| 基隆市| 保山市| 旌德县| 乳源| 宁津县| 永清县| 县级市| 伊金霍洛旗| 肇源县| 玛多县| 沭阳县| 麻城市| 昌黎县| 蒙城县| 渝北区| 香港 | 潞西市| 大石桥市| 平舆县| 安西县| 蒙自县| 凤山市| 旬邑县|