如何使用Vivado在Zybo设计中使用更多GPIO?

时间:2015-08-12 16:03:27

标签: vivado

我是Xilinx Vivado和Zybo的新用户。我按照以下链接中的教程: http://www.dbrss.org/zybo/tutorial1.html 它运作良好。

然后我为GPIO添加了一个通道并将其与交换机连接。这是.c文件:

/* Borrowed from ZynqBook Tutorials */

/* Include Files */
#include "xparameters.h"
#include "xgpio.h"
#include "xstatus.h"
#include "xil_printf.h"

/* Definitions */
#define GPIO_DEVICE_ID  XPAR_AXI_GPIO_0_DEVICE_ID   /* GPIO device that LEDs are connected to */
#define LED 0x00                                    /* Initial LED value - 0000 */
#define LED_DELAY 10000000                          /* Software delay length */
#define LED_CHANNEL 1                               /* GPIO port for LEDs */
#define SW_CHANNEL 2
#define printf xil_printf                           /* smaller, optimized printf */

XGpio Gpio;                                         /* GPIO Device driver instance */

int LEDOutputExample(void)
{

    //volatile int Delay;
    int Status;
    int led = LED; /* Hold current LED value. Initialize to LED definition */

        /* GPIO driver initialization */

        Status = XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
        if (Status != XST_SUCCESS) {
            return XST_FAILURE;
        }

        /*Set the direction for the LEDs to output. */
        XGpio_SetDataDirection(&Gpio, LED_CHANNEL, 0x00);
        XGpio_SetDataDirection(&Gpio, SW_CHANNEL, 0x0F);

        /* Loop forever blinking the LED. */
            while (1) {
                /* Write output to the LEDs. */
                led = XGpio_DiscreteRead(&Gpio, SW_CHANNEL);
                XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, led);

                /* Flip LEDs. */
                //led = ~led;


                /* Wait a small amount of time so that the LED blinking is visible. */
                //for (Delay = 0; Delay < LED_DELAY; Delay++);
            }

        return XST_SUCCESS; /* Ideally unreachable */
}

/* Main function. */
int main(void){

    int Status;

    /* Execute the LED output. */
    Status = LEDOutputExample();
    if (Status != XST_SUCCESS) {
        xil_printf("GPIO output to the LEDs failed!\r\n");
    }

    return 0;
}

但是当我更换开关时,LED仍处于初始状态。问题是什么? 谢谢!

1 个答案:

答案 0 :(得分:0)

首先,您必须记住更换硬件部分并为交换机添加新的AXi_GPIO IP内核(您只有1个用于LED) 当您尝试获得闪烁的LED时,使用开关的目的是什么? 您的代码中存在很多问题。您需要阅读有关使用vivado和SDK的更多信息,您不能只从SDK中添加更多输出。 我强烈建议您阅读xilinx vivado教程书,该教程可以在他们的网站上免费在线阅读。它极好地解释了所有基础知识。