0

我是 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 保持初始状态。有什么问题?谢谢!

4

1 回答 1

0

首先,您必须记住更改硬件部分并为开关添加一个新的 AXi_GPIO IP 内核。(目前您只有 1 个,仅用于 LED)此外,当您尝试使用开关时,使用开关的目的是什么?得到一个闪烁的 LED?你的代码有很多问题。您需要阅读更多关于将 vivado 与 SDK 结合使用的信息,您不能只从 SDK 添加更多输出。我强烈建议您阅读 xilinx vivado 教程书,该书可在其网站上免费在线阅读。它非常好地解释了所有基础知识。

于 2016-01-13T16:10:00.703 回答