STM32F407和F103 华为liteos源码,可以运行基本功能。在此基础上进行修改。
实验器材:
MiniSTM32F103开发板V3版本
实验目的:
学习GPIO作为输出的使用
硬件资源:
1,DS0(连接在PA8)
2,DS1(连接在PD2)
实验现象:
本实验通过代码控制开发板上的两个LED:DS0和DS1交替闪烁,实现类似跑马灯的效果。
注意事项:
无.
stm32单片机源程序:
- #include "main.h"
- UINT32 g_TestTskHandle;
- void hardware_init(void)
- {
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- uart_init(115200); //初始化串口波特率115200
- LED_Init(); //初始化LED
- OLED_Init(); //初始化OLED
- OLED_Clear();
- EXIT_KEY_Init();
- LOS_HwiCreate(7,0,0,EXTI1_IRQHandler,NULL);//创建中断
- LOS_HwiCreate(8,0,0,EXTI2_IRQHandler,NULL);//创建中断
- LOS_HwiCreate(9,0,0,EXTI3_IRQHandler,NULL);//创建中断
- }
- VOID task1(void)
- {
- UINT32 uwRet = LOS_OK;
- UINT32 count=0;
- while(1)
- {
- count++;
- printf("This is task 1,count is %d\r\n",count);
- LED0=~LED0;
- uwRet = LOS_TaskDelay(1000);
- if(uwRet !=LOS_OK)
- return;
- }
- }
- UINT32 creat_task1(void)
- {
- UINT32 uwRet = LOS_OK;
- TSK_INIT_PARAM_S task_init_param;
- task_init_param.usTaskPrio = 3;
- task_init_param.pcName = "task1";
- task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)task1;
- task_init_param.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
- task_init_param.uwResved = LOS_TASK_STATUS_DETACHED;
- uwRet = LOS_TaskCreate(&g_TestTskHandle,&task_init_param);
- if(uwRet !=LOS_OK)
- {
- return uwRet;
- }
- return uwRet;
- }
- VOID task2(void)
- {
- UINT32 uwRet = LOS_OK;
- UINT32 count=0;
- while(1)
- {
- count++;
- printf("This is task 2,count is %d\r\n",count);
- LED1=~LED1;
- uwRet = LOS_TaskDelay(1000);
- if(uwRet !=LOS_OK)
- return;
- }
- }
- UINT32 creat_task2(void)
- {
- UINT32 uwRet = LOS_OK;
- TSK_INIT_PARAM_S task_init_param;
- task_init_param.usTaskPrio = 5;
- task_init_param.pcName = "task2";
- task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)task2;
- task_init_param.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
- task_init_param.uwResved = LOS_TASK_STATUS_DETACHED;
- uwRet = LOS_TaskCreate(&g_TestTskHandle,&task_init_param);
- if(uwRet !=LOS_OK)
- {
- return uwRet;
- }
- return uwRet;
- }
- VOID task3(void)
- {
- UINT32 uwRet = LOS_OK;
- UINT32 count=100;
- u8 t;
- while(1)
- {
- OLED_Clear();
- OLED_ShowCHinese(0,0,0);//中
- OLED_ShowCHinese(18,0,1);//景
- OLED_ShowCHinese(36,0,2);//园
- OLED_ShowCHinese(54,0,3);//电
- OLED_ShowCHinese(72,0,4);//子
- OLED_ShowCHinese(90,0,5);//科
- OLED_ShowCHinese(108,0,6);//技
- OLED_ShowString(0,3,"1.3' OLED TEST");
- OLED_ShowString(0,6,"ASCII:");
- OLED_ShowString(63,6,"CODE:");
- OLED_ShowChar(48,6,t);//显示ASCII字符
- t++;
- if(t>'~')t=' ';
- OLED_ShowNum(103,6,t,3,16);//显示ASCII字符的码值
- //delay_ms(100);
- /*OLED_Clear();
- delay_ms(8000);
- OLED_DrawBMP(0,0,128,8,BMP1); //图片显示(图片显示慎用,生成的字表较大,会占用较多空间,FLASH空间8K以下慎用)
- delay_ms(8000);
- OLED_DrawBMP(0,0,128,8,BMP2);
- delay_ms(8000);*/
- printf("This is task 3,count is %d\r\n",count);
- uwRet = LOS_TaskDelay(100);
- if(uwRet !=LOS_OK)
- return;
- }
- }
- UINT32 creat_task3(void)
- {
- UINT32 uwRet = LOS_OK;
- TSK_INIT_PARAM_S task_init_param;
- task_init_param.usTaskPrio = 9;
- task_init_param.pcName = "task3";
- task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)task3;
- task_init_param.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
- task_init_param.uwResved = LOS_TASK_STATUS_DETACHED;
- uwRet = LOS_TaskCreate(&g_TestTskHandle,&task_init_param);
- if(uwRet !=LOS_OK)
- {
- return uwRet;
- }
- return uwRet;
- }
- UINT32 osAppInit(void)
- {
- UINT32 uwRet = 0;
- hardware_init();
- printf("Welcom to Huawei LiteOS!!!\r\n");
- delay_ms(100);
- uwRet = creat_task1();
- if(uwRet !=LOS_OK)
- {
- return uwRet;
- }
-
- uwRet = creat_task2();
- if(uwRet !=LOS_OK)
- {
- return uwRet;
- }
-
- uwRet = creat_task3();
- if(uwRet !=LOS_OK)
- {
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码 下载:
Huawei LiteOS for ALIENTEK MiniSTM32V3(20161130).rar
(479.55 KB, 下载次数: 125)
|