GPIO and Interrupt C Programming for virtual Piano using Keil simulator

189 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

题目

stm32 GPIO中断仿真钢琴按键\

For this lab exercise you will Keil simulator(based on Nucleo-F103RB board). The objective is to understand how the GPlO device connects with the microprocessor and how to manipulate GPIO pins to serve our purpose. · This lab contributes to 8% of your final grade. · This lab is an individual work. When you submit, you also confirm that the submission is your own work. · The source code(s) that you submit will be compared against other submissions as part of the plagiarism check. Useful sources(QMplus) GPIOonKeil project Introduction In this exercise, you will create a program that uses GPlO pins to control piano keys to play a music tune from the Sound of Music. This will be done on Keil simulator and it will not be possible to connect the GPlO pins to an actual virtual piano. Here is what you are asked to do: · Read a digit value between 1 and 8 which will be input in binary form using B3,B2, B1 pins where B3 is the most significant and B1 is the least significant bit. · Based on the number read, play one of the lines in Table 1. · Assign a GPlO pin for each of the highlighted eight piano keys in Figure 1. · Assign another GPIO pin to switch from one key to another. This is connected to a push button PB. image.png image.png Software Flow You are required to write a C program to: · Initialise GPIO peripherals· Initialise global variables · Set interrupt trigger of GPIO pin PB that it connected to the push button as rising edge. · Set GPIO PB callback function to an PB/SR/status/that you will write. · Repeat the following infinitely: oRead the digit from pins B3 B2 B1 and store in variable LINE. o Call the function PlayNote/L/NE/that you will write. Upon the rising edge of PB, play the next key in the line LINE.E.g, if B3 B2 B1=011 then LINE=3. If it is the first rising edge of PB, you should activate the GPlO that is connected to key E. At the second rising edge of PB the GPIO connected tokey F should be activated, etc. Task0 Initialise the GPIO peripherals: -3 pins configured as input bits B3,B2, and B1 -1pin configured as input connected to push button PB 8pins configured as outputs Define global variables: -LINE -Interrupt Use gpio get rangeinbuilt function to read the value of LINE and call Task 1 Write the interrupt service routine function PB_ISRlint status/that will set the global variable Interrupt to 0 every time it is called. Task2 Write the function PlayNote(LINE) that plays the keys corresponding to LINE based on Table 1. The function should wait for Interrupt to be activate before playing any key and should terminate once all keys in LINE are played. Testing Strategy · In order to test the key-playing function, try to step your main program during debugging. You can inspect the values of some of your variables in the debugger and check that the output GPIO pins are correctly activated. · Set a breakpoint in your program after the push button has been released and examine the variables using the watch window. Submission Please be reminded that this lab is an individual work. 1.You are asked to test your code based on(1)the input digit that corresponds to the last digit of you BUPT ID number and(2)the last digit of your QMUL ID number(if your ID ends with 0 or 9 use 5 instead). 2.Prepare a 5-minute video to explain your code in details and show the execution of the function within the Keil simulation.This video should be submitted on QMPlus (60%).Please begin with a clear camera view of yourself,introducing yourname and QMUL student ID. 3.Submit your final source code main.c(40%)to QMPlus when you have completed. Your source code will be checked for plagiarism.

分析

本题相当于一个38译码器。
PA0作为外部中断触发引脚,PA1-3作为LINE数据总线,PB0-7作为输出。

展示

在这里插入图片描述

代码传送门

download.csdn.net/download/re…