[C] 纯文本查看 复制代码
#include "xgpiops.h"
#include "unistd.h"
XGpioPs Gpio;
XGpioPs_Config *ConfigPtr;
int main(void)
{
ConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
XGpioPs_CfgInitialize(&Gpio, ConfigPtr, ConfigPtr->BaseAddr);
/*设置EMIO0为输入,MIO有54个,EMIO0=54+0=54*/
XGpioPs_SetDirectionPin(&Gpio, 54, 1);
XGpioPs_SetOutputEnablePin(&Gpio, 54, 1);
/*设置EMIO1为输入*/
XGpioPs_SetDirectionPin(&Gpio, 55, 0);
XGpioPs_SetOutputEnablePin(&Gpio, 55, 0);
while(1)
{
while(!XGpioPs_ReadPin(&Gpio, 55))
{
//设置bit54输出1
XGpioPs_WritePin(&Gpio, 54, 0x1);
usleep(500000);
//设置bit54输出0
XGpioPs_WritePin(&Gpio, 54, 0x0);
usleep(500000);
}
//设置bit54输出0
XGpioPs_WritePin(&Gpio, 54, 0x0);
}
return 0;
}