Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
[第三期 空气质量分析仪]第4周作业
发布于 2019-11-10 22:14:18 浏览:1177
订阅该版
错过交作业的时间,真是抱歉; 本周任务:花式流水灯使用的硬件平台,是自制STM32429开发板(第一次画板焊板,所以存在好多问题,哈哈); BSP用的现成的F429-atk-apollo,用CubeMx配置IO 本来是想做一个驱动RGB屏的作业,但无奈焊功太差,40p的座子无法顺利焊上去,所以改为对8个LED驱动的设计任务(8个灯,从弱到强不同程度的亮,循环来回亮灭); [attach]12202[/attach] ``` static void led_hw_init(void); static void led_entry(void); static void led1_entry(void); static void led2_entry(void); static void led3_entry(void); static void led4_entry(void); static void led5_entry(void); static void led6_entry(void); static void led7_entry(void); static void led8_entry(void); static void led_onoff(uint8_t nums,uint8_t onoff); static uint8_t led_mode = 0; const uint8_t led_level[] = {0,8,12,15,17,19,21,23,25};//值越小,越亮 const uint8_t led_index[][8] = { {0,1,2,3,4,5,6,7}, {1,0,1,2,3,4,5,6}, {2,1,0,1,2,3,4,5}, {3,2,1,0,1,2,3,4}, {4,3,2,1,0,1,2,3}, {5,4,3,2,1,0,1,2}, {6,5,4,3,2,1,0,1}, {7,6,5,4,3,2,1,0} }; static int8_t led1_index = 0; static int8_t led2_index = 0; static int8_t led3_index = 0; static int8_t led4_index = 0; static int8_t led5_index = 0; static int8_t led6_index = 0; static int8_t led7_index = 0; static int8_t led8_index = 0; static uint8_t led_flag = 0; static uint8_t led1_on = 0; static uint8_t led2_on = 8; static uint8_t led3_on = 12; static uint8_t led4_on = 15; static uint8_t led5_on = 17; static uint8_t led6_on = 19; static uint8_t led7_on = 21; static uint8_t led8_on = 23; uint8_t led_init(void) { uint8_t th_index = 0; rt_thread_t led_contrl_th,led_th1,led_th2,led_th3,led_th4,led_th5,led_th6,led_th7,led_th8; rt_err_t result; led_hw_init(); led_contrl_th = rt_thread_create("led_contrl_th",(void *)led_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2,20); if(led_contrl_th == RT_NULL) { return -1; } led_th1 = rt_thread_create("led_th1",(void *)led1_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2+1,20); if(led_th1 == RT_NULL) { return -1; } led_th2 = rt_thread_create("led_th2",(void *)led2_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2+1,20); if(led_th2 == RT_NULL) { return -1; } led_th3 = rt_thread_create("led_th3",(void *)led3_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2+1,20); if(led_th3 == RT_NULL) { return -1; } led_th4 = rt_thread_create("led_th4",(void *)led4_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2+1,20); if(led_th4 == RT_NULL) { return -1; } led_th5 = rt_thread_create("led_th5",(void *)led5_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2+1,20); if(led_th5 == RT_NULL) { return -1; } led_th6 = rt_thread_create("led_th6",(void *)led6_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2+1,20); if(led_th6 == RT_NULL) { return -1; } led_th7 = rt_thread_create("led_th7",(void *)led7_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2+1,20); if(led_th7 == RT_NULL) { return -1; } led_th8 = rt_thread_create("led_th8",(void *)led8_entry,RT_NULL,256, RT_THREAD_PRIORITY_MAX / 2+1,20); if(led_th8 == RT_NULL) { return -1; } rt_thread_startup(led_contrl_th); rt_thread_startup(led_th1); rt_thread_startup(led_th2); rt_thread_startup(led_th3); rt_thread_startup(led_th4); rt_thread_startup(led_th5); rt_thread_startup(led_th6); rt_thread_startup(led_th7); rt_thread_startup(led_th8); return RT_EOK; } //INIT_COMPONENT_EXPORT(key_init); static void led_hw_init(void) { uint8_t ii; /* set LED pin mode to output */ rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT); rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT); rt_pin_mode(LED3_PIN, PIN_MODE_OUTPUT); rt_pin_mode(LED4_PIN, PIN_MODE_OUTPUT); rt_pin_mode(LED5_PIN, PIN_MODE_OUTPUT); rt_pin_mode(LED6_PIN, PIN_MODE_OUTPUT); rt_pin_mode(LED7_PIN, PIN_MODE_OUTPUT); rt_pin_mode(LED8_PIN, PIN_MODE_OUTPUT); for(ii = 1; ii <= 8; ii++) { led_onoff(ii,PIN_HIGH); } } static void led_entry(void) { int8_t index = 0; uint8_t flag = 0; while(1) { if(led_mode == 0) { if(flag == 0) { index++; if(index>=7) { flag = !flag; } } else { index--; if(index <=0) { flag = !flag; } } led1_index = led_index[index][0]; led2_index = led_index[index][1]; led3_index = led_index[index][2]; led4_index = led_index[index][3]; led5_index = led_index[index][4]; led6_index = led_index[index][5]; led7_index = led_index[index][6]; led8_index = led_index[index][7]; } else if(led_mode == 1) { } else if(led_mode == 0xff) { led1_index = 8; led2_index = 8; led3_index = 8; led4_index = 8; led5_index = 8; led6_index = 8; led7_index = 8; led8_index = 8; } led1_on = led_level[led1_index]; led2_on = led_level[led2_index]; led3_on = led_level[led3_index]; led4_on = led_level[led4_index]; led5_on = led_level[led5_index]; led6_on = led_level[led6_index]; led7_on = led_level[led7_index]; led8_on = led_level[led8_index]; rt_thread_mdelay(200); } } static void led_onoff(uint8_t nums,uint8_t onoff) { switch(nums) { case 1: rt_pin_write(LED1_PIN, onoff); break; case 2: rt_pin_write(LED2_PIN, onoff); break; case 3: rt_pin_write(LED3_PIN, onoff); break; case 4: rt_pin_write(LED4_PIN, onoff); break; case 5: rt_pin_write(LED5_PIN, onoff); break; case 6: rt_pin_write(LED6_PIN, onoff); break; case 7: rt_pin_write(LED7_PIN, onoff); break; case 8: rt_pin_write(LED8_PIN, onoff); break; default : break; } } static void led1_entry(void) { uint8_t i1; while(1) { for(i1 = 0; i1 < CIRCLE_MS; i1++) { if(i1 > led1_on) { rt_pin_write(LED1_PIN, PIN_LOW); } else { rt_pin_write(LED1_PIN, PIN_HIGH); } rt_thread_mdelay(1); } } } static void led2_entry(void) { uint8_t i2; while(1) { for(i2 = 0; i2 < CIRCLE_MS; i2++) { if(i2 > led2_on) { rt_pin_write(LED2_PIN, PIN_LOW); } else { rt_pin_write(LED2_PIN, PIN_HIGH); } rt_thread_mdelay(1); } } } static void led3_entry(void) { uint8_t i3; while(1) { for(i3 = 0; i3 < CIRCLE_MS; i3++) { if(i3 > led3_on) { rt_pin_write(LED3_PIN, PIN_LOW); } else { rt_pin_write(LED3_PIN, PIN_HIGH); } rt_thread_mdelay(1); } } } static void led4_entry(void) { uint8_t i4; while(1) { for(i4 = 0; i4 < CIRCLE_MS; i4++) { if(i4 > led4_on) { rt_pin_write(LED4_PIN, PIN_LOW); } else { rt_pin_write(LED4_PIN, PIN_HIGH); } rt_thread_mdelay(1); } } } static void led5_entry(void) { uint8_t i5; while(1) { for(i5 = 0; i5 < CIRCLE_MS; i5++) { if(i5 > led5_on) { rt_pin_write(LED5_PIN, PIN_LOW); } else { rt_pin_write(LED5_PIN, PIN_HIGH); } rt_thread_mdelay(1); } } } static void led6_entry(void) { uint8_t i6; while(1) { for(i6 = 0; i6 < CIRCLE_MS; i6++) { if(i6 > led6_on) { rt_pin_write(LED6_PIN, PIN_LOW); } else { rt_pin_write(LED6_PIN, PIN_HIGH); } rt_thread_mdelay(1); } } } static void led7_entry(void) { uint8_t i7; while(1) { for(i7 = 0; i7 < CIRCLE_MS; i7++) { if(i7 > led7_on) { rt_pin_write(LED7_PIN, PIN_LOW); } else { rt_pin_write(LED7_PIN, PIN_HIGH); } rt_thread_mdelay(1); } } } static void led8_entry(void) { uint8_t i8,onoff = 0; while(1) { for(i8 = 0; i8 < CIRCLE_MS; i8++) { if(i8 > led8_on) { rt_pin_write(LED8_PIN, PIN_LOW); } else { rt_pin_write(LED8_PIN, PIN_HIGH); } rt_thread_mdelay(1); } } } void Set_LedMode(uint8_t opt) { led_mode = opt; } ``` 控制灯的驱动是普通IO,并没有定时器输出的功能,所以每个灯都开了一个任务,灯的亮程度等级为(1-25),也就是按25ms为一个控制周期,高于这个时间,LED会明显出现闪烁情况; 按键一个控制暂停,一个控制启动,(按键延时在硬件上加了RC电路做消抖处理) 先交个作业,其他功能后续调试好再补发
查看更多
0
个回答
默认排序
按发布时间排序
暂无答案,快来添加答案吧
撰写答案
登录
注册新账号
关注者
0
被浏览
1.2k
关于作者
蔡信望
这家伙很懒,什么也没写!
提问
4
回答
0
被采纳
0
关注TA
发私信
相关问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【24嵌入式设计大赛】基于RT-Thread星火一号的智慧家居系统
2
RT-Thread EtherKit开源以太网硬件正式发布
3
如何在master上的BSP中添加配置yml文件
4
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
5
RT-Thread 发布 EtherKit开源以太网硬件!
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
MicroPython
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
16
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
13
个答案
1
次被采纳
本月文章贡献
程序员阿伟
9
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
5
次点赞
RTT_逍遥
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部