在20分鐘內(nèi)建立一個(gè)NIOS II開發(fā)環(huán)境的方法
經(jīng)過以上處理,就可以編譯和下載程序了。
編譯項(xiàng)目
從 Processing 菜單選Start compilation,或者Cntl+L,開始編譯。出現(xiàn)警告信息可以不管,等待編譯結(jié)束。
配置 FPGA
從Tools 菜單選擇Programmer,選擇JTAG 模式和對(duì)應(yīng)的sof 文件,點(diǎn)擊Start,
開始下載,如果成功,那么開始進(jìn)入軟件調(diào)試環(huán)境。
啟動(dòng) NIOS II IDE 環(huán)境
關(guān)閉 Programmer,打開頂層文件??旖?a class="contentlabel" href="http://www.ex-cimer.com/news/listbylabel/label/方法">方法就是點(diǎn)圖標(biāo)

雙擊 low_cost_1C20 系統(tǒng)模塊,進(jìn)入SOPC Builder。

選擇 Run Nios II IDE,進(jìn)入IDE 開發(fā)環(huán)境。
建立軟件工程文件
選擇 File-》New -》Project 選項(xiàng)。

選擇 C/C++ Application, 點(diǎn)擊Next。

從模板中選擇 Hello LED,其他設(shè)置按默認(rèn)設(shè)置,點(diǎn)擊Finish。
編譯工程文件
選中 hello_led_0,按右鍵,選擇 Build Project

結(jié)束后,右下方的控制臺(tái)會(huì)提示編譯結(jié)束。

運(yùn)行程序
從菜單中選擇 Run-》Run…,彈出對(duì)話框

點(diǎn)擊 New,會(huì)自動(dòng)生成一個(gè)系統(tǒng)配置。

點(diǎn)擊 Apply,然后點(diǎn)擊Run。
開始下載程序到 SDRAM,并運(yùn)行起來。

觀察板上的 4 個(gè)LED,大概沒隔4 秒,LED 會(huì)輪流閃爍一次。
恭喜您,第一個(gè) C 程序在NIOSII CPU 上已經(jīng)運(yùn)行起來了。
如果感興趣,可以修改源文件,然后在編譯,運(yùn)行,看看 LED 有什么變化
以下是一個(gè)讓 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個(gè)LED,所以當(dāng)led的Bit3和Bit0有效的時(shí)候,
//就改變方向;
{
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; i200000; 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 (i100000) //加快閃爍間隔
i++;
}
return 0;
}
本文引用地址:http://www.ex-cimer.com/article/149395.htm
評(píng)論