1.打开XPS,创建一个新工程,名称为lab4
2.Board Selection: 选择和开发板对应的参数,reset polarity选active low
3.System Configuration: 选择Single-Processor System
4.Processor Configuration: Reference Clock Frequency和System Clock Frequency都选择 50MHz
5.Peripheral Configuration:
Add Device,IO Interface Type选GPIO,Device选LEDS;
Add Device,IO Interface Type选GPIO,Device选Push_Buttons;
GPIO Data Width默认为32bit,一直next,直至finish
6.打开UCF文件,把LED和按键的管脚连上
7.在Project Tab中双击iMPACT Command File,把其中的5改为2,保存文件
8.Generate Libraries and BSPs
9.在Application标签中,右键点击Project:TestApp_Memory_microblaze_0中的.C文件,remove,再右键点击Sources,Add New File,建立一个新的C文件,打开C文件,输入如下代码:
#include "xparameters.h"
#include "xgpio.h"
//====================================================
int main (void)
{
XGpio push;
int i, psb_check;
// define instance pointer for LEDs_8Bit device
XGpio LEDs8_Bit;
XGpio_Initialize(&push, XPAR_PUSH_BUTTONS_DEVICE_ID);
//XPAR_PUSH_BUTTONS_DEVICE_ID要和xparameters.h中的一样
XGpio_SetDataDirection(&push, 1, 0xffffffff);
// initialize and set data direction for LEDs_8Bit device
XGpio_Initialize(&LEDs8_Bit, XPAR_LEDS_DEVICE_ID);
//XPAR_LEDS_DEVICE_ID要和xparameters.h中的一样
XGpio_SetDataDirection(&LEDs8_Bit, 1, 0x0);
while (1)
{
psb_check = XGpio_DiscreteRead(&push, 1);
// output push switches value on LEDs_8Bit device
XGpio_DiscreteWrite(&LEDs8_Bit, 1, ~psb_check);
//按键为低有效,而LED为高有效,所以psh_check取反
for (i=0; i<999999; i++);
}
}
10.在Application标签中,右键点击Project:TestApp_Memory_microblaze_0,选择Build Project
11.Generate Netlist
12.Generate Bitstream
13.Download Bitstream,下载完后按下一个按键,对应的LED就被点亮
用户230340 2010-4-22 18:24
用户251222 2010-4-20 11:05
用户230340 2010-4-20 10:56