Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Modify the C code as such that when button 0 ( BTN 0 ) is pressed only LED 0 ( LD 0 ) turns on
Modify the C code as such that when buttonBTN is pressed only LEDLD turns on if
button is pressed only LED turns on and so on for all four buttons. Include a screen shot of
the modified code.
#include "xparameters.h
#include "xparameters.h
#include "xilprintf.h
#include "xgpio.h
#include "xiltypes.h
Get device IDs from xparameters.h
#define BTNID XPARAXIGPIOBUTTONSDEVICEID
#define LEDID XPARAXIGPIOLEDDEVICEID
#define BTNCHANNEL
#define LEDCHANNEL
#define BTNMASK b
#define LEDMASK b
int main
XGpioConfig cfgptr;
XGpio leddevice, btndevice;
u data;
xilprintfEntered function mainr
;
Initialize LED Device
cfgptr XGpioLookupConfigLEDID;
XGpioCfgInitialize&leddevice, cfgptr cfgptrBaseAddress;
Initialize Button Device
cfgptr XGpioLookupConfigBTNID;
XGpioCfgInitialize&btndevice, cfgptr cfgptrBaseAddress;
Set Button Tristate
XGpioSetDataDirection&btndevice, BTNCHANNEL, BTNMASK;
Set Led Tristate
XGpioSetDataDirection&leddevice, LEDCHANNEL, ;
while
data XGpioDiscreteRead&btndevice, BTNCHANNEL;
data & BTNMASK;
if data
data LEDMASK;
else
data ;
XGpioDiscreteWrite&leddevice, LEDCHANNEL, data;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started