zedboard做流水灯代码
2015-07-16 17:43
309 查看
/*
* MD.c
*
* Created on: 2015年7月16日
* Author: Administrator
*/
/*
* LEDwc.c
*
* Created on: 2015年7月16日
* Author: Administrator
*/
#include"xparameters.h"/* Peripheral parameters */
#include"xgpio.h"/* GPIO data struct and APIs */
#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 10000000/* 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)
{
//volatileint
int Delay;
//int Delay;
u32 LedBit;
u32 LedLoop;
int Status;
/*
* Initialize the GPIO driver so that it's ready to use,
* specify the device ID that is generated in xparameters.h
*/
Status = XGpio_Initialize(&GpioOutput, DeviceId);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
//Set the direction for all signals to be outputs
XGpio_SetDataDirection(&GpioOutput, LED_CHANNEL, 0x0);
// Set the GPIO outputs to low
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, 0x0);
for (LedBit = 0x0; LedBit < GpioWidth; LedBit++) {
for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop++) {
//Set the GPIO Output to High
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL,
1 << LedBit);
//Wait a small amount of time so the LED is visible
for (Delay = 0; Delay < LED_DELAY; Delay++);
//Clear the GPIO Output
XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL,
1 << LedBit);
// Wait a small amount of time so the LED is visible
for (Delay = 0; Delay < LED_DELAY; Delay++);
}
}
return XST_SUCCESS;
}
main(void)//把main前面的int去掉了。
{//Application start
/* loop forever*/
while(1){
u32 status;
status = GpioMarquee (GPIO_DEVICE_ID,GPIO_BITWIDTH);
if (status == 0)
printf("SUCESS!.\r\n");
else printf("FAILED.\r\n");
}
return XST_SUCCESS;
}
* MD.c
*
* Created on: 2015年7月16日
* Author: Administrator
*/
/*
* LEDwc.c
*
* Created on: 2015年7月16日
* Author: Administrator
*/
#include"xparameters.h"/* Peripheral parameters */
#include"xgpio.h"/* GPIO data struct and APIs */
#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 10000000/* 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)
{
//volatileint
int Delay;
//int Delay;
u32 LedBit;
u32 LedLoop;
int Status;
/*
* Initialize the GPIO driver so that it's ready to use,
* specify the device ID that is generated in xparameters.h
*/
Status = XGpio_Initialize(&GpioOutput, DeviceId);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
//Set the direction for all signals to be outputs
XGpio_SetDataDirection(&GpioOutput, LED_CHANNEL, 0x0);
// Set the GPIO outputs to low
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, 0x0);
for (LedBit = 0x0; LedBit < GpioWidth; LedBit++) {
for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop++) {
//Set the GPIO Output to High
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL,
1 << LedBit);
//Wait a small amount of time so the LED is visible
for (Delay = 0; Delay < LED_DELAY; Delay++);
//Clear the GPIO Output
XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL,
1 << LedBit);
// Wait a small amount of time so the LED is visible
for (Delay = 0; Delay < LED_DELAY; Delay++);
}
}
return XST_SUCCESS;
}
main(void)//把main前面的int去掉了。
{//Application start
/* loop forever*/
while(1){
u32 status;
status = GpioMarquee (GPIO_DEVICE_ID,GPIO_BITWIDTH);
if (status == 0)
printf("SUCESS!.\r\n");
else printf("FAILED.\r\n");
}
return XST_SUCCESS;
}
相关文章推荐
- 最简单地完成一项编程任务
- C++读取配置文件内中的数组
- Thinking in java 读书笔记
- 正则经验
- C语言获取文件大小
- qt5 mouseless 多子页面切换测试
- C++中继承方式对访控属性的影响
- C语言实现修改文本文件中特定行的实现代码
- JAVA面试题:Spring中bean的生命周期
- Spring AOP声明式事务异常回滚
- C语言实现文件复制或者拼接
- spring中@Component注解
- 使用 cloc 统计代码行数
- C++ STL
- spring aop中的propagation的7种配置的意思
- 【C++】基类析构函数为什么要为虚函数
- PHP进度条
- PHP调用WebService接口
- Using ASP.Net WebAPI with Web Forms
- 关于spring-servlet.xml cannot be opened because it does not exist的解决