标签:
源代码
#include <stdio.h>
#include "platform.h"
#include "xparameters.h"
#include "xgpio.h"
#include "sleep.h"
#include "platform.h"
#include "xil_types.h"
#include "xgpiops.h"
/************************** Constant Definitions *****************************/
/*
* The following constant maps to the name of the hardware instances that
* were created in the EDK XPS system.
*/
#define XPAR_LEDS_ID XPAR_AXI_GPIO_0_BASEADDR//AXI_GPIO_0 是添加的第一个 gpio 所以是 leds
#define XPAR_SWS_ID XPAR_AXI_GPIO_1_BASEADDR //那么 这个自然是 开关了
//int
main()
{
static XGpio LED_Ptr;//定义GPIO指针
static XGpio SWS_Ptr;
int XStatus;
int num = 0;
//初始化 LED
XStatus = XGpio_Initialize(&LED_Ptr,XPAR_AXI_GPIO_0_DEVICE_ID);
if(XST_SUCCESS != XStatus)
print("GPIO INIT FAILED\n\r");
XGpio_SetDataDirection(&LED_Ptr, 1,0x00);//通道1;设置方向 0 输出 1输入, 0x00表示8位都是输出
XGpio_DiscreteWrite(&LED_Ptr, 1,0x00);
//初始化 开关
XStatus = XGpio_Initialize(&SWS_Ptr,XPAR_AXI_GPIO_1_DEVICE_ID);
if(XST_SUCCESS != XStatus)
print("GPIO INIT FAILED\n\r");
XGpio_SetDataDirection(&SWS_Ptr, 1,0xFF);//通道1;设置方向 0 输出 1输入 0xFF表示8位都是输入
while(1){
num = XGpio_DiscreteRead(&SWS_Ptr, 1); //从开关处 读数据
printf("Numb %d\n\r", num);
XGpio_DiscreteWrite(&LED_Ptr, 1, num);
// @param Channel contains the channel of the GPIO (1 or 2) to operate on.
// XGpio_DiscreteWrite(&LED_Ptr, 1,num); //直接写入 led
usleep(1000000); //delay 1ms
}
printf("end\n\r \n\r");
// return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/kobesdu/article/details/47186141