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