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

SCC.369 Working with GPIO

时间:2024-10-18 11:58:49浏览次数:6  
标签:function use Working should will 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 registers

to 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 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". 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 correctly

listed, 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 return

type) 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 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, onecount at a time, starting at the value passed in. You should call your displayBinary() function fromabove. After re代 写SCC.369  Working with GPIO aching a displayed count of 0b11111 the counter should ‘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 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 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 themicro: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 clockwise

3V.

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 variableresistor 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 bluend 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 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 fullcycle gets more marks, and the 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 widecolour 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 itST4.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 istouched. A “long-touch” to reset the count to the initialValue will get you extra marks

标签:function,use,Working,should,will,subtask,SCC.369,GPIO,bit
From: https://www.cnblogs.com/goodlunn/p/18473984

相关文章

  • 一、STM32F103C8T6--GPIO
    STM32f103c8t632位Cortex-M3内核RISC处理器,最高主频72MHZ,Flash:64KB,SRAM:20KB片上外设:I/O端口:多达37个GPIO引脚(支持复用功能)。GPIO端口支持输入、输出、上拉/下拉功能。定时器:3个16位通用定时器(支持PWM输出)。********1个高级定时器(支持多通道PWM)。通信接口:......
  • IIC通信配置时,其GPIO应处于何种工作模式?为何这样做?及IIC总线上为何需增加上拉电阻?其
        直奔主题,以下是以下关于IIC总线应用中所需要理解的特性:1、GPIO应处于何种工作模式?    解:IIC总线通信使用两根新,分别是SDA和SCL,其IO工作模式通常需要配置为开漏输出。因为IIC总线是允许多个设备共享同一总线的,所以所有设备都可以将总线拉低,但不会相互冲突......
  • ESP32-IDF GPIO 专题
    目录一、基本介绍1、配置结构体2、API2.1gpio_config2.2gpio_reset_pin2.3gpio_set_intr_type2.4gpio_intr_enable2.5gpio_intr_disable2.6gpio_set_level2.7gpio_get_level2.8gpio_set_direction2.9gpio_set_pull_mode2.10gpio_isr_register2.11gpio_install......
  • ZYNQ使用XGPIO驱动外设模块(后半部分)
    目录注意重点:一、SDK代码开发部分:显示所需的字符编码:1.用于显示8x16的字符函数:2.绘制图片:3.清楚给定两个坐标之间的显示:4.显示16*32的阿拉伯数字字符:5.显示16*32的整型数字,最大显示到万位:Debug运行二、取模显示图片三、调试效果:注意重点:1.我们运行代码,注意,DEB......
  • 3-GPIO八大输出模式 推挽输出 与 开漏输出
    推挽输出与开漏输出GPIO有八大输出模式下图为每个GPIO口的基本结构:通过这张图来学习最右侧是I/O引脚,是从STM32引脚到GPIO口的导线,与其他芯片进行连接的线。芯片内部电路所能承受的电压有限,当未知的静电进入GPIO口,大于所能承受的电压,就会被上方的保护二极管导通,将电......
  • 关于GPIO输入模式的配置选择
    GPIO(通用输入输出)口是嵌入式系统中的重要组成部分,输入模式使得微控制器能够与外部世界进行交互。本文将探讨GPIO输入模式中的浮空输入、上拉输入和下拉输入的配置、使用场景及注意事项,并提供一些决策指导,帮助读者在实际项目中做出合适的配置选择。输入模式的基本概念在输入模......
  • [米联客-XILINX-H3_CZ08_7100] FPGA_SDK入门篇连载-18 PL AXI-GPIO实验
    软件版本:VIVADO2021.1操作系统:WIN1064bit硬件平台:适用XILINXA7/K7/Z7/ZU/KU系列FPGA实验平台:米联客-MLK-H3-CZ08-7100开发板板卡获取平台:https://milianke.tmall.com/登录“米联客”FPGA社区http://www.uisrc.com视频课程、答疑解惑!目录1概述2系统框图3AXI-GPI......
  • GPIO输入输出端口
    目录GPIO输出模块:        1.使用RCC开启GPIO时钟;2.配置GPIO函数初始化GPIO;3.使用输出控制GPIO端口;代码示例1.LED闪烁2.LED流水灯3.蜂鸣器GPIO输入模块:流程同上(GPIO改成输入模式函数部分改为读取函数)代码示例1.按键控制LED2.光敏传感器控制蜂鸣器GPI......
  • 迅为RK3588开发板 | 在高性能处理器上如何使用GPIO
      ------------------------------------ 注:详细使用可参考《【北京迅为】itop-3588开发板驱动开发指南》 GPIO基本概念GPIO,即General-PurposeInput/Output,指的是可以由软件控制的通用输入输出引脚。每个GPIO引脚可以配置为输入或输出,用来读取外部设备的状态(如按键)或控制外设(......
  • 迅为RK3588开发板 | 在高性能处理器上如何使用GPIO
      ------------------------------------ 注:详细使用可参考《【北京迅为】itop-3588开发板驱动开发指南》 GPIO基本概念GPIO,即General-PurposeInput/Output,指的是可以由软件控制的通用输入输出引脚。每个GPIO引脚可以配置为输入或输出,用来读取外部设备的状态(如按键)或......