首页 > 代码库 > zedboard 流水灯

zedboard 流水灯

#include"xparameters.h"/* Peripheral parameters 外围的參数 */
#include"xgpio.h"/* GPIO data struct and APIs GPIO、结构,应用程序编程接口 */
#include"xil_printf.h"
#include"xil_cache.h"
#define GPIO_BITWIDTH	8	/* This is the width of the GPIO */
#define GPIO_DEVICE_ID  XPAR_AXI_GPIO_0_DEVICE_ID//device id
#define LED_DELAY     40000000/* times delay*/
#define LED_MAX_BLINK	0x1	/* Number of times the LED Blinks */
#define LED_CHANNEL 1/* GPIO channel*/
#define printf xil_printf	/* A smaller footprint printf */
XGpio Gpio; /* The Instance of the GPIO Driver */
XGpio GpioOutput; /* The driver instance for GPIO Device configured as O/P */

int GpioMarquee (u16 DeviceId, u32 GpioWidth)
{
	int Delay;
	u32 LedBit;
	u32 LedLoop;
	int Status;
	 Status = XGpio_Initialize(&GpioOutput, DeviceId);
	if (Status != XST_SUCCESS)  {
		return XST_FAILURE;
	 }
	 XGpio_SetDataDirection(&GpioOutput, LED_CHANNEL, 0x0);//输出模式
	 XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, 0x0);
	for (LedBit = 0x0; LedBit < GpioWidth; LedBit++)  {
			XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL,
						1 << LedBit);
			for (Delay = 0; Delay < LED_DELAY; Delay++);
			XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL,
						1 << LedBit);
	 }
	for (LedBit = 0x07; LedBit >= 0x01; LedBit--)  {
				XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL,
							1 << LedBit);
				for (Delay = 0; Delay < LED_DELAY; Delay++);
				XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL,
							1 << LedBit);
		 }
	for (LedBit = 0x0; LedBit < GpioWidth; LedBit++)  {
		        LedBit++;
				XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL,
							1 << LedBit);
				for (Delay = 0; Delay < LED_DELAY; Delay++);
				XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL,
							1 << LedBit);
		 }
	return XST_SUCCESS;
}
 main(void)
{
	while(1){
		u32 status;
		status = GpioMarquee (GPIO_DEVICE_ID,GPIO_BITWIDTH);
			printf("SUCESS!.\r\n");
	}
	return XST_SUCCESS;
}










zedboard 流水灯