Can someone help me? I'm stuck. I'm using a zybo z7, vivado block diagrams, and vivits platform on a C language source.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Can someone help me? I'm stuck. I'm using a zybo z7, vivado block diagrams, and vivits platform on a C language source.

Post by answerhappygod »

Can someone help me? I'm stuck. I'm using a zybo z7, vivadoblock diagrams, and vivits platform on a C languagesource. The professor is asking to modify a C code suchthat when button0 (BTN0) is pressed only LED0 (LD0) turns on, ifbutton1 is pressed only LED1 turns on, and so on for all fourbuttons. Include a screenshot of the modified code. The originalcode turn all the led lights on, not matter the button pressed.
This is the original code:
#include "xparameters.h" #include "xil_printf.h" #include"xgpio.h" #include "xil_types.h" // Get device IDs fromxparameters.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_MASK0b1111 int main() { XGpio_Config *cfg_ptr; XGpio led_device,btn_device; u32 data; xil_printf("Entered function main\r\n"); //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 TristateXGpio_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); } }
Which looks like this:
Can Someone Help Me I M Stuck I M Using A Zybo Z7 Vivado Block Diagrams And Vivits Platform On A C Language Source 1
Can Someone Help Me I M Stuck I M Using A Zybo Z7 Vivado Block Diagrams And Vivits Platform On A C Language Source 1 (112.26 KiB) Viewed 36 times
I tried adding different variables, but it still doing the same.This is the code I have right now:
#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_CHANNEL0 1#define BTN_CHANNEL1 1#define BTN_CHANNEL2 1#define BTN_CHANNEL3 1#define LED_CHANNEL0 1#define LED_CHANNEL1 1#define LED_CHANNEL2 1#define LED_CHANNEL3 1#define BTN_MASK0 0b1111#define BTN_MASK1 0b1111#define BTN_MASK2 0b1111#define BTN_MASK3 0b1111#define LED_MASK0 0b1111#define LED_MASK1 0b1111#define LED_MASK2 0b1111#define LED_MASK3 0b1111
int main() { XGpio_Config *cfg_ptr; XGpioled_device0,led_device1,led_device2,led_device3,btn_device0,btn_device1,btn_device2,btn_device3; u32 data; xil_printf("Entered functionmain\r\n"); // Initialize LEDDevice cfg_ptr =XGpio_LookupConfig(LED_ID); XGpio_CfgInitialize(&led_device0, cfg_ptr,cfg_ptr->BaseAddress); XGpio_CfgInitialize(&led_device1, cfg_ptr,cfg_ptr->BaseAddress); XGpio_CfgInitialize(&led_device2, cfg_ptr,cfg_ptr->BaseAddress); XGpio_CfgInitialize(&led_device3, cfg_ptr,cfg_ptr->BaseAddress);
// Initialize ButtonDevice cfg_ptr =XGpio_LookupConfig(BTN_ID); XGpio_CfgInitialize(&btn_device0, cfg_ptr,cfg_ptr->BaseAddress); XGpio_CfgInitialize(&btn_device1, cfg_ptr,cfg_ptr->BaseAddress); XGpio_CfgInitialize(&btn_device2, cfg_ptr,cfg_ptr->BaseAddress); XGpio_CfgInitialize(&btn_device3, cfg_ptr,cfg_ptr->BaseAddress);
// Set Button Tristate XGpio_SetDataDirection(&btn_device0, BTN_CHANNEL0,BTN_MASK0); XGpio_SetDataDirection(&btn_device1, BTN_CHANNEL1,BTN_MASK1); XGpio_SetDataDirection(&btn_device2, BTN_CHANNEL2,BTN_MASK2); XGpio_SetDataDirection(&btn_device3, BTN_CHANNEL3,BTN_MASK3);
// Set Led Tristate XGpio_SetDataDirection(&led_device0, LED_CHANNEL0,0); XGpio_SetDataDirection(&led_device1, LED_CHANNEL1,0); XGpio_SetDataDirection(&led_device2, LED_CHANNEL2,0); XGpio_SetDataDirection(&led_device3, LED_CHANNEL3,0);
while (1) { data0 =XGpio_DiscreteRead(&btn_device0, BTN_CHANNEL0); data0&= BTN_MASK0;
data1 =XGpio_DiscreteRead(&btn_device1, BTN_CHANNEL1); data1&= BTN_MASK1;
data2 =XGpio_DiscreteRead(&btn_device2, BTN_CHANNEL2); data2&= BTN_MASK2;
data3 =XGpio_DiscreteRead(&btn_device3, BTN_CHANNEL3); data3&= BTN_MASK3;
if(data0 != 0) { data0 = LED_MASK0; } else{ data0 = 0; }
if(data1 != 0) { data1 = LED_MASK1; } else{ data1 = 0; }
if(data2 != 0) { data2 = LED_MASK2; } else{ data2 = 0; }
if(data3 != 0) { data3 = LED_MASK3; } else{ data3 = 0; }
XGpio_DiscreteWrite(&led_device0, LED_CHANNEL0,data0); XGpio_DiscreteWrite(&led_device1, LED_CHANNEL1,data1); XGpio_DiscreteWrite(&led_device2, LED_CHANNEL2,data2); XGpio_DiscreteWrite(&led_device3, LED_CHANNEL3,data3);
}}
I don't know if I have to modify the 0b1111 next to theBTN_MASK and LED_MASK, but I'm not sure which values I would addthere then.
I will also post a picture of the block diagram just incase.
Can Someone Help Me I M Stuck I M Using A Zybo Z7 Vivado Block Diagrams And Vivits Platform On A C Language Source 2
Can Someone Help Me I M Stuck I M Using A Zybo Z7 Vivado Block Diagrams And Vivits Platform On A C Language Source 2 (45.57 KiB) Viewed 36 times
#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 Ob1111 #define LED_MASK Ob1111 int main() { XGpio_Config *cfg_ptr; XGpio led device, btn_device; u32 data; xil_printf("Entered function main\r\n"); // 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_Discrete Read (&btn_device, BTN_CHANNEL); data &= BTN_MASK; if (data != 0) { } else { } data LED_MASK; data = 0; XGpio_DiscreteWrite(&led_device, LED_CHANNEL, data);
processing system 7 0 MAX_GPO_ACLK ZYNQ. S_AX ZYNQ7 Processing System AXI_GPIO_LED _ad_add(80) damady arvalid saavad asady adawald - brady dhp(10 ad bvalid - ◄s_ad_data(31 - _ad_mady ◄smas(10) _ad_valid _ad_data[31:0) wady watt(20) _ad_valid sack dann AXI GPIO + SAX s_ad_adk DOR + FIXED IO + USBIND 0 + M_AX GP + FCLK CLK FOLK RESETO N dann AXI GPIO BUTTONS AXI GPIO GRO- jq3► GRO + st_ps7_0_50M slow sync_dk axt rain aux natin mb_debug ya dam Jackad bus struct - paripheral_rast(0:0) interconnectars(0:0) ► paripharal_anisatr(0:0) ► Processor System Reset ps7_0_axi_periph D + 500 AX ACLK ARESETN 500 ACLK 500 ARE SETN MOO_ACLK MOO_ARE SETN MO1ACLK MO1 ARE SETN A MOO_AX + MOLAX + AXI Interconnect leds_4bits DDR FIXED_IO
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply