首页 > 其他分享 >SCC.369 Working with GPIO Moodle

SCC.369 Working with GPIO Moodle

时间:2024-11-08 20:21:41浏览次数:1  
标签:function use Moodle will micro subtask SCC.369 GPIO bit

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 toregisters to control the GPIO pins, in this coursework you will explore some of the other functionalitythat’s possible with GPIO pins. Along the way you will get more comfortable working with registersto control the MCU and a better idea of the capabilities of the nRF52 series of MCUs. You will alsostart 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 CThis means that you are NOT permitted to use any library functions thatyou have not written yourself (apart from for debugging over serial) – only #include "MicroBit.h". Inaddition 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 correctlylisted, you just need to write the code for each one!
  1. Within CW1.cpp, write your code for each subtask within the indicated section of the file.
  2. Do not change the specified function prototypes (i.e. function name, parameters and returntype) for each subtask, use the ones given in the CW1.cpp template.
  1. Do not include a main() function or main.cpp file in your submission, although you will ofcourse 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 belooking 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 thedirection register of a GPIO port if the directions don’t keep changing.

o Only change the bits of a register that you代写SCC.369 Working with GPIO Moodle  need to, e.g. AND or OR in the bits youneed 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 funUse 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 whenlooking at the micro:bit with the USB cable pointing up. A ‘1’ in a bit position should turn thecorresponding LED on, a ‘0’ should turn the LED off. You can use any row of LEDs on the micro:bit toshow 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, onecount at a time, starting at the value passed in. You should call your displayBinary() function fromabove. After reaching a displayed count of 0b11111 the countershould ‘keep going’, i.e. wraparound to 0b00000. The frequency of counting should be 5Hz, i.e. 5 counts per second or 200ms percount. Think about how you can test the frequency of counting; the stretch goal is to see if you canadjust 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 Aand B on the micro:bit. Check the micro:bit schematic to see which GPIOs they use. There is only onefunction to write:

Function prototype: void countWithButtonsBinary(uint8_t initialValue);

This function displays the initial count value passed in, using the displayBinary() function fromSubtask 1, and updates the display with a new value when a micro:bit button is pressed. Button Ashould decrement the value by one count, and button B should increment it by one. To make thiswork 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 andread the voltage present on that pin. To test this you will need to apply a variable analogue voltageto that pin. You’ll need a breadboard, a micro:bit breakout adapter, a variable resistor and somejumper 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 workingmicro:bit/breadboard setup in .jpg format for some easy marks! Please name it ST3.jpg.

Function prototype: uint8_t sampleVoltage(void); 2Write 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 0represents 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 clockwise3V.

Function prototype: void displayVoltageBinary(void);

Write a function to repeatedly display in binary the magnitude of the analogue voltage measured onthe 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

esistor 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 blueand 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 workswith one or more elements lit up. But for the coursework, control each pin with a PWM signal atroughly 1kHz. Driving all three colours at a fixed ratio of 50% on, 50% off gets you over half themarks. Making the LED ‘breathe’ by repeatedly fading from completely off to fully on and back overthe course of 2-4 seconds for a full cycle gets more marks, andthe stretch is to have the variableresistor from Subtask 3 control the colour at the same time the LED is breathing – a full turn of theresistor knob should run through a wide range of colours such that there are no obvious switchesfrom 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 workingmicro: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 fromSubtask 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

标签:function,use,Moodle,will,micro,subtask,SCC.369,GPIO,bit
From: https://www.cnblogs.com/comp9321/p/18535619

相关文章

  • 记录STM32的GPIO 的坑 复用引脚PB3 PB4
    系列文章目录点击直达——文章总目录文章目录系列文章目录一、STM32的GPIO复用引脚PB3PB4二、关闭JTAG功能(PB3/4),只使用SWD(PA13/14)调试关于作者2024年11月3日,浪费我一天的时间,就因为这个BUG,害我没找妹子去玩,可恶可恶!!!STM32的GPIO引脚有这一些约定俗......
  • 想要硬件设计不用愁?首先要搞懂这三类GPIO!
    合宙低功耗4G模组经典型号Air780E,支持两种软件开发方式:一种是传统的AT指令;一种是基于模组做Open开发。传统AT指令的开发方式,合宙模组与行业内其它模组品牌在软件上区别不大,在硬件功耗上更有优势;模组Open开发,合宙采用的是LuatOS方式,相对C-SDK入门更简单,开发更方便,开发时间上也更......
  • SCC.369 Working with GPIO Moodle
    SCC.369Coursework1:WorkingwithGPIO Moodlesubmission16:00Fridayweek4;weighting33%ofmodule.AimHavingfamiliarizedyourselfwiththeCdevelopmentenvironmentandthebasicprocessofwritingtoregisterstocontroltheGPIOpins,inthiscour......
  • ESP32学习笔记2(GPIO的数字输入输出功能)
    1.普通5mm直径LED参数测定实验以上为普通5mm直径LED,手册建议持续工作电流为20mA以内。以下,采用学生电源(带控压限流功能)通过限流电阻170欧给各色LED供电,通过缓慢加压测流和观察LED亮度的方法,确定电流、压降与亮度关系,实测该批次LED颜色与压降大致如下:颜色1mA状态与压降......
  • stm32教程:GPIO口及流水灯实验
    早上好啊,大佬们,想必在你电脑硬盘的某处放着一个stm32的工程模板吧!~然后今天,就和大家一起写出第一个小项目——流水灯咱们先来讲讲GPIO口吧。关于GPIO的那点事儿什么是GPIOGPIO(英语:General-purposeinput/output),通用型之输入输出的简称,功能类似8051的P0—P3,其接脚可以供......
  • ACCFIN5242 Moodle Discussion Forum
    AssessmentBrief2024/2025Pleasemakesureyoucarefullyreadandunderstandthequestionortask.Ifyouhaveunansweredquestions,pleaseposttheseonthecourseMoodleDiscussionForum,andwe’llrespond.  AssignmentInformationCourseCodeA......
  • 采用gpio-mio的sdk文档编译petalinux
    其余步骤都ok到下面生成boot.bin文件时失败 在网上找到了类似的  部署运行petalinux系统镜像_defaultbitsreamisnotfound,pleasespecifyabi-CSDN博客 经发现为该文件为纯PS端 未用到pl端  所以在生成时需要去除--fpga 这样就成功了......
  • STM32学习笔记-GPIO
    参考江科大32单片机学习相关知识GPIO基本构造APB2(AdvancedPeripheralBus2)是STM32微控制器架构中的一个外设总线,用于连接一些高性能外设,如定时器、USART、ADC和GPIO等。这些外设通常对性能要求较高,需要更快的数据传输速率。相较于APB1,总线频率更高,适合用于需要快速响应......
  • 使用spi-gpio-custom模块配置SPI总线
    使用spi-gpio-custom模块配置SPI总线 来源https://www.xuzhe.tj.cn/index.php/2023/10/26/spi-gpio-customspi/参考专栏 https://www.zhihu.com/column/c_1698084667767709696 1.引言SPI(SerialPeripheralInterface)是一种常见的串行通信协议,广泛应用于微控制器与外部......
  • STM32:GPIO
    目录一、简介二、结构三、功能        1.GPIO        2.外部中断四、示例 一、简介    输入输出(IO)是单片机最基本的外设功能之一。根据型号不同,STM32的IO端口数量不同,如64引脚的STM32F103RBT6有A、B、C、D四个IO端口,每个端口有16个引脚。......