新建工程、
MIO (线程固定好的MIO的使用)
led 放在-EMIO 可以勾选上,要几个脚,就输几个。
如果引脚还不够,就axi_gpio
//Bank 1 I/O Voltage 1.8v。 后面是1.8v,前面是3.3v
clock configuration 后面PL Configuration FCLK_CLK0 后的时钟100
Quard SPI Flash MIO 1...6 Single SS 4-bit IO MIO 1...6
Feedback CLK MIO 8
//SD0 MIO 40-45 CD MIO 47
//UART1 MIO 48...49
clock里面:33.333333 CPU 666.666666 DDR 533.333333
时钟 QSPI 125M
//USB0 28-39
//ENET0 16-27 MIO 52-53
UART1 48-49
DDR型号:MT41K128M16JT-125
GP接口 PS-PL Configuration ... M AXI GP0 interface
所有的编辑ok后,点击Run block automation
在GPIO下的EMIO GPIO(Width) 4
可以再加一个AXI GPIO 对开关进行引出引脚
在没有引脚输出的引脚上,右击Make Externel
修改名称,点击后,在左侧修改。
在source下,右击design_1 generate output products
Create HDL Wrapper
SYNTHESIS 下 点击Run Synthesis 、 window IO 添加引脚、Run Implementation 。后保存。后再Generate Bitstream。
先export ,再launch SDK
在SDK里面,新建一个文件File➡NEW➡application project lab1的src添加一个新的文件,是main.c
在lab1_bsp下的ps7_cortexa9_0的include下,有许多的文件,如sleep.h是延时函数。可以调用,如main.c里面写
#include "xgpio.h"
#include "xgpiops.h"
#include "xparameters.h"
#include <xil_printf.h>
int main (void)
{
XGpio sw;
XGpioPs led;//XGpio驱动程序实例数据
XGpioPs_Config *ConfigPtr;//此typedef包含设备的配置信息。
int xStatus;
int sw_check;
XGpio_Initialize(&sw, XPAR_AXI_GPIO_0_DEVICE_ID);
XGpio_SetDataDirection(&sw,1,0xffffffff);
ConfigPtr = XGpioPs_LookupConfig(XPAR_AXI_GPIO_0_DEVICE_ID);
if (ConfigPtr == NULL) {
return XST_FAILURE;
}
xStatus = XGpioPs_CfgInitialize(&led, ConfigPtr, ConfigPtr->BaseAddr);
if (xStatus != XST_SUCCESS){
xil_printf("PS GPIO init failed \n\r");
return 0;
}
XGpioPs_SetDirectionPin(&led, 54,1);
XGpioPs_SetDirectionPin(&led, 55,1);
XGpioPs_SetDirectionPin(&led, 56,1);
XGpioPs_SetDirectionPin(&led, 57,1);
XGpioPs_SetOutputEnablePin(&led,54,1);
XGpioPs_SetOutputEnablePin(&led,55,1);
XGpioPs_SetOutputEnablePin(&led,56,1);
XGpioPs_SetOutputEnablePin(&led,57,1);
xil_printf("GPIO init successed \n\r");
while(1)
{
sw_check = XGpio_DiscreteRead(&sw, 1);
xil_printf("sw_check=%x \n\r",sw_check);
switch(sw_check){
case 0x0:
XGpioPs_WritePin(&led,54,1);
XGpioPs_WritePin(&led,55,0);
XGpioPs_WritePin(&led,56,0);
XGpioPs_WritePin(&led,57,0);
break;
case 0x1:
XGpioPs_WritePin(&led,54,0);
XGpioPs_WritePin(&led,55,1);
XGpioPs_WritePin(&led,56,0);
XGpioPs_WritePin(&led,57,0);
break;
case 0x2:
XGpioPs_WritePin(&led,54,0);
XGpioPs_WritePin(&led,55,0);
XGpioPs_WritePin(&led,56,1);
XGpioPs_WritePin(&led,57,0);
break;
case 0x3:
XGpioPs_WritePin(&led,54,0);
XGpioPs_WritePin(&led,55,0);
XGpioPs_WritePin(&led,56,0);
XGpioPs_WritePin(&led,57,1);
break;
default:xil_printf("error\n\r"); break;
}
}
}