我写了一个简单的Microblaze C应用程序,用一个按钮在十六进制和BCD模式之间切换来测试电路板显示。
这是我的代码:
#include <xparameters.h>
#include <xgpio.h>
int main ()
{
XGpio display, digit, bcd, butt; // four variables are defined named display, digit, bcd, butt
int flag = 1;
XGpio_Initialize (&display, XPAR_AXI_GPIO_0_DEVICE_ID);
XGpio_SetDataDirection (&display,1,0); // set display as output ports
XGpio_Initialize (&digit,XPAR_AXI_GPIO_1_DEVICE_ID);
XGpio_SetDataDirection (&digit,1,0); // set digit as output ports
XGpio_Initialize (&bcd,XPAR_AXI_GPIO_2_DEVICE_ID);
XGpio_SetDataDirection (&bcd,1,0); // set bcd as output ports
XGpio_Initialize (&butt, XPAR_AXI_GPIO_3_DEVICE_ID);
XGpio_SetDataDirection (&butt,1,1); //set button as input port
while(1)
{
if (XGpio_DiscreteRead (&butt, 1) == 1)
{
if (flag==1)
{ flag=0; }
else
{ flag=1; }
} // toggle flag
XGpio_DiscreteWrite (&bcd, 1, flag); // set bcd to flag
XGpio_DiscreteWrite (&digit, 1, 7); // set n°8 digit
XGpio_DiscreteWrite (&display, 1, 99563243); // write to display
}
}
当我在主板上调试时,一切正常。在FPGA上下载后,切换不起作用。
有人可以解释原因吗?
答案 0 :(得分:1)
解决 以下代码运行正常。将标志定义为u32并添加延迟周期。
#include<xparameters.h>
#include<xgpio.h>
int main()
{
XGpio display, digit, bcd, sw; // defined gpio variables
long int delay; // defined a delay variable
u32 flag=1; // defined a flag variable
XGpio_Initialize(&display, XPAR_AXI_GPIO_0_DEVICE_ID);
XGpio_SetDataDirection(&display,1,0); // set display as output ports
XGpio_Initialize(&digit,XPAR_AXI_GPIO_1_DEVICE_ID);
XGpio_SetDataDirection(&digit,1,0); // set digit as output ports
XGpio_Initialize(&bcd,XPAR_AXI_GPIO_2_DEVICE_ID);
XGpio_SetDataDirection(&bcd,1,0); // set bcd as output ports
XGpio_Initialize(&sw, XPAR_AXI_GPIO_3_DEVICE_ID);
XGpio_SetDataDirection(&sw,1,1); //set sw as input port
while(1)
{
flag= XGpio_DiscreteRead(&sw, 1);
XGpio_DiscreteWrite(&bcd, 1, flag); // set bcd to flag
XGpio_DiscreteWrite(&digit, 1, 7); // set n°8 digit
XGpio_DiscreteWrite(&display, 1, 5888999); // write to display
for(delay=0;delay<3000000;delay++){}; // delay cycle
}
}