Question: Here is my code so far, it runs fine and compiles fine, I just need it to run when any of the pushbuttons are pressed
Here is my code so far, it runs fine and compiles fine, I just need it to run when any of the pushbuttons are pressed down individually because right now it only runs either when only KEY is pressed or when all KEYS KEY are pressed simultaneously. Might also need to add JTAG like the directions say.
#include
#include
#include
#include
#include "alteraavalonpioregs.h
#include sysaltirq.h
#include "alteraavalontimerregs.h
volatile int running ; Initially running
volatile int edgecapture;
char hextablexxxAxBxxx
xxxxxxAxAxxE;
int counter ; Start from the first odd number
int incrementflag ; for incrementing, for decrementing
static void timerinit;
static void timerisr;
void clearhex;
void pioinit;
void handlekeyinterruptsvoid context;
void writetosevenint count;
int main
clearhex;
timerinit;
pioinit;
while
usleep;
if running
writetosevencounter;
return ;
void writetosevenint count
Show ones place on HEX and tens place on HEX
IOWRALTERAAVALONPIODATAHEXBASE, hextablecount & xF;
IOWRALTERAAVALONPIODATAHEXBASE, hextable; Only shows on HEX as count is onedigit
static void timerinit
Stop the timer initially
IOWRALTERAAVALONTIMERCONTROLSYSTEMTIMERBASE, ;
Set a second interval
int period SYSTEMTIMERLOADVALUE ;
int periodh period ;
int periodl period & xFFFF;
IOWRALTERAAVALONTIMERPERIODLSYSTEMTIMERBASE, periodl;
IOWRALTERAAVALONTIMERPERIODHSYSTEMTIMERBASE, periodh;
Start the timer with interrupts enabled
IOWRALTERAAVALONTIMERCONTROLSYSTEMTIMERBASE, ;
alticisrregisterSYSTEMTIMERIRQINTERRUPTCONTROLLERID SYSTEMTIMERIRQ, timerisr, NULL, NULL;
static void timerisr
Reset the timer status to acknowledge the interrupt
IOWRALTERAAVALONTIMERSTATUSSYSTEMTIMERBASE, ;
if running return; If paused, exit ISR
Update counter
if incrementflag
counter ; Move to the next odd number in increment mode
else
counter ; Move to the previous odd number in decrement mode
Boundaries for cycle: to then reverse back and forth
if counter
incrementflag ; Start decrementing at upper boundary
else if counter
incrementflag ; Start incrementing at lower boundary
Print current counter value to JTAG UART
printfCounter: X
counter;
void pioinit
void edgecaptureptr void&edgecapture;
Enable interrupts for all keys
IOWRALTERAAVALONPIOIRQMASKKEYBASE, x;
IOWRALTERAAVALONPIOIRQMASKKEYBASE, x;
IOWRALTERAAVALONPIOIRQMASKKEYBASE, x;
Clear edge capture registers
IOWRALTERAAVALONPIOEDGECAPKEYBASE, x;
IOWRALTERAAVALONPIOEDGECAPKEYBASE, x;
IOWRALTERAAVALONPIOEDGECAPKEYBASE, x;
Register the ISR for each key
alticisrregisterKEYIRQINTERRUPTCONTROLLERID KEYIRQ, handlekeyinterrupts, edgecaptureptrx;
alticisrregisterKEYIRQINTERRUPTCONTROLLERID KEYIRQ, handlekeyinterrupts, edgecaptureptrx;
alticisrregisterKEYIRQINTERRUPTCONTROLLERID KEYIRQ, handlekeyinterrupts, edgecaptureptrx;
void handlekeyinterruptsvoid context
volatile int edgecaptureptr volatile int context;
edgecaptureptr IORDALTERAAVALONPIOEDGECAPKEYBASEIORDALTERAAVALONPIOEDGECAPKEYBASEIORDALTERAAVALONPIOEDGECAPKEYBASE;
Toggle running state when any key is pressed
running running;
Clear edge capture registers for each key
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
