观察板上的 4 个LED,大概没隔4 秒,LED 会轮流闪烁一次。
恭喜您,第一个 C 程序在NIOSII CPU 上已经运行起来了。
如果感兴趣,可以修改源文件,然后在编译,运行,看看 LED 有什么变化
以下是一个让 LED 闪烁更频繁的例子:
int main (void) __attribute__ ((weak, alias ("alt_main")));
/*
* Use alt_main as entry point for this free-standing application
*/
int alt_main (void)
{
alt_u8 led = 0x2;
alt_u8 dir = 0;
volatile int i;
/*
* Infinitly shift a variable with one bit set back and forth, and write
* it to the LED PIO. Software loop provides delay element.
*/
while (1)
{
if (led & 0x09) // 我们板上只有4个LED,所以当led的Bit3和Bit0有效的时候,
//就改变方向;
{
dir = (dir ^ 0x1);
}
if (dir)
{
led = led >> 1;
}
else
{
led = led << 1;
}
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
/*
* The delay element in this design has been written as a while loop
* to avoid confusing the software debugger. A tight, one line software
* delay loop such as:
* for(i=0; i<200000; i++);
* can cause problems when it is stepped through using a software
debugger.
* The while loop below produces the same behavior as the for loop shown
* above, but without causing potential debugger problems.
*/
i = 0;
while (i<100000) //加快闪烁间隔
i++;
}
return 0;
}