0% found this document useful (0 votes)
35 views3 pages

Code

The document describes code for an embedded system that uses an interrupt on the falling edge of a button press to increment a counter. It initializes the interrupt on a specific port and pin connected to a user button, then counts the button presses in the interrupt routine to determine a winner in a game between two players based on number of presses within a time limit.

Uploaded by

Dr Kashif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Code

The document describes code for an embedded system that uses an interrupt on the falling edge of a button press to increment a counter. It initializes the interrupt on a specific port and pin connected to a user button, then counts the button presses in the interrupt routine to determine a winner in a game between two players based on number of presses within a time limit.

Uploaded by

Dr Kashif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// EdgeInterrupt.

// Runs on LM4F120 or TM4C123

// Request an interrupt on the falling edge of PF4 (when the user

// button is pressed) and increment a counter in the interrupt. Note

// that button bouncing is not addressed.

// Daniel Valvano

// May 3, 2015

/* This example accompanies the book

"Embedded Systems: Introduction to ARM Cortex M Microcontrollers"

ISBN: 978-1469998749, Jonathan Valvano, copyright (c) 2015

Volume 1, Program 9.4

"Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers",

ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014

Volume 2, Program 5.6, Section 5.5

Copyright 2015 by Jonathan W. Valvano, [email protected]

You may use, edit, run or distribute this file

as long as the above copyright notice remains

THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED

OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF

MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.

VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,

OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.

For more information about my classes, my research, and my books, see

http://users.ece.utexas.edu/~valvano/

*/
// user button connected to PF4 and PF0 (increment counter on falling edge)

#include <stdint.h>

#include "../inc/tm4c123gh6pm.h"

#include "../inc/EdgeInterruptPortF.h"

#include "../inc/CortexM.h"

#include "../inc/LaunchPad.h"

#include "../inc/Cheat.h"

if (power select switch is on)

start timer

while (timer >= 0sec) {

count number of button presses for each player

if (cheat implemented by P1) {

LaunchPad_Output(RED); // P1 wins, turn LED1 on GPIO_DATA_R = 0X02;

else if (cheat implemented by P2) {

LaunchPad_Output(BLUE); // P2 wins, turn LED2 on GPIO_DATA_R = 0X04;

if (no cheats used) {

if (FallingEdges1 > FallingEdges2) { //P1 button presses > P2 button presses

LaunchPad_Output(RED); //P1 wins, turn LED1 on GPIO_DATA_R = 0X02;


}

else if (FallingEdges2 > FallingEdges1) { //P2 button presses > P1 button presses

LaunchPad_Output(BLUE); //P2 wins, turn LED2 on GPIO_DATA_R = 0X04;

else {

LaunchPad_Output(YELLOW); // tie, turn LED3 on GPIO_DATA_R = 0X08;

// global variable visible in Watch window of debugger

// increments at least once per button press

extern volatile uint32_t FallingEdges1; //to count P1's button presses

extern volatile uint32_t FallingEdges2; //to count P2's button presses

//debug code

int main(void){

LaunchPad_Init();

EdgeCounterPortF_Init(); // initialize GPIO Port F interrupt

EnableInterrupts();

while(1){

WaitForInterrupt();

You might also like