Vous êtes sur la page 1sur 1

STM32Fxx Programming Exercises (Timer & Interrupt) V1.

Microprocessor Eng 16-7210

General Notes!

 Use the sample example projects as a starting point. You can re-use the same and replace the 'C' files as
required with your own code. Note you must remove the previous 'C' file which contains the main(), you
can only have one main()in the project. Removing a file from a project does not delete the file!
 Layout your program neatly – look at the layout in the example programs and read the C style guide for
further guidance.
 You will be required to demonstrate the example lab questions you have completed as part of the
assessment for the module, make sure you save the c source file for each question separately.
 You may use the peripheral driver libraries provided by STM if you wish however you will be required to
explain the operation of the code and why you have set specific parameters.

Timer & Interrupt Lab questions - You must use a hardware timer for the following questions

Q1 Replace the software delay function used in one of your previous exercises with one that uses a hardware
timer. You will need to select which timer to use, select a suitable prescaler value and to calculate the value
that needs to be loaded into the timer/counter to generate a 3 second delay. Note: some counters can be
programmed to count up or down, others are fixed to count up. After the timer has been initialised and
started, the timer overflow flag should be polled to detect when it changes from logic 0 to logic 1 indicating
the timing period has elapsed.

Q2 Save Q1 as a new source file and modify the program to make use of a timer interrupt.

Q3 Create a program which measures and displays the time period between sequential presses of a push
button.(Make sure the push button you use is connected to a suitable input pin which can be configured as an
external interrupt in preparation for the next question). The time period should be displayed on a suitable
output (LCD (if available) and/or the Printf Debug Viewer.

Q4 Save Q3 as a new source file and modify the program as follows: Configure the pin connected to the
push button to be an external edge triggered interrupt. You should reset of the timer through the Interrupt
Service Routine (ISR) triggered by the push button.

Q5 Now convert your program into a stopwatch. You stopwatch should display the elapsed time on the LCD
in minutes, seconds and hundredths in the following format MM: SS: HH. Use one of the spare push buttons
to reset the stopwatch. (Remember to save this as a new C file)

Alan Holloway 1
Sheffield Hallam University.
Feb 2013

Vous aimerez peut-être aussi