c - 程序只有在 Debug模式下才能正确运行

标签 c debugging microblaze

我编写了一个简单的 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 后,切换不起作用。

谁能解释一下为什么吗?

最佳答案

已解决 以下代码运行良好。定义flag为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
}
}    

关于c - 程序只有在 Debug模式下才能正确运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26427162/

相关文章:

c - 结构中的 Void * 空间而不是 malloc

c++ - 查找存储在内存中的值 C/C++

php - 有哪些好的 PHP MySQL 调试工具?

iOS - 我的实例变量发生了什么?

python - 为什么在 VS Code 的集成 Python 调试中启动多个调试线程?

c - 代码修改后,Microblaze 上的运行时间有所不同

c - 这是在 C 中声明数组的有效方法吗?

c++ - 将代码从 C++ 转换为 C : `a+b > b+a` where a and b are `string`

gcc - Microblaze 交叉编译

c - c中的字符串比较