Answered step by step
Verified Expert Solution
Link Copied!

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 button0(BTN0) is pressed only LED0(LD0) turns on, if
button1 is pressed only LED1 turns on and so on for all four buttons. Include a screen shot of
the modified code.
#include "xparameters.h"
#include "xparameters.h"
#include "xil_printf.h"
#include "xgpio.h"
#include "xil_types.h"
// Get device IDs from xparameters.h
#define BTN_ID XPAR_AXI_GPIO_BUTTONS_DEVICE_ID
#define LED_ID XPAR_AXI_GPIO_LED_DEVICE_ID
#define BTN_CHANNEL 1
#define LED_CHANNEL 1
#define BTN_MASK 0b1111
#define LED_MASK 0b1111
int main(){
XGpio_Config *cfg_ptr;
XGpio led_device, btn_device;
u32 data;
xil_printf("Entered function main\r
");
// Initialize LED Device
cfg_ptr = XGpio_LookupConfig(LED_ID);
XGpio_CfgInitialize(&led_device, cfg_ptr, cfg_ptr->BaseAddress);
// Initialize Button Device
cfg_ptr = XGpio_LookupConfig(BTN_ID);
XGpio_CfgInitialize(&btn_device, cfg_ptr, cfg_ptr->BaseAddress);
// Set Button Tristate
XGpio_SetDataDirection(&btn_device, BTN_CHANNEL, BTN_MASK);
// Set Led Tristate
XGpio_SetDataDirection(&led_device, LED_CHANNEL, 0);
while (1){
data = XGpio_DiscreteRead(&btn_device, BTN_CHANNEL);
data &= BTN_MASK;
if (data !=0){
data = LED_MASK;
} else {
data =0;
}
XGpio_DiscreteWrite(&led_device, LED_CHANNEL, data);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

How would you respond to each of the girls?

Answered: 1 week ago

Question

9.8 Describe leadership development and its impact

Answered: 1 week ago

Question

9.6 Explain what management development is and why it is important.

Answered: 1 week ago