SCC.369 Coursework 1: Working with GPIO
Moodle submission 16:00 Friday week 4; weighting 33% of module.
Aim
Having familiarized yourself with the C development environment and the basic process of writing to
registers to control the GPIO pins, in this coursework you will explore some of the other functionality
that’s possible with GPIO pins. Along the way you will get more comfortable working with registers
to control the MCU and a better idea of the capabilities of the nRF52 series of MCUs. You will also
start working with breadboards and electronic components.
Instructions for all subtasks
The coursework is split into a number of subtasks, listed below. Implement each one of them from
first principles using pure C. This means that you are NOT permitted to use any library functions that
you have not written yourself (apart from for debugging over serial) – only #include "MicroBit.h". In
addition to C keywords and C operators, you can use typedefs, structs and literals from the nRF SDK.
We will be looking at and testing your code with the help of some automated scripts, so it’s super
important that you follow the following guidelines. If you do not, you will lose marks:
1. Write and submit your CW in a file called CW1.cpp.
2. Start with the template CW1.cpp file on Moodle because it has all the functions correctly
listed, you just need to write the code for each one!
3. Within CW1.cpp, write your code for each subtask within the indicated section of the file.
4. Do not change the specified function prototypes (i.e. function name, parameters and return
type) for each subtask, use the ones given in the CW1.cpp template.
5. Do not include a main() function or main.cpp file in your submission, although you will of
course need to use one for your own testing. You might like to use the main() in
MainSubtaskRunner.cpp because that’s what we will use when we test your code.
For each subtask, 20-30% of the marks will depend on code quality. The kinds of things we will be
looking for include:
• Visually well-formatted and readable code
• Good, elegant code structure and style, e.g.:
o Appropriate use of loops, helper functions, literals etc.
o Initialise MCU peripherals only once where possible, e.g. don’t keep setting the
direction register of a GPIO port if the directions don’t keep changing.
o Only change the bits of a register that you need to, e.g. AND or OR in the bits you
need to change.
• Ample and thoughtful comments including:
o Before function definitions explaining function purpose, parameters etc.
o What variables are used for
o The choice of bit patterns and/or literals being written to registers
o The purpose of writing to registers
o The purpose of loops etc.
• No commented-out code with no explanation!
Remember to have fun . Use the labs to ask about anything you don’t understand!
Subtask 1, 20%: Display a binary number that counts up at 5Hz
This subtask requires you to write two functions as follows:
Function prototype: void displayBinary(uint8_t value);
Set the bit pattern of a row of LEDs on the micro:bit to match the least significant 5 bits of the
unsigned 8-bit value provided as a parameter. The least significant bit should be on the right when
looking at the micro:bit with the USB cable pointing up. A ‘1’ in a bit position should turn the
corresponding LED on, a ‘0’ should turn the LED off. You can use any row of LEDs on the micro:bit to
show this 5 bit number, but only use one row – the LEDs on the other rows should not light up.
The first time displayBinary() is called it will need to initialise GPIOs. It’s good practice not to
repeatedly re-initialise registers with the same value, so you could use a local static variable to
record the first time displayBinary() is called so that subsequent calls don’t repeatedly initialise.
Function prototype: void countUpBinary(uint8_t initialValue);
Write a function that causes the number on the row you chose above to count up in binary, one
count at a time, starting at the value passed in. You should call your displayBinary() function from
above. After reaching a displayed count of 0b11111 the counter should ‘keep going’, i.e. wrap
around to 0b00000. The frequency of counting should be 5Hz, i.e. 5 counts per second or 200ms per
count. Think about how you can test the frequency of counting; the stretch goal is to see if you can
adjust it to be within 5% of the target.
Subtask 2, 20%: Display a binary number that counts down/up with buttons A/B
For this subtask you will need to use two GPIO pins as inputs; use the ones connected to buttons A
and B on the micro:bit. Check the micro:bit schematic to see which GPIOs they use. There is only one
function to write:
Function prototype: void countWithButtonsBinary(uint8_t initialValue);
This function displays the initial count value passed in, using the displayBinary() function from
Subtask 1, and updates the display with a new value when a micro:bit button is pressed. Button A
should decrement the value by one count, and button B should increment it by one. To make this
work well you will need to debounce the button inputs. The count should wrap around to 0b11111
when decremented below zero, and vice-versa. The count should only change on a button press,
not on a button release, and it should not keep incrementing while a button is held down.
Remember to use the relevant PIN_CNF[x] register to access all the settings you need.
Subtask 3, 25%: Measure and display an analogue voltage
NB the week 3 lecture will explain aspects of this Subtask.
For this subtask you will configure the GPIO connected to micro:bit pin P0 as an analogue input and
read the voltage present on that pin. To test this you will need to apply a variable analogue voltage
to that pin. You’ll need a breadboard, a micro:bit breakout adapter, a variable resistor and some
jumper wires.
Wire up the ends of the variable resistor to power and ground, and connect the slider to P0.
For this subtask, in addition to your code please submit a photo of your working
micro:bit/breadboard setup in .jpg format for some easy marks! Please name it ST3.jpg.
Function prototype: uint8_t sampleVoltage(void);
2
Write a function to measure the magnitude of the analogue voltage on the large P0 pin of the
micro:bit edge connector. There are many ways to configure the analogue-to-digital converter (ADC)
on the nRF, but the important thing is that this function returns an 8-bit unsigned value where 0
represents an input of 0V and 255 represents an input of 3V (that the MCU is being powered from).
Wire the variable resistor so that fully anticlockwise produces 0V on the wiper and fully clockwise
3V.
Function prototype: void displayVoltageBinary(void);
Write a function to repeatedly display in binary the magnitude of the analogue voltage measured on
the large P0 pin. Use your displayBinary() function from Subtask 1 and make sure to display the five
most significant bits of the sampled voltage so that the display reaches 0b00000 when the variable
resistor is turned fully anticlockwise and 0b11111 when it’s turned fully clockwise.
Subtask 4, 25%: Drive an RGB LED
NB the week 3 lecture will explain aspects of this Subtask.
For this subtask you will connect an RGB LED to P1 (red), P8 (blue) and P9 (green) on the micro:bit
edge connector, each via a current-limiting resistor. Use a 220R resistor for red and 100R for blue
and green. The LED we are using is a common anode type.
Function prototype: void driveRGB(void);
You can drive the P1, P8 and P9 pins as regular GPIO outputs if you want to see how the LED works
with one or more elements lit up. But for the coursework, control each pin with a PWM signal at
roughly 1kHz. Driving all three colours at a fixed ratio of 50% on, 50% off gets you over half the
marks. Making the LED ‘breathe’ by repeatedly fading from completely off to fully on and back over
the course of 2-4 seconds for a full cycle gets more marks, and the stretch is to have the variable
resistor from Subtask 3 control the colour at the same time the LED is breathing – a full turn of the
resistor knob should run through a wide range of colours such that there are no obvious switches
from one colour to another – a nice, gentle fade through a wide colour palette!
For this subtask, in addition to your code please submit a photo of your working
micro:bit/breadboard setup in .jpg format for some easy marks! Please name it ST4.jpg.
Subtask 5, 10%: Display a binary number that counts up/resets on touch input
NB the week 3 lecture will explain aspects of this Subtask.
The final subtask has a lower weighting but is here to stretch you!
It’s like Subtask 2 but the display should count up by one count when you touch the golden micro:bit
“face” logo above the LEDs. No need to worry about counting down for this subtask though.
Function prototype: void countWithTouchesBinary(uint8_t initialValue);
This function displays the initial count value passed in, using the displayBinary() function from
Subtask 1, and increments the displayed number by one when the golden micro:bit face logo is
touched. A “long-touch” to reset the count to the initialValue will get you extra marks 😊.
Mark Scheme
For each subtask, 70-80% of the marks will be awarded for meeting the functional requirements
given. 20-30% of the marks will depend on code quality as described on the first page above. If you
3
4
do not use the filename, function prototypes and hardware configuration specified (all repeated in
red below) you will lose marks. Your work will be assessed by a combination of automatic processing
and manual inspection. Your final grade will be based on a weighted mean of your subtask marks.
Subtask Hardware config Weight To be submitted
(submit code in CW1.cpp)
1: Display a binary number
that counts up at 5Hz One row of micro:bit display 20% displayBinary()
countUpBinary()
2: Display a binary number
that counts down/up
with buttons A/B
Same row of micro:bit display;
the micro:bit buttons 20% countWithButtonsBinary()
3: Measure and display an
analogue voltage
Same row of micro:bit display;
variable resistor wired to edge
connector pin P0
25%
sampleVoltage()
displayVoltageBinary()
ST3.jpg photo of hardware
4: Drive an RGB LED RGB LED wired to edge
connector pins P1, P8 and P9 25% driveRGB()
ST4.jpg photo of hardware
5: Display a binary number
that counts up/resets on
touch input
Same row of micro:bit display;
the touch-sensitive
micro:bit ‘face’ logo
10% countWithTouchesBinary()
相关推荐
四分之一汽车模型主动悬架设计:在MATLAB_Simulink中实现比例积分控制、前馈扰动抑制和扰动估计,以优化乘坐舒适性和道路附着力。.rar
四分之一汽车模型主动悬架设计:在MATLAB_Simulink中实现比例积分控制、前馈扰动抑制和扰动估计,以优化乘坐舒适性和道路附着力。.rar
SCC.369 Coursework 1: Working with GPIOC/C++
SubtaskWeightToinCW1.cpp1:Display abinarynumberupat5HzOnerow of20%2:Display abinarynumberdown/upwithSamerow ofmicro:bitdisplay;themicro:bitbuttons20%3:displayanSamerow ofmicro:bit。
Delphi 13.2控件之msquic4d.rar
Delphi 13.2控件之msquic4d.rar
【FDE知识库】(1):AI 编程时代开发语言选型分析,云使用go,企业用java,算法python,底层c
AI 编程时代,开发语言选型需综合考量AI适配度、编译速度、跨平台与学习成本。Python以海量语料和即时执行成首选,适用于AI/ML与原型开发;TypeScript凭借类型系统与秒级构建,成为前端及应用层主流;Go以极速编译与统一风格,契合AI代理高效迭代需求。Rust/C++虽性能强,但编译慢、学习成本高,不适于快速试错。综合推荐:优先选Python、TypeScript、Go,兼顾效率与生态,实现最优AI协作体验。
企业数字化转型AI大模型赋能智能体平台及AI场景应用规划方案(生态合作版).pptx
企业数字化转型AI大模型赋能智能体平台及AI场景应用规划方案(生态合作版).pptx
智慧环保生态保护行业可信数据空间应用规划方案(技术方案版).pptx
智慧环保生态保护行业可信数据空间应用规划方案(技术方案版).pptx
MCGS的Http协议驱动,支持http协议
硬件配置 参数设置 设备属性 设备命令 通讯状态 附录 #HTTP 1、 设备简介 驱动类型 该驱动为独立设备,直接添加构件即可,不需要挂载到父设备下 通讯协议 采用标准HTTP1.1协议 通讯方式 驱动构件为客户端。 2、 硬件连接 本软件在通讯之前,请保证通讯连接正确。通讯连接方式:采用标准的RJ45接口的以太网接线(对调网线或使用HUB交换)。 3、 设备通讯参数 本设备为独立设备,无父设备参数 4、 设备构件参数设置 “HTTP设备”参数设置如下: <1> 内部属性: 构建url信息。 <2> 最小采集周期:本软件对设备进行操作的时间周期,单位为ms,默认为100ms。 <3> 通讯等待时间:通讯数据接收等待时间,默认设置为200ms,当采集速度要求较高或数据量较大时,设置值可适当减小或增大。 <4> HttpHead:http head添加需要的字段,不需要添加http head时值为空,默认不添加。 5、 设备命令 本设备构件提供设备命令,用于进行相应的操作,设备命令的格式如下: 设备命令 命令介绍 GetHttpHead 格式1 GetHttpHead(headStr) 用途 获取http head参数 参数 headStr 参数可以为字符型变量、字符串常量 例1 !SetDevice(设备0,6,"GetHttpHead(headStr)") 获取http head数据保存到headStr中 SetHttpHead 格式1 SetHttpHead(headStr) 用途 设置http head参数 参数 headStr 参数可以为字符型变量、字符串常量
气象服务行业可信数据空间应用规划方案(技术方案版).pptx
气象服务行业可信数据空间应用规划方案(技术方案版).pptx
【DBO三维路径规划】基于多策略改进的蜣螂算法MSDBO多无人机协同集群避障路径规划(目标函数:最低成本:路径、高度、威胁、转角)研究(Matlab代码实现)
内容概要:本文研究了基于多策略改进的蜣螂优化算法(MSDBO)在多无人机协同集群三维路径规划中的应用,旨在解决复杂三维环境下的避障与最优路径搜索问题。通过构建包含路径长度、飞行高度、威胁规避和转弯角度的综合成本目标函数,利用MSDBO算法对多无人机系统的飞行轨迹进行全局优化,实现在保证安全性与稳定性的前提下达到最低能耗与最优性能的目标。文中详细阐述了算法的多策略改进机制、三维环境建模方法以及多无人机协同避障策略,并通过Matlab仿真平台验证了该方法相较于传统优化算法在收敛速度、路径质量和鲁棒性方面的优越性能。; 适合人群:具备一定优化算法理论基础和无人机控制系统知识的科研人员及研究生,特别适用于从事智能优化算法、多智能体协同控制、路径规划与自主导航等相关领域的研究人员和技术开发者。; 使用场景及目标:①应用于灾害救援、军事侦察、智能巡检等复杂三维场景中多无人机协同任务的路径规划;②为多目标约束下的路径优化、动态避障与能耗平衡问题提供高效的算法支持与仿真验证工具;③推动智能优化算法在无人系统自主决策与协同控制中的实际应用与工程落地。; 阅读建议:建议读者结合提供的Matlab代码深入理解算法的具体实现过程,重点关注目标函数设计、多策略改进机制(如种群初始化、自适应参数调整、局部搜索增强等)及仿真结果分析部分,同时可尝试将该算法迁移至其他智能优化算法框架中进行对比研究,以深化对路径规划问题本质的理解与实践能力的提升。
机器视觉检测实战教程 19页成品课程光源选型Halcon标定海康相机VisionPro
内容概要:机器视觉检测实战教程,19页6章成品课程PDF:视觉检测光源选型对照表+五个翻车案例、Halcon模板匹配create_shape_model七参数整定、视觉标定三类(9点/旋转/手眼)、海康工业相机C#取图黑图丢帧排坑、VisionPro QuickBuild部署License迁移C#宿主、远心镜头选型。含C#/Halcon代码与现场案例。适用人群:机器视觉工程师、自动化检测开发、企业内训。使用场景:视觉方案设计、选型、标定部署、团队培训。原创整理。
【医疗器械制造】基于酸碱腐蚀环境的一次性乳胶手套铝合金手模失效机理分析与量产风险控制
内容概要:本文围绕一次性医用乳胶手套生产中使用的铝合金手模在酸碱环境下的失效风险展开系统性分析,重点探讨其在外表面腐蚀、清洗循环、氯介质侵入及表面粗糙度控制等方面的工程挑战。研究表明,尽管市场上已有带涂层的铝合金手模供应,但其能否在强碱、酸洗、毛刷摩擦、冷热交变和氯共存的复杂工况下长期维持Ra 1.0—2.5 μm的表面质量并实现稳定脱模,仍需经过严格的多阶段验证。常规阳极氧化+PTFE涂层方案已被实测排除,而316L不锈钢筒体在湿氯环境中出现的三个月内腐蚀失效案例提示必须重视内腔隔离设计。文章强调,采购决策应基于“小批量试制—离线加速试验—影子生产验证—条件性放行”的四阶段准入机制,结合表面参数、工艺相容性、手套成品性能与全生命周期成本进行综合评估,避免依赖供应商宣传数据。; 适合人群:从事医疗器械制造、材料工程、设备采购与工艺质量管理的技术人员及决策管理者,尤其是涉及乳胶手套生产线优化与手模选型的相关从业人员。; 使用场景及目标:①评估铝合金手模替代陶瓷手模的技术可行性与风险边界;②建立手模选型的系统验证流程,防范因表面失效导致的脱模异常、手套缺陷与非计划停机;③指导采购合同中技术条款的制定,确保供应商交付具备可验证数据支撑; 阅读建议:此资源以工程实证为导向,建议读者结合自身产线工艺参数,重点关注外表面Ra控制、内腔双密封设计、影子生产验证方法及失效链追溯体系的构建,在试制阶段严格执行多维度联合判定标准,审慎推进规模化替代。
【CEEMDAN-VMD-GRU】完备集合经验模态分解-变分模态分解-门控循环单元预测研究(Python代码实现)
内容概要:本文提出了一种融合完备集合经验模态分解(CEEMDAN)、变分模态分解(VMD)与门控循环单元(GRU)的复合预测模型,旨在提升对复杂非平稳时间序列的预测精度。首先利用CEEMDAN对原始信号进行自适应分解,有效缓解模态混叠问题,获得一组本征模态函数(IMFs);随后引入VMD对关键模态分量作进一步优化分解,增强特征分离能力,降低噪声干扰;最后将处理后的平滑分量分别输入GRU神经网络进行独立训练与预测,并通过加权集成策略融合各分量输出,得到最终高精度预测结果。该方法结合了多尺度信号分解与深度学习的优势,显著提升了模型在处理强噪声、非线性、非平稳序列(如电力负荷、风速、光伏发电功率等)时的泛化能力和预测稳定性,文中提供了完整的Python代码实现,便于复现与应用。; 适合人群:具备一定Python编程基础和机器学习理论知识,从事科研或工程应用的硕士、博士研究生及科研人员,尤其适用于能源系统预测、智能电网调度、可再生能源管理、信号处理与时间序列分析等相关领域的研究人员和技术开发者。; 使用场景及目标:①解决传统单一预测模型在面对复杂非平稳时间序列时存在的过拟合、收敛慢、精度低等问题;②通过多阶段信号分解降低原始序列的复杂度与不确定性,提升GRU模型的训练效率与预测鲁棒性;③为电力系统负荷预测、新能源出力预报、设备运行状态预警及市场交易策略制定等关键任务提供高精度数据支撑。; 阅读建议:建议读者结合提供的Python代码逐模块理解算法实现流程,重点关注CEEMDAN与VMD的参数配置对信号分解效果的影响,尝试在不同数据集上进行实验对比,并通过可视化手段分析各模态分量的物理意义,进一步掌握模型调优与性能评估的方法。
【新能源电力系统】项目介绍 MATLAB实现基于GWO-VMD-SSA-LSTM灰狼优化算法(GWO)结合变分模态分解(VMD)、麻雀搜索算法(SSA)及长短期记忆网络(LSTM)进行辐照度-温度驱动
内容概要:本文提出了一种融合灰狼优化算法(GWO)、变分模态分解(VMD)、麻雀搜索算法(SSA)和长短期记忆网络(LSTM)的复合模型(GWO-VMD-SSA-LSTM),用于实现高精度的辐照度-温度驱动短期光伏功率预测。该模型首先通过GWO优化VMD的关键参数(模态数K和惩罚因子α),实现对非平稳光伏功率序列的高效多尺度分解,降低信号复杂性;随后利用SSA对LSTM的超参数(如隐藏层单元数、Dropout率、学习率等)进行智能寻优,提升网络训练效率与泛化能力;最后通过独立LSTM网络对各VMD模态进行预测并重构输出。模型结合了信号分解、智能优化与深度学习优势,显著提升了在多云、阴雨等复杂天气下的预测精度与稳定性,并通过MAE、RMSE、MAPE和R²等指标验证了有效性。文中还提供了完整的MATLAB实现流程,涵盖数据清洗、归一化、滑动窗口构建、参数优化与结果可视化等环节。; 适合人群:具备一定机器学习与时间序列预测基础,从事新能源发电预测、智能电网调度、电力系统自动化等相关领域的科研人员、工程师及研究生。; 使用场景及目标:①解决光伏功率受辐照度、温度等因素影响而导致的强随机性、非平稳性预测难题;②提升短期(15分钟至1小时)光伏出力预测精度,支撑电网经济调度、储能协同控制与电力现货市场申报;③为多源气象数据驱动的可再生能源预测提供可扩展的技术框架。; 阅读建议:建议结合提供的MATLAB代码逐步实践,重点关注GWO与SSA的优化机制、VMD分解效果及其与LSTM的集成方式,注意避免时间泄漏问题,推荐在实际数据上复现实验以深入理解模型性能。
无人机路径规划中多种优化算法的仿真研究(Matlab代码实现)
内容概要:本文围绕无人机三维路径规划问题,系统研究了多种智能优化算法在复杂环境下的仿真应用与性能对比,重点实现了改进灰狼优化算法(I-GWO)、标准灰狼优化算法(GWO)、金鹰优化算法(GJO)和正弦余弦算法(SCA)的Matlab代码实现。通过构建包含路径长度、飞行高度、威胁规避及转弯角度等多维度目标函数的综合评价体系,对各算法在单无人机路径优化与多无人机协同集群避障场景中的表现进行全面仿真分析,评估其路径规划能力、收敛速度与鲁棒性。研究旨在实现最低综合成本的飞行路径,并为多智能体协同任务提供可靠的算法支撑。; 适合人群:具备一定Matlab编程基础,从事无人机系统设计、智能优化算法研究、路径规划及相关自动化、人工智能领域的科研人员、工程技术人员及研究生。; 使用场景及目标:① 掌握主流智能优化算法在三维空间路径规划中的具体建模与实现方法;② 对比分析不同算法在路径优化质量、计算效率、避障能力和多目标权衡方面的性能差异;③ 为多无人机协同执行侦察、监测、救援等任务提供高效的路径规划解决方案与仿真验证平台。; 阅读建议:建议结合文中提供的Matlab代码进行动手实践,重点关注算法参数调优、目标函数设计以及环境障碍物建模对最终路径的影响,可进一步扩展至动态障碍环境或加入通信约束以适应更复杂的实际应用场景。
T12_eVTOL低空经济低空公共航线网络规划设计方案_可研报告版.pptx
T12_eVTOL低空经济低空公共航线网络规划设计方案_可研报告版.pptx
T07_低空经济与智能网联汽车融合的城市空地一体出行服务平台建设方案_决策评审版.pptx
T07_低空经济与智能网联汽车融合的城市空地一体出行服务平台建设方案_决策评审版.pptx
超全Mathcad全桥LLC谐振变换器开关电源设计mathcad计算书
内容概要:本文档《超全Mathcad全桥LLC谐振变换器开关电源设计mathcad计算书》系统阐述了全桥LLC谐振变换器在开关电源中的设计方法,重点利用Mathcad工具进行精确的数学建模与参数计算。内容涵盖LLC谐振变换器的工作原理、关键参数设计(如谐振频率、励磁电感、变比等)、闭环控制策略、软开关实现条件、效率优化及工程实践中需注意的关键事项。文档通过详尽的数学推导和工程实例,构建了一套完整的从理论分析到实际应用的设计流程,特别强调了在不同负载与输入电压条件下确保ZVS/ZCS软开关的实现机制,并提供了实际设计中的取值依据与优化方向,为电力电子工程师提供了一个高效、可靠的设计参考方案。; 适合人群:具备电力电子技术基础,从事开关电源研发的工程师、高校电力电子及相关专业的研究生与科研人员,以及熟悉Mathcad、Simulink等仿真与计算工具的技术人员;; 使用场景及目标:① 掌握全桥LLC谐振变换器的参数设计与性能优化方法;② 开发高效率、高功率密度的软开关电源系统;③ 支持科研项目或工业产品中高性能电源模块的设计与验证;④ 结合仿真模型进行设计结果的验证与教学培训;; 阅读建议:建议结合配套的仿真模型与计算书同步学习,重点关注参数设计公式的推导过程与工程取值的合理性,动手复现计算步骤以加深理解,并通过仿真手段验证设计结果的准确性与鲁棒性。
ISCC练习题MISC
解题技巧:看最后括号应该是IceCTF,先用了一键解码啥也没有啊,不对不对!好像是字符频率统计,转换网站:http://quipqiup.com/有人给你发了一串信息,你能解开吗?
905



被折叠的 条评论
为什么被折叠?



